我使用 pg_trgm 扩展来检查文本列的相似性。我想通过使用附加条件来加速它,但没有成功。速度是一样的。这是我的例子:
create table test (
id serial,
descr text,
yesno text,
truefalse boolean
);
insert into test SELECT generate_series(1,1000000) AS id,
md5(random()::text) AS descr ;
update test set yesno = 'yes' where id < 500000;
update test set yesno = 'no' where id > 499999;
update test set truefalse = true where id < 100000;
update test set truefalse = false where id > 99999;
CREATE INDEX test_trgm_idx ON test USING gist (descr gist_trgm_ops);
因此,当我执行查询时,是否使用 where 子句没有区别。
select descr <-> '65c141ee1fdeb269d2e393cb1d3e1c09'
as dist, descr, yesno, truefalse from test
where
yesno = 'yes'
and
truefalse = true
order by dist
limit 10;
这是正确的吗?