Postgresql 多文本列索引
我正在探索博士后如何在不同的环境下工作。我的问题涉及多列索引。假设我创建并填充下表Postgresql 多文本列索引,postgresql,Postgresql,我正在探索博士后如何在不同的环境下工作。我的问题涉及多列索引。假设我创建并填充下表 DROP TABLE IF EXISTS perf_test; create table perf_test(id int, reason text, annotation text); insert into perf_test(id, reason, annotation) select s.id, md5(random()::text), null) from generate_series(1,100
DROP TABLE IF EXISTS perf_test;
create table perf_test(id int, reason text, annotation text);
insert into perf_test(id, reason, annotation)
select s.id, md5(random()::text), null)
from generate_series(1,10000000) as s(id)
order by random();
-- do this separately to avoid the same values for both columns
UPDATE perf_test
SET annotation = md5(random()::text)
如果我运行以下查询:
EXPLAIN ANALYZE
SELECT *
FROM perf_test
WHERE reason LIKE 'bc%' AND annotation LIKE 'ab%';
我得到了并行顺序扫描,这并不奇怪。如果我为两列建立索引:
CREATE INDEX idx_perf_test_reason_annotation
ON perf_test(reason,annotation);
然后再次运行相同的查询,我得到了相同的问题:顺序扫描。为什么计划员不想切换到索引扫描?结果由大约100条记录组成(我想不是那么多)。我尝试了其他字符,只得到了几条记录,但它仍然通过顺序扫描做到了这一点。为什么即使结果由几行组成,它也不想使用索引?请回答您的问题并添加执行计划(格式文本)重新分析表?由于行数如此之多,使用的index.duplicate的成本可能不值得