可获得性
本特性自MogDB 5.0.4版本开始引入。
特性简介
A兼容模式下,支持通过GUC参数启用自动创建支持模糊匹配的索引。
特性描述
通常在MogDB中想要创建一个支持模糊匹配的索引,需要在创建索引时指定模糊匹配的操作符类(如 text_pattern_ops、varchar_pattern_ops 或 bpchar_pattern_ops)。自MogDB 5.0.4版本开始,允许使用 behavior_compat_options 参数中的 allow_like_indexable 来控制这些操作符类在索引上的使用。
特性约束
allow_like_indexable 选项仅用于控制操作符类的使用行为,在实际使用过程中需要注意:
- 创建索引前设置该参数选项;
- 确保模糊匹配操作满足操作符类的使用条件。
示例
MogDB=# create table t1(a int, b text);
CREATE TABLE
MogDB=# insert into t1 values (1, 'foo'), (2, 'bar');
INSERT 0 2
MogDB=# set behavior_compat_options='allow_like_indexable';
SET
MogDB=# create index on t1(b);
CREATE INDEX
MogDB=# explain select /*+ indexscan(t1) */ * from t1 where b like 'fo%';
QUERY PLAN
--------------------------------------------------------------------
Index Scan using t1_b_idx on t1 (cost=0.00..8.27 rows=1 width=36)
Index Cond: ((b >= 'fo'::text) AND (b < 'fp'::text))
Filter: (b ~~ 'fo%'::text)
(3 rows)
相关页面
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




