diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-05-17 19:44:19 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-05-17 19:44:34 -0400 |
commit | 6630ccad7a25cad32e2d1a6833fb971602cb67fe (patch) | |
tree | 9eeddfb1e56a6d202bc5711d0b84d3474af15bfb /src/include/executor | |
parent | 05685897f07e7ae5684f0247157faad1f782f889 (diff) | |
download | postgresql-6630ccad7a25cad32e2d1a6833fb971602cb67fe.tar.gz postgresql-6630ccad7a25cad32e2d1a6833fb971602cb67fe.zip |
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.
Discussion: https://postgr.es/m/FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com
Diffstat (limited to 'src/include/executor')
-rw-r--r-- | src/include/executor/execPartition.h | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/include/executor/execPartition.h b/src/include/executor/execPartition.h index b363aba2a5c..bf91b3db390 100644 --- a/src/include/executor/execPartition.h +++ b/src/include/executor/execPartition.h @@ -58,28 +58,30 @@ typedef struct PartitionRoutingInfo * PartitionedRelPruneInfo (see plannodes.h); though note that here, * subpart_map contains indexes into PartitionPruningData.partrelprunedata[]. * + * nparts Length of subplan_map[] and subpart_map[]. * subplan_map Subplan index by partition index, or -1. * subpart_map Subpart index by partition index, or -1. * present_parts A Bitmapset of the partition indexes that we * have subplans or subparts for. - * context Contains the context details required to call - * the partition pruning code. - * pruning_steps List of PartitionPruneSteps used to - * perform the actual pruning. - * do_initial_prune true if pruning should be performed during - * executor startup (for this partitioning level). - * do_exec_prune true if pruning should be performed during - * executor run (for this partitioning level). + * initial_pruning_steps List of PartitionPruneSteps used to + * perform executor startup pruning. + * exec_pruning_steps List of PartitionPruneSteps used to + * perform per-scan pruning. + * initial_context If initial_pruning_steps isn't NIL, contains + * the details needed to execute those steps. + * exec_context If exec_pruning_steps isn't NIL, contains + * the details needed to execute those steps. */ typedef struct PartitionedRelPruningData { + int nparts; int *subplan_map; int *subpart_map; Bitmapset *present_parts; - PartitionPruneContext context; - List *pruning_steps; - bool do_initial_prune; - bool do_exec_prune; + List *initial_pruning_steps; + List *exec_pruning_steps; + PartitionPruneContext initial_context; + PartitionPruneContext exec_context; } PartitionedRelPruningData; /* |