本文介绍如何为单个主表创建多个搜索索引。
前提条件
使用限制
单个主表上最多支持创建5个搜索索引。
同一个主表上的搜索索引不允许相互同名、不允许与其它类型的索引同名。
使用方法
创建宽表。
create table testTable (pk int, c1 int, c2 varchar, c3 long, primary key(pk));说明Lindorm搜索索引的多索引特性目前处于公测阶段,如需体验该功能,请联系Lindorm技术支持(钉钉号:s0s3eg3)开启。
在同一个宽表上可建立多个搜索索引。每个搜索索引的索引列及属性可以相同。
create index idx1 using search on testTable (c1,c2); create index idx2 using search on testTable (c3); create index idx3 using search on testTable (c1,c2,c3);向宽表中写入数据,数据会同步到每个搜索索引中。
upsert into testTable(pk,c1,c2,c3) values (1,1,'1',1); upsert into testTable(pk,c1,c2,c3) values (2,2,'2',2); upsert into testTable(pk,c1,c2,c3) values (3,3,'3',3); upsert into testTable(pk,c1,c2,c3) values (4,4,'4',4);数据查询。根据查询条件的不同,将自动选择合适的搜索索引。如果有多个搜索索引均覆盖了查询条件,将会选择其中一个。
查询c1、c2和c3列,自动选择索引idx3。
select * from testTable where c1>0 and c2>'0' and c3>0;查询c1和c2列,索引idx1和idx3均可覆盖,将会选择索引idx1或idx3。
select * from testTable where c1>0 and c2>'0';查询c3列,索引idx2和idx3均可覆盖,将会选择索引idx2或idx3。
select * from testTable where c3>0;
查询时显式指定索引。
可通过HINT语法显式指定某个搜索索引用于查询。
select /*+ _l_force_index_('idx1') */ * from testTable where c1>0 and c2>'0';控制索引的状态。
可通过ALTER INDEX语句独立控制各个索引的状态。
alter index idx1 on testTable inactive; alter index idx1 on testTable disabled;状态值
说明
ACTIVE
该搜索索引可用于查询,宽表数据会自动构建索引。
INACTIVE
该搜索索引不可用于查询,宽表数据仍然会自动构建索引。
DISABLED
该搜索索引不可用于查询,宽表数据不会构建索引。
说明处于DISABLED状态的搜索索引,不能够再切换到其他状态,需要执行REBUILD才可重新启用。
该文章对您有帮助吗?