pgsql: Improve planner's handling of duplicated index column expression - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Improve planner's handling of duplicated index column expression
Date
Msg-id E1ReEoX-0006NR-MX@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Improve planner's handling of duplicated index column expressions.

It's potentially useful for an index to repeat the same indexable column
or expression in multiple index columns, if the columns have different
opclasses.  (If they share opclasses too, the duplicate column is pretty
useless, but nonetheless we've allowed such cases since 9.0.)  However,
the planner failed to cope with this, because createplan.c was relying on
simple equal() matching to figure out which index column each index qual
is intended for.  We do have that information available upstream in
indxpath.c, though, so the fix is to not flatten the multi-level indexquals
list when putting it into an IndexPath.  Then we can rely on the sublist
structure to identify target index columns in createplan.c.  There's a
similar issue for index ORDER BYs (the KNNGIST feature), so introduce a
multi-level-list representation for that too.  This adds a bit more
representational overhead, but we might more or less buy that back by not
having to search for matching index columns anymore in createplan.c;
likewise btcostestimate saves some cycles.

Per bug #6351 from Christian Rudolph.  Likely symptoms include the "btree
index keys must be ordered by attribute" failure shown there, as well as
"operator MMMM is not a member of opfamily NNNN".

Although this is a pre-existing problem that can be demonstrated in 9.0 and
9.1, I'm not going to back-patch it, because the API changes in the planner
seem likely to break things such as index plugins.  The corner cases where
this matters seem too narrow to justify possibly breaking things in a minor
release.

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/path/costsize.c      |   10 +-
src/backend/optimizer/path/indxpath.c      |  228 +++++++++++++-----
src/backend/optimizer/plan/createplan.c    |  351 +++++++++++++++++-----------
src/backend/optimizer/util/pathnode.c      |    4 +-
src/backend/optimizer/util/restrictinfo.c  |    2 +-
src/backend/utils/adt/selfuncs.c           |  204 +++++++++--------
src/include/nodes/relation.h               |   31 ++-
src/include/optimizer/paths.h              |    6 +
src/test/regress/expected/create_index.out |   24 ++
src/test/regress/expected/sanity_check.out |    3 +-
src/test/regress/output/misc.source        |    3 +-
src/test/regress/sql/create_index.sql      |   15 ++
12 files changed, 562 insertions(+), 319 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: Add bytea_agg, parallel to string_agg.
Next
From: Tom Lane
Date:
Subject: pgsql: Rethink representation of index clauses' mapping to index column