From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Refactor the representation of indexable clauses in IndexPaths.
Date: Sat, 09 Feb 2019 22:30:48 +0000
Message-ID: <E1gsb96-0003Ss-He@gemulon.postgresql.org> (raw)
Refactor the representation of indexable clauses in IndexPaths.
In place of three separate but interrelated lists (indexclauses,
indexquals, and indexqualcols), an IndexPath now has one list
"indexclauses" of IndexClause nodes. This holds basically the same
information as before, but in a more useful format: in particular, there
is now a clear connection between an indexclause (an original restriction
clause from WHERE or JOIN/ON) and the indexquals (directly usable index
conditions) derived from it.
We also change the ground rules a bit by mandating that clause commutation,
if needed, be done up-front so that what is stored in the indexquals list
is always directly usable as an index condition. This gets rid of repeated
re-determination of which side of the clause is the indexkey during costing
and plan generation, as well as repeated lookups of the commutator
operator. To minimize the added up-front cost, the typical case of
commuting a plain OpExpr is handled by a new special-purpose function
commute_restrictinfo(). For RowCompareExprs, generating the new clause
properly commuted to begin with is not really any more complex than before,
it's just different --- and we can save doing that work twice, as the
pretty-klugy original implementation did.
Tracking the connection between original and derived clauses lets us
also track explicitly whether the derived clauses are an exact or lossy
translation of the original. This provides a cheap solution to getting
rid of unnecessary rechecks of boolean index clauses, which previously
seemed like it'd be more expensive than it was worth.
Another pleasant (IMO) side-effect is that EXPLAIN now always shows
index clauses with the indexkey on the left; this seems less confusing.
This commit leaves expand_indexqual_conditions() and some related
functions in a slightly messy state. I didn't bother to change them
any more than minimally necessary to work with the new data structure,
because all that code is going to be refactored out of existence in
a follow-on patch.
Discussion: https://postgr.es/m/22182.1549124950@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/1a8d5afb0dfc5d0dcc6eda0656a34cb1f0cf0bdf
Modified Files
--------------
src/backend/nodes/nodeFuncs.c | 22 ++
src/backend/nodes/outfuncs.c | 17 +-
src/backend/optimizer/path/costsize.c | 43 ++-
src/backend/optimizer/path/equivclass.c | 37 +++
src/backend/optimizer/path/indxpath.c | 404 ++++++++++++++------------
src/backend/optimizer/plan/createplan.c | 332 ++++++++++-----------
src/backend/optimizer/plan/planner.c | 2 +-
src/backend/optimizer/util/clauses.c | 65 -----
src/backend/optimizer/util/pathnode.c | 17 +-
src/backend/optimizer/util/restrictinfo.c | 64 ++++
src/backend/utils/adt/selfuncs.c | 149 +++++-----
src/include/nodes/nodes.h | 1 +
src/include/nodes/pathnodes.h | 76 +++--
src/include/optimizer/clauses.h | 1 -
src/include/optimizer/pathnode.h | 1 -
src/include/optimizer/paths.h | 10 +-
src/include/optimizer/restrictinfo.h | 1 +
src/include/utils/selfuncs.h | 1 -
src/test/regress/expected/create_index.out | 13 +-
src/test/regress/expected/join.out | 16 +-
src/test/regress/expected/partition_join.out | 12 +-
src/test/regress/expected/partition_prune.out | 36 +--
22 files changed, 698 insertions(+), 622 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Refactor the representation of indexable clauses in IndexPaths.
In-Reply-To: <E1gsb96-0003Ss-He@gemulon.postgresql.org>
References: <E1gsb96-0003Ss-He@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox