[pgsql-jp: 32530] インデックスが使用されません。
gotou
gotou @ hokkou.co.jp
2004年 3月 22日 (月) 13:47:26 JST
いつもお世話になっております。ごとうです。
現在抱えている問題は、テーブルの検索時にインデックスが使用されていない、
と言う問題です。
元は、SQLServer にあったデータを ODBCでAccessを通して、移行しました。
テーブルの構造は
Table "public.postrn"
Column | Type | Modifiers
-------------+------------------------+-----------
d_index | character varying(50) | not null
br_cd | integer |
reji_cd | integer |
yy | integer |
mm | integer |
dd | integer |
:
gd_cd | double precision |
no_ent_sc | integer |
gd_nm | character varying(100) |
gd_no | integer |
can_riyu | integer |
gr_cd | integer |
bm_cd | integer |
bu_cd | integer |
hi_cd | integer |
you_cd | integer |
:
yyyymmdd | character varying(50) |
となっております。
(カラム数が多分にあるため関連なさそうなものは省略しています。)
インデックスの定義は
CREATE UNIQUE INDEX p_postrn_idx ON postrn(d_index);
CREATE INDEX postrn_br ON postrn(br_cd);
CREATE INDEX postrn_yy ON postrn(yy);
CREATE INDEX postrn_mm ON postrn(mm);
CREATE INDEX postrn_dd ON postrn(dd);
CREATE INDEX postrn_gd ON postrn(gd_cd);
CREATE INDEX postrn_gr ON postrn(gr_cd);
CREATE INDEX postrn_bm ON postrn(bm_cd);
CREATE INDEX postrn_bu ON postrn(bu_cd);
CREATE INDEX postrn_hi ON postrn(hi_cd);
CREATE INDEX postrn_dt ON postrn(yyyymmdd);
このように作成しています。
レコード件数は、300万件以上あります。
インデックスを作成した後に、Vacuum を行い、簡単な検索クエリを
投げてみましたが、Index Scan ではなく、Seq Scan で行われ、
結果が返ってくるのに、一分以上かかっています。
****************************************************************
=# explain analyze
-# select yy from postrn where br_cd=101 and yy=2002 group by yy;
QUERY PLAN
----------------------------------------------------------------------------
----------------------------
Group (cost=183882.37..184484.81 rows=12049 width=4) (actual
time=43168.95..43168.95 rows=1 loops=1)
-> Sort (cost=183882.37..184183.59 rows=120489 width=4) (actual
time=42972.54..43086.08 rows=121951 loops=1)
Sort Key: yy
-> Seq Scan on postrn (cost=0.00..172820.04 rows=120489 width=4)
(actual time=12.00..42777.25 rows=121951 loops=1)
Filter: ((br_cd = 101) AND (yy = 2002))
Total runtime: 43170.18 msec
(6 rows)
***************************************************************
ほとんど同じテーブル構造の postrn2 というテーブルに同じクエリを投げると、
Index Scan で検索が行われます。
postrn2 のレコード件数は、50万弱というところです。
何か、心当たりのある方はお知らせ願えますでしょうか?
よろしくお願いします。
最後になりましたが、Versionは
RedHat Linux 9.0
PostgreSQL 7.3.4
です。
pgsql-jp メーリングリストの案内