桌子:
CREATE TABLE msp_adm_munic_complet_g_01
(
nom_tri character varying(64),
ogc_fid serial NOT NULL
)
指数:
CREATE INDEX idx_gist_msp_adm_munic_complet_g_nom_tri
ON msp_adm_munic_complet_g_01
USING gist
(nom_tri COLLATE pg_catalog."default" gist_trgm_ops);
询问:
select * from msp_adm_munic_complet_g_01
ORDER BY 'potato'<->nom_tri
LIMIT 25;
问题:
为什么它通过 ORDER BY + LIMIT 组合的索引而不是当查询仅包含 ORDER BY 时?
当然,使用索引会提高查询速度
我发现的唯一解释是: http ://www.postgresql.org/docs/9.1/static/indexes-ordering.html
但它缺乏细节
编辑#1:
带有 LIMIT 的查询计划:
Limit (cost=0.00..19.27 rows=25 width=590)
-> Index Scan using idx_gist_msp_adm_munic_complet_g_nom_tri on
msp_adm_munic_complet_g_01 (cost=0.00..2784.49 rows=3612 width=590)
Order By: ((nom_tri)::text <-> 'potato'::text)
没有限制的查询计划:
Sort (cost=1847.59..1856.62 rows=3612 width=590)
Sort Key: (('potato'::text <-> (nom_tri)::text))
-> Seq Scan on msp_adm_munic_complet_g_01 (cost=0.00..682.15 rows=3612 width=590)