pgsql: Restructure creation of run-time pruning steps.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

pgsql: Restructure creation of run-time pruning steps.

Tom Lane-2
Restructure creation of run-time pruning steps.

Previously, gen_partprune_steps() always built executor pruning steps
using all suitable clauses, including those containing PARAM_EXEC
Params.  This meant that the pruning steps were only completely safe
for executor run-time (scan start) pruning.  To prune at executor
startup, we had to ignore the steps involving exec Params.  But this
doesn't really work in general, since there may be logic changes
needed as well --- for example, pruning according to the last operator's
btree strategy is the wrong thing if we're not applying that operator.
The rules embodied in gen_partprune_steps() and its minions are
sufficiently complicated that tracking their incremental effects in
other logic seems quite impractical.

Short of a complete redesign, the only safe fix seems to be to run
gen_partprune_steps() twice, once to create executor startup pruning
steps and then again for run-time pruning steps.  We can save a few
cycles however by noting during the first scan whether we rejected
any clauses because they involved exec Params --- if not, we don't
need to do the second scan.

In support of this, refactor the internal APIs in partprune.c to make
more use of passing information in the GeneratePruningStepsContext
struct, rather than as separate arguments.

This is, I hope, the last piece of our response to a bug report from
Alan Jackson.  Back-patch to v11 where this code came in.




Modified Files
src/backend/executor/execPartition.c          | 180 +++---
src/backend/nodes/copyfuncs.c                 |   7 +-
src/backend/nodes/outfuncs.c                  |   7 +-
src/backend/nodes/readfuncs.c                 |   7 +-
src/backend/partitioning/partprune.c          | 784 ++++++++++++++------------
src/include/executor/execPartition.h          |  26 +-
src/include/nodes/plannodes.h                 |  24 +-
src/include/partitioning/partprune.h          |   6 -
src/test/regress/expected/partition_prune.out |  39 ++
src/test/regress/sql/partition_prune.sql      |  18 +
10 files changed, 614 insertions(+), 484 deletions(-)