pgsql: Postpone creation of pathkeys lists to fix bug #8049. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Postpone creation of pathkeys lists to fix bug #8049.
Date
Msg-id E1UWtAM-0004dk-NO@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Postpone creation of pathkeys lists to fix bug #8049.

This patch gets rid of the concept of, and infrastructure for,
non-canonical PathKeys; we now only ever create canonical pathkey lists.

The need for non-canonical pathkeys came from the desire to have
grouping_planner initialize query_pathkeys and related pathkey lists before
calling query_planner.  However, since query_planner didn't actually *do*
anything with those lists before they'd been made canonical, we can get rid
of the whole mess by just not creating the lists at all until the point
where we formerly canonicalized them.

There are several ways in which we could implement that without making
query_planner itself deal with grouping/sorting features (which are
supposed to be the province of grouping_planner).  I chose to add a
callback function to query_planner's API; other alternatives would have
required adding more fields to PlannerInfo, which while not bad in itself
would create an ABI break for planner-related plugins in the 9.2 release
series.  This still breaks ABI for anything that calls query_planner
directly, but it seems somewhat unlikely that there are any such plugins.

I had originally conceived of this change as merely a step on the way to
fixing bug #8049 from Teun Hoogendoorn; but it turns out that this fixes
that bug all by itself, as per the added regression test.  The reason is
that now get_eclass_for_sort_expr is adding the ORDER BY expression at the
end of EquivalenceClass creation not the start, and so anything that is in
a multi-member EquivalenceClass has already been created with correct
em_nullable_relids.  I am suspicious that there are related scenarios in
which we still need to teach get_eclass_for_sort_expr to compute correct
nullable_relids, but am not eager to risk destabilizing either 9.2 or 9.3
to fix bugs that are only hypothetical.  So for the moment, do this and
stop here.

Back-patch to 9.2 but not to earlier branches, since they don't exhibit
this bug for lack of join-clause-movement logic that depends on
em_nullable_relids being correct.  (We might have to revisit that choice
if any related bugs turn up.)  In 9.2, don't change the signature of
make_pathkeys_for_sortclauses nor remove canonicalize_pathkeys, so as
not to risk more plugin breakage than we have to.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/db9f0e1d9a4a0842c814a464cdc9758c3f20b96c

Modified Files
--------------
src/backend/nodes/equalfuncs.c          |   18 +---
src/backend/optimizer/README            |   21 +---
src/backend/optimizer/path/equivclass.c |   18 ++-
src/backend/optimizer/path/pathkeys.c   |  159 +++++-------------------
src/backend/optimizer/plan/planagg.c    |   35 +++---
src/backend/optimizer/plan/planmain.c   |   52 ++------
src/backend/optimizer/plan/planner.c    |  201 +++++++++++++++++--------------
src/include/nodes/relation.h            |    2 +-
src/include/optimizer/paths.h           |    4 +-
src/include/optimizer/planmain.h        |    4 +
src/test/regress/expected/join.out      |   29 +++++
src/test/regress/sql/join.sql           |   17 +++
12 files changed, 246 insertions(+), 314 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Postpone creation of pathkeys lists to fix bug #8049.
Next
From: Peter Eisentraut
Date:
Subject: pgsql: Revert "pg_ctl: Add idempotent option"