diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index eabe2a9235..bda6adfdfc 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -3840,6 +3840,11 @@ ANY num_sync ( for more information + on partition pruning and partitioning. + diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 34da0d8d57..89735b4804 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -3760,7 +3760,7 @@ ANALYZE measurement; - Partitioning and Constraint Exclusion + Inheritance Partitioning and Constraint Exclusion constraint exclusion @@ -3768,9 +3768,8 @@ ANALYZE measurement; Constraint exclusion is a query optimization technique - that improves performance for partitioned tables defined in the - fashion described above (both declaratively partitioned tables and those - implemented using inheritance). As an example: + that improves performance for inheritance partitioned tables defined in the + fashion described above. As an example: SET constraint_exclusion = on; @@ -3847,15 +3846,14 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01'; is actually neither on nor off, but an intermediate setting called partition, which causes the technique to be - applied only to queries that are likely to be working on partitioned + applied only to queries that are likely to be working on inheritance partitioned tables. The on setting causes the planner to examine CHECK constraints in all queries, even simple ones that are unlikely to benefit. - The following caveats apply to constraint exclusion, which is used by - both inheritance and partitioned tables: + The following caveats apply to constraint exclusion: @@ -3879,9 +3877,7 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01'; contain only comparisons of the partitioning column(s) to constants using B-tree-indexable operators, which applies even to partitioned tables, because only B-tree-indexable column(s) are allowed in the - partition key. (This is not a problem when using declarative - partitioning, since the automatically generated constraints are simple - enough to be understood by the planner.) + partition key. @@ -3898,6 +3894,95 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01'; + + + Declarative Partitioning and Partition Pruning + + + partition pruning + + + + Partition Pruning is a query optimization technique + similar to constraint exclusion, but applies only to declaratively + partitioned tables. Like constraint exclusion, this uses (but is not + limited to using) the query's WHERE clause to exclude + partitions which cannot possibly contain any matching records. + + + + Unlike constraint exclusion, partition pruning can be performed much more + quickly as it does not have to scan each individual partition's metadata + to determine if the partition is required for a particular query. + + + + Partition Pruning is also more powerful than constraint exclusion as + partition pruning is not something that is performed only during the + planning of a given query. In certain cases, partition pruning may also + be performed during execution of the query as well. This allows pruning + to be performed using values which are unknown during query planning, for + example, using parameters defined in a PREPARE + statement, using a value obtained from a subquery or using parameters from + a parameterized nested loop join. + + + + The partition pruning which is performed during execution is done so at + either one or both of the following times: + + + + + During initialization of the query plan. Partition pruning can be + performed here for parameter values which are known during the + initialization phase of execution. If partition pruning can be + performed here then there is the added benefit of not having to + initialize partitions which are pruned. Partitions which are pruned + during this stage will not show up in the query's + EXPLAIN or EXPLAIN ANALYZE. It + is possible to determine the number of partitions which were removed + using this method by observing the Subplans Removed + property in the EXPLAIN output. + + + + + + During actual execution of the query plan. Partition pruning may also + be performed here to remove partitions using values which are only known + during actual query execution. This includes values from subqueries and + values from execution time parameters such as ones from parameterized + nested loop joins. Since the value of these parameters may change many + times during the execution of the query, partition pruning is performed + whenever one of the execution parameters which is being compared to a + partition column or expression changes. In order to determine if + partitions were pruned at this stage requires careful inspection of the + nloops property in the + EXPLAIN ANALYZE output. + + + + + + + Partition pruning can be disabled using the + setting. + + + + + Currently, partition pruning of partitions during the planning of an + UPDATE or DELETE command are + internally implemented using the constraint exclusion method. Only + SELECT uses the faster partition pruning method. Also + partition pruning performed during execution is only done so for the + Append node type. Both of these limitations are likely to be removed + in a future release of PostgreSQL. + + + +