类型: | enum |
默认: | partition |
上下文: | user |
重新开始: | false |
值: | [partition, on, off] |
控制查询规划器使用的表约束优化查询。constraint_exclusion
允许的值是 on
(检查所有表的约束), off
(永远不检查约束),以及 partition
(检查仅用于继承子表和UNION ALL
子查询的约束)。 partition
是默认设置。它往往使用继承和分区表来提高性能。
当这个参数为特定表允许时,那么规划器用查询条件和CHECK
约束进行比较,并且在查询条件和约束冲突的情况下,忽略对表的扫描。比如:CREATE TABLE parent(key integer, ...);CREATE TABLE child1000(check (key between 1000 and 1999)) INHERITS(parent);CREATE TABLE child2000(check (key between 2000 and 2999)) INHERITS(parent);...SELECT * FROM parent WHERE key = 2400; 在打开约束排除的时候,这个SELECT将完全不会扫描child1000。 这样可以提高性能。
目前,constraint exclusion默认启用, 仅适用于那些通常用来实现表分区情况。 在简单查询中为所有表强加额外开销计划而打开它是很明显的, 并且经常会产生不受益于简单查询。 如果你没有分区表,您可能更愿意将其完全关闭。
参考ddl-partitioning-constraint-exclusion获取有关使用约束排除和分区的更多信息。
建议 [EN]
Default of “partition” is fine for most users. Setting it to “on” can allow optimization of UNION queries as well, but deserves testing before production deployment.
在 StackOverflow
在 pgsql-hackers
- Check each of base restriction clauses for constant-FALSE-or-NULL
- Re: Check each of base restriction clauses for constant-FALSE-or-NULL
- Re: MergeJoin beats HashJoin in the case of multiple hash clauses
- Re: CHECK Constraint Deferrable
- Re: Removing const-false IS NULL quals and redundant IS NOT NULL quals