Re: [SQL] qurey plan and indices

Поиск
Список
Период
Сортировка
От Vadim Mikheev
Тема Re: [SQL] qurey plan and indices
Дата
Msg-id 37AA43C4.5DDBE65F@krs.ru
обсуждение исходный текст
Ответ на Re: [SQL] qurey plan and indices  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [SQL] qurey plan and indices  (Bruce Momjian <maillist@candle.pha.pa.us>)
Список pgsql-sql
Tom Lane wrote:
> 
> Yes.  The inner query must happen by sequential scan.  But the outer
> query can use an index if it is in the form
>         ... where (name = 'a') or (name = 'b') or (name = 'c');
> which is what "where name in ('a','b','c')" gets translated to.
> 
> However, the *real* problem here is that the inner query is treated
> as a subplan, which means it is re-evaluated for each tuple scanned
> by the outer query.  This is not very bright; the system ought to
> notice that the inner query does not depend on the state of the
> outer query, and do it only once.  There is already a notion of
> InitPlan vs. SubPlan.  I'm not sure why this case is being classified
> as a SubPlan, but it sure looks like it ought to be done as an
> InitPlan...

Not in all cases. First, to use InitPlan you would have to add 
DISTINCT to subquery to avoid duplicates. Second, there is another
way of optimization - cache/hash subquery results to avoid 
re-execution of subquery plan. Planner should make decision what
way to follow. 

Vadim


В списке pgsql-sql по дате отправления:

Предыдущее
От: Richard Dice
Дата:
Сообщение: subscribe
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [SQL] qurey plan and indices