diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-03-30 18:58:55 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-03-30 18:58:55 -0400 |
commit | 428b260f87e8861ba8e58807b69d433db491c4f4 (patch) | |
tree | 19291c1fbbbd8cd3186b3789728ed7120a96a624 /src/backend/executor/execPartition.c | |
parent | ad3107b97324e0c8cf65932294115b6af9db8ded (diff) | |
download | postgresql-428b260f87e8861ba8e58807b69d433db491c4f4.tar.gz postgresql-428b260f87e8861ba8e58807b69d433db491c4f4.zip |
Speed up planning when partitions can be pruned at plan time.
Previously, the planner created RangeTblEntry and RelOptInfo structs
for every partition of a partitioned table, even though many of them
might later be deemed uninteresting thanks to partition pruning logic.
This incurred significant overhead when there are many partitions.
Arrange to postpone creation of these data structures until after
we've processed the query enough to identify restriction quals for
the partitioned table, and then apply partition pruning before not
after creation of each partition's data structures. In this way
we need not open the partition relations at all for partitions that
the planner has no real interest in.
For queries that can be proven at plan time to access only a small
number of partitions, this patch improves the practical maximum
number of partitions from under 100 to perhaps a few thousand.
Amit Langote, reviewed at various times by Dilip Kumar, Jesper Pedersen,
Yoshikazu Imai, and David Rowley
Discussion: https://postgr.es/m/9d7c5112-cb99-6a47-d3be-cf1ee6862a1d@lab.ntt.co.jp
Diffstat (limited to 'src/backend/executor/execPartition.c')
-rw-r--r-- | src/backend/executor/execPartition.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index cfad8a38f0f..b72db85aab4 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -1654,9 +1654,17 @@ ExecCreatePartitionPruneState(PlanState *planstate, memcpy(pprune->subplan_map, pinfo->subplan_map, sizeof(int) * pinfo->nparts); - /* Double-check that list of relations has not changed. */ - Assert(memcmp(partdesc->oids, pinfo->relid_map, - pinfo->nparts * sizeof(Oid)) == 0); + /* + * Double-check that the list of unpruned relations has not + * changed. (Pruned partitions are not in relid_map[].) + */ +#ifdef USE_ASSERT_CHECKING + for (int k = 0; k < pinfo->nparts; k++) + { + Assert(partdesc->oids[k] == pinfo->relid_map[k] || + pinfo->subplan_map[k] == -1); + } +#endif } else { |