[pgsql-jp: 29031] Re: Like を使った前方一致検索時のインデックス使用条件について

ISHIDA Akio iakio @ pjam.jpweb.net
2003年 2月 13日 (木) 21:48:22 JST


石田@苫小牧市です。追試。
あんまりよいテストデータではないなと思ったので、

a ='AA'
(1..10000).each {
  print "#{a[-2..-1]}" + sprintf("%04d",rand(10000)) + "\n"
  a.succ!
}
と、最後 4 ケタを乱数にしてみました。
# なんか変なソースかも。私の ruby の能力がバレバレ。

ishida=> EXPLAIN SELECT * from t1 WHERE f LIKE 'A%';
                      QUERY PLAN
-------------------------------------------------------
 Seq Scan on t1  (cost=0.00..180.00 rows=253 width=10)
   Filter: (f ~~ 'A%'::text)
(2 rows)

ishida=> EXPLAIN SELECT * from t1 WHERE f LIKE 'AA%';
                            QUERY PLAN
------------------------------------------------------------------
 Index Scan using t_idx on t1  (cost=0.00..33.04 rows=8 width=10)
   Index Cond: ((f >= 'AA'::text) AND (f < 'AB'::text))
   Filter: (f ~~ 'AA%'::text)
(3 rows)

ishida=> EXPLAIN SELECT * from t1 WHERE f LIKE 'BB%';
                            QUERY PLAN
-------------------------------------------------------------------
 Index Scan using t_idx on t1  (cost=0.00..38.10 rows=10 width=10)
   Index Cond: ((f >= 'BB'::text) AND (f < 'BC'::text))
   Filter: (f ~~ 'BB%'::text)
(3 rows)

-- 
ISHIDA Akio




pgsql-jp メーリングリストの案内