Re: index scan over composite type

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: index scan over composite type
Дата
Msg-id 21623.1526417821@sss.pgh.pa.us
обсуждение исходный текст
Ответ на index scan over composite type  (Teodor Sigaev <teodor@sigaev.ru>)
Ответы Re: index scan over composite type  (Teodor Sigaev <teodor@sigaev.ru>)
Список pgsql-hackers
Teodor Sigaev <teodor@sigaev.ru> writes:
> I'm not understand why postgres prefers to sort table instead of using 
> index only scan when query is a simple inner join on composite type. 
> Query with equality clause with constant works fine with index scan but 
> join not. Could somebody point me why? Thank you.

Hmm ... the reason why not seems to be that canonicalize_ec_expression()
improperly adds a RelabelType node, causing the composite-type Vars to not
be recognized as matching the eclass they should match.  The attached
patch fixes it and doesn't seem to break anything in the regression tests.

This raises the question of why we don't treat type RECORD more like a
true polymorphic type, but that's a can of worms I don't particularly want
to open right now.  For the moment, this is the only IsPolymorphicType
call in the planner AFAICS, so there's some reason to hope that we don't
have more bugs of the same ilk.

            regards, tom lane

diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c
index 70a925c..e8cdea5 100644
--- a/src/backend/optimizer/path/equivclass.c
+++ b/src/backend/optimizer/path/equivclass.c
@@ -497,8 +497,9 @@ canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation)

     /*
      * For a polymorphic-input-type opclass, just keep the same exposed type.
+     * RECORD opclasses work like polymorphic types for this purpose.
      */
-    if (IsPolymorphicType(req_type))
+    if (IsPolymorphicType(req_type) || req_type == RECORDOID)
         req_type = expr_type;

     /*

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

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: explain (verbose off, normalized) vs query planid
Следующее
От: Tom Lane
Дата:
Сообщение: Re: explain (verbose off, normalized) vs query planid