0

テーブル:

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 のみが含まれている場合ではなく、ORDER BY + LIMIT の組み合わせでインデックスを通過するのはなぜですか?

もちろん、インデックスを使用すると、クエリの速度が向上します

私が見つけた唯一の説明はここにありました: 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)

NO LIMIT のクエリ プラン:

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)
4

1 に答える 1