diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index ffea744cb8..76606a8535 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -3841,6 +3841,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 004ecacbbf..d02edd771f 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: @@ -3877,11 +3875,7 @@ EXPLAIN SELECT count(*) FROM measurement WHERE logdate >= DATE '2008-01-01'; range tests for range partitioning, as illustrated in the preceding examples. A good rule of thumb is that partitioning constraints should 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.) + using B-tree-indexable operators. @@ -3898,6 +3892,94 @@ 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. + + + + Partition pruning is much more efficient than constraint exclusion, since + it avoids scanning each partition's metadata to determine if the partition + is required for a particular query. + + + + Partition pruning is also more powerful than constraint exclusion as it + can be performed not only during the planning of a given query, but also + during its execution. This is useful as it can allow more partitions to + be pruned when clauses contain expressions whose values are unknown to the + query planner. For example, parameters defined in a + PREPARE statement, using a value obtained from a + subquery or using a parameterized value on the inner side of a nested loop + join. + + + + Partition pruning during execution can be performed at any 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. 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 during this phase 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 those 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 being + used by partition pruning changes. Determining if partitions were + pruned during this phase requires careful inspection of the + nloops property in the + EXPLAIN ANALYZE output. + + + + + + + Partition pruning can be disabled using the + setting. + + + + + Currently, pruning of partitions during the planning of an + UPDATE or DELETE command is + implemented using the constraint exclusion method. Only + SELECT uses the partition pruning technique. 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. + + + +