【发布时间】:2016-05-23 20:24:53
【问题描述】:
我有一个带有 B-Tree 索引的表:
CREATE INDEX idx_test_report_accession on test_report (accession);
我用解释运行以下查询:
"QUERY PLAN"
"Seq Scan on public.test_report r (cost=0.00..705829.12 rows=30694 width=1140) (actual time=0.143..6253.818 rows=11094 loops=1)"
" Output: detected_transcript_translation_id, peptide_spectrum_match_id, accession, peptide, modified_sequence, var_mod, spectrum_title, spectrum_file, confidence, mz, retention_time, precursor_mz_error_ppm, sample_name, transcript, gene_symbol, prot_seq, ref_based_location, external_identifier, experiment_name, report_filename, line_number, experiment_path"
" Filter: (r.accession ~~ 'IP_%'::text)"
" Rows Removed by Filter: 4296116"
"Planning time: 1.331 ms"
"Execution time: 6255.560 ms"
似乎认为表中只有30694行,决定不使用索引。鉴于 like 通配符是后缀,我认为没有理由不使用索引...
行数为:
SELECT count(*) from test_report r;
4307210
匹配的行数非常少:
SELECT count(*) from test_report r WHERE r.accession like 'IP_%';
11094
注意事项:
- Postgres 版本为 9.4
【问题讨论】:
-
请显示
explain (analyze, verbose)的输出。另外:您的确切 Postgres 版本是什么?旧版本需要text_pattern_ops用于create index -
@a_horse:有什么变化吗?据我所知,
text_pattern_ops对于 Unicode 整理的字段仍然是必需的。 -
感谢@a_horse_with_no_name,我增加了解释的详细程度,并按照您的建议添加了 pg 版本(9.4)
标签: postgresql