Re: Transforming IN (...) to ORs, volatility

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Transforming IN (...) to ORs, volatility
Дата
Msg-id 27610.1301766483@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Transforming IN (...) to ORs, volatility  (Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>)
Ответы Re: Transforming IN (...) to ORs, volatility  (Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>)
Список pgsql-hackers
Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> writes:
> We sometimes transform IN-clauses to a list of ORs:
> postgres=# explain SELECT * FROM foo WHERE a IN (b, c);
>                        QUERY PLAN
> ------------------------------------------------------
>   Seq Scan on foo  (cost=0.00..39.10 rows=19 width=12)
>     Filter: ((a = b) OR (a = c))
> (2 rows)

> But what if you replace "a" with a volatile function? It doesn't seem 
> legal to do that transformation in that case, but we do it:

This is the fault of transformAExprIn().  But please let's *not* fix
this by adding volatility to the set of heuristics used there.  Looking
at this again, it seems to me that most of the problem with this code
is that we're trying to make optimization decisions in the parser.

I think what we ought to do is have the parser emit a full-fledged
InExpr node type (with semantics rather like CaseExpr) and then teach
the planner to optimize that to something else when it seems
safe/prudent to do so.  One nontrivial advantage of that is that
rules/views containing IN constructs would start to reverse-parse
in the same fashion, instead of introducing weird substitute
expressions.
        regards, tom lane


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

Предыдущее
От: David Fetter
Дата:
Сообщение: Re: [COMMITTERS] pgsql: Escape greater than and less than characters in docs.
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Another swing at JSON