or_to_any_transform_limit

一个建议的 GUC,用于控制多个 OR 表达式如何分组到 ANY
此条目与一个提议的PostgreSQL功能相关,该功能在公开发布之前已被撤回。

or_to_any_transform_limit 是一个建议的 配置参数,用于指定 OR 表达式中元素的最小数量,超过此数量后,优化器会将多个相似的 OR 表达式分组为 ANY 表达式。

or_to_any_transform_limitPostgreSQL 17 中添加,但随后被撤回,以待进一步考虑。

默认

默认值为 or_to_any_transform_limit: 5

按 PostgreSQL 版本详细信息

or_to_any_transform_limit (PostgreSQL 17)

设置 5
单位  
类别 查询调优 / 其他规划器选项
简短描述 设置 OR 子句列表的最小长度,以尝试进行 OR 到 ANY 的转换。
扩展描述 一旦达到此限制,优化器将尝试将类似 'x=c1 OR x=c2 ..' 的表达式替换为 'x = ANY(ARRAY[c1,c2,..])' 表达式。
上下文 user
变量类型 整数
来源 默认
最小值 -1
最大值 2147483647
枚举值  
启动值 5
重置值 5
源文件  
源行  
需要重启 false

文档: or_to_any_transform_limit

变更历史

示例

or_to_any_transform_limit 的基本用法示例

postgres=# CREATE TABLE foo (
            id INT NOT NULL PRIMARY KEY
           );
CREATE TABLE

postgres=# INSERT INTO foo VALUES (generate_series(1,10));
INSERT 0 10

postgres=# SHOW or_to_any_transform_limit;
 or_to_any_transform_limit 
---------------------------
 5
(1 row)

postgres=# EXPLAIN
           SELECT *
             FROM foo
            WHERE id = 1 OR id = 2 OR id = 3 OR id = 6 OR id = 8;
                              QUERY PLAN                               
-----------------------------------------------------------------------
 Bitmap Heap Scan on foo  (cost=4.19..12.69 rows=5 width=4)
   Recheck Cond: (id = ANY ('{1,2,3,6,8}'::integer[]))
   ->  Bitmap Index Scan on foo_pkey  (cost=0.00..4.19 rows=5 width=0)
         Index Cond: (id = ANY ('{1,2,3,6,8}'::integer[]))
(4 rows)

postgres=# SET or_to_any_transform_limit = 6;
SET

postgres=# EXPLAIN                           
           SELECT *
             FROM foo
            WHERE id = 1 OR id = 2 OR id = 3 OR id = 6 OR id = 8;
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Bitmap Heap Scan on foo  (cost=20.82..29.34 rows=5 width=4)
   Recheck Cond: ((id = 1) OR (id = 2) OR (id = 3) OR (id = 6) OR (id = 8))
   ->  BitmapOr  (cost=20.82..20.82 rows=5 width=0)
         ->  Bitmap Index Scan on foo_pkey  (cost=0.00..4.16 rows=1 width=0)
               Index Cond: (id = 1)
         ->  Bitmap Index Scan on foo_pkey  (cost=0.00..4.16 rows=1 width=0)
               Index Cond: (id = 2)
         ->  Bitmap Index Scan on foo_pkey  (cost=0.00..4.16 rows=1 width=0)
               Index Cond: (id = 3)
         ->  Bitmap Index Scan on foo_pkey  (cost=0.00..4.16 rows=1 width=0)
               Index Cond: (id = 6)
         ->  Bitmap Index Scan on foo_pkey  (cost=0.00..4.16 rows=1 width=0)
               Index Cond: (id = 8)
(13 rows)

分类

GUC 配置项, 优化器, 已撤回

另请参阅

from_collapse_limit, join_collapse_limit

反馈

对“or_to_any_transform_limit”的任何评论、建议或更正请 在此提交