首页 > 数据库 > > 表和索引-索引使用约束
下面是一个使用索引的例子:
create table table1 (c_int int,c_bigint bigint,c_varchar varchar,c_text text) with(orientation=row);
create text search configuration ts_conf_1(parser=POUND);
create text search configuration ts_conf_2(parser=POUND) with(split_flag='%');
set default_text_search_config='ts_conf_1';
create index idx1 on table1 using gin(to_tsvector(c_text));
set default_text_search_config='ts_conf_2';
create index idx2 on tscp_u_m_005_tbl using gin(to_tsvector(c_text));
select c_varchar,to_tsvector(c_varchar) from table1 where to_tsvector(c_text) @@ plainto_tsquery('¥#@……&**') and to_tsvector(c_text) @@ plainto_tsquery('某公司 ') and c_varchar is not null order by 1 desc limit 3;
该例子的关键点是表table1的同一个列c_text上建立了两个gin索引:idx1和idx2,但这两个索引是在不同default_text_search_config的设置下建立的。该例子和同一张表的同一个列上建立普通索引的不同之处在于:
因此当执行同一个查询时,使用idx1和idx2查询出的结果是不同的。
通过上面的例子,索引使用满足如下条件时:
为了避免使用不同gin索引导致查询结果不同的问题,需要保证在物理表的一列上只有一个gin索引可用。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69959250/viewspace-3170705/ ,如需转载,请注明出处,否则将追究法律责任。