pgsql: Restructure code that is responsible for ensuring that clauseless

Поиск
Список
Период
Сортировка
От tgl@postgresql.org (Tom Lane)
Тема pgsql: Restructure code that is responsible for ensuring that clauseless
Дата
Msg-id 20070216001408.794999FBEBB@postgresql.org
обсуждение исходный текст
Список pgsql-committers
Log Message:
-----------
Restructure code that is responsible for ensuring that clauseless joins are
considered when it is necessary to do so because of a join-order restriction
(that is, an outer-join or IN-subselect construct).  The former coding was a
bit ad-hoc and inconsistent, and it missed some cases, as exposed by Mario
Weilguni's recent bug report.  His specific problem was that an IN could be
turned into a "clauseless" join due to constant-propagation removing the IN's
joinclause, and if the IN's subselect involved more than one relation and
there was more than one such IN linking to the same upper relation, then the
only valid join orders involve "bushy" plans but we would fail to consider the
specific paths needed to get there.  (See the example case added to the join
regression test.)  On examining the code I wonder if there weren't some other
problem cases too; in particular it seems that GEQO was defending against a
different set of corner cases than the main planner was.  There was also an
efficiency problem, in that when we did realize we needed a clauseless join
because of an IN, we'd consider clauseless joins against every other relation
whether this was sensible or not.  It seems a better design is to use the
outer-join and in-clause lists as a backup heuristic, just as the rule of
joining only where there are joinclauses is a heuristic: we'll join two
relations if they have a usable joinclause *or* this might be necessary to
satisfy an outer-join or IN-clause join order restriction.  I refactored the
code to have just one place considering this instead of three, and made sure
that it covered all the cases that any of them had been considering.

Backpatch as far as 8.1 (which has only the IN-clause form of the disease).
By rights 8.0 and 7.4 should have the bug too, but they accidentally fail
to fail, because the joininfo structure used in those releases preserves some
memory of there having once been a joinclause between the inner and outer
sides of an IN, and so it leads the code in the right direction anyway.
I'll be conservative and not touch them.

Tags:
----
REL8_2_STABLE

Modified Files:
--------------
    pgsql/src/backend/optimizer/geqo:
        geqo_eval.c (r1.81.2.2 -> r1.81.2.3)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/geqo/geqo_eval.c.diff?r1=1.81.2.2&r2=1.81.2.3)
    pgsql/src/backend/optimizer/path:
        joinrels.c (r1.81.2.2 -> r1.81.2.3)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/path/joinrels.c.diff?r1=1.81.2.2&r2=1.81.2.3)
    pgsql/src/backend/optimizer/util:
        joininfo.c (r1.44.2.1 -> r1.44.2.2)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/util/joininfo.c.diff?r1=1.44.2.1&r2=1.44.2.2)
    pgsql/src/include/optimizer:
        paths.h (r1.93 -> r1.93.2.1)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/include/optimizer/paths.h.diff?r1=1.93&r2=1.93.2.1)
    pgsql/src/test/regress/expected:
        join.out (r1.28 -> r1.28.2.1)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/join.out.diff?r1=1.28&r2=1.28.2.1)
        join_1.out (r1.10 -> r1.10.2.1)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/join_1.out.diff?r1=1.10&r2=1.10.2.1)
    pgsql/src/test/regress/sql:
        join.sql (r1.19 -> r1.19.2.1)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/join.sql.diff?r1=1.19&r2=1.19.2.1)

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

Предыдущее
От: tgl@postgresql.org (Tom Lane)
Дата:
Сообщение: pgsql: Restructure code that is responsible for ensuring that clauseless
Следующее
От: tgl@postgresql.org (Tom Lane)
Дата:
Сообщение: pgsql: Restructure code that is responsible for ensuring that clauseless