[WIP] Support for "ANY/ALL(array) op scalar" (Was: Re: Boolean operators without commutators vs. ALL/ANY)

Поиск
Список
Период
Сортировка
От Florian Pflug
Тема [WIP] Support for "ANY/ALL(array) op scalar" (Was: Re: Boolean operators without commutators vs. ALL/ANY)
Дата
Msg-id EDA18655-C7EF-4250-A930-9DD0709DCF2E@phlo.org
обсуждение исходный текст
Ответ на Re: Boolean operators without commutators vs. ALL/ANY  (David Fetter <david@fetter.org>)
Ответы Re: [WIP] Support for "ANY/ALL(array) op scalar" (Was: Re: Boolean operators without commutators vs. ALL/ANY)  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Jun13, 2011, at 17:41 , David Fetter wrote:
> On Mon, Jun 13, 2011 at 09:01:45AM +0200, Florian Pflug wrote:
>> Hm, that's less bulky but more kludgy, I'd say. But wait a minute...
>>
>> If ANY and ALL are reserved anyway, should it be possible to
>> make "(ANY(..) <op> <expr>)" and "(ALL(...) <op> <expr>)"
>> work grammar-wise? (Note the enclosing parens)
>
> This would be a very, very useful feature. :)


There, you dared me. So here's a patch :-P

So far it supports (ANY(array) op scalar) and (ALL(array) op scalar),
but not (ANY/ALL(subselect) op scalar). "ANY/ALL op scalar" is
supported independent from whether <op> has a commutator or not.
In the latter case, the clause isn't indexable, but thats no
different from the case "const op field". Both ANY(...) = ctid
and ctid = ANY(...) are correctly executed as TID scans (if the
array expression is a pseudo-constant, that is).

The patch adds a fields "aryArgIdx" (0 or 1) to ScalarArrayOpExpr
which stores the index of the array-valued argument. Thus, for
the traditional "scalar op ANY/ALL(array)" variant, aryArgIdx == 1,
for "ANY/ALL(array) op scalar" it's zero.

I've updates all places that I could find which inspect
ScalarArrayOpExprs to take the aryArgIdx into account. And boy,
those were quite a few, which explains the size of the patch.
Most of the changes are pretty trivial, though.

The indexing support works similar to the case "scalar op scalar",
i.e. match_clause_to_indexcol() consideres the clause to be index-able
if the scalar argument matches an index definition, and relies on
fix_indexqual_references() to commute the ScalarArrayOpExprs if
the scalar argument is on the right side instead of on the left.

I noticed that ANY/ALL is hardly exercised by the regression tests
at all, so I added a (pretty exhaustive, I think) test any_all.
The test exercises the traditional and the reversed form of
ANY/ALL and verify that an index is used if possible.

Comments are extremely welcome, especially ones regarding
the overall approach taken in this patch. If people consider
that to be acceptable, I'd try to add the missing features
and add documentation.

best regards,
Florian Pflug

Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Why polecat and colugos are failing to build back branches
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [WIP] Support for "ANY/ALL(array) op scalar" (Was: Re: Boolean operators without commutators vs. ALL/ANY)