[pgsql-jp: 33904] Re: 異なるクエリ間のコスト比較

Tatsuo Ishii t-ishii @ sra.co.jp
2004年 8月 22日 (日) 22:59:13 JST


横から失礼.石井です.ちょっと気になったもので.

> explain analyze select tbl0.id from tbl0 where tbl0.var in (select tbl1.var from tbl1);
>                                                        QUERY PLAN                                                       
> ------------------------------------------------------------------------------------------------------------------------
>  Hash Join  (cost=94.89..125.89 rows=999 width=8) (actual time=79.994..100.874 rows=995 loops=1)
>    Hash Cond: ("outer".var = "inner".var)
>    ->  Seq Scan on tbl0  (cost=0.00..16.00 rows=1000 width=12) (actual time=0.089..6.904 rows=1000 loops=1)
>    ->  Hash  (cost=92.50..92.50 rows=958 width=4) (actual time=79.816..79.816 rows=0 loops=1)
>          ->  HashAggregate  (cost=92.50..92.50 rows=958 width=4) (actual time=66.508..73.234 rows=994 loops=1)
>                ->  Seq Scan on tbl1  (cost=0.00..80.00 rows=5000 width=4) (actual time=0.055..34.209 rows=5000 loops=1)
>  Total runtime: 107.412 ms

本当にこういうプランになるんでしょうか?HashAggregateとか出ちゃってます
が...

もし本当にこうなるんだったら8.0betaのバグっぽいので報告したいと思いま
す.

手元で Hash In Joinになるように適当にやってみた限りではこんな感じです.

test=# explain select a.aid from accounts a where a.aid in (select aid from accounts2);
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Hash IN Join  (cost=3308.00..9648.01 rows=100000 width=4)
   Hash Cond: ("outer".aid = "inner".aid)
   ->  Seq Scan on accounts a  (cost=0.00..2667.00 rows=100000 width=4)
   ->  Hash  (cost=2667.00..2667.00 rows=100000 width=4)
         ->  Seq Scan on accounts2  (cost=0.00..2667.00 rows=100000 width=4)
(5 rows)
--
Tatsuo Ishii



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