类型: 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,从而提高性能。

目前,约束排除只在用来实现表分区的情况中被默认启用。为所有表启用它会增加额外的规划开销,特别是在简单查询上并且不会产生任何好处。如果没有分区表时,最好是完全关闭它。

更多关于使用约束排除和分区的信息请参阅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.

条评论