Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DFA951337B43 for ; Thu, 13 Jan 2011 05:07:48 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 32532-02 for ; Thu, 13 Jan 2011 09:07:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 0210F133616B for ; Thu, 13 Jan 2011 05:07:47 -0400 (AST) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p0D97lvw063379 for ; Thu, 13 Jan 2011 09:07:47 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p0D97lX2063378; Thu, 13 Jan 2011 09:07:47 GMT (envelope-from www) Date: Thu, 13 Jan 2011 09:07:47 GMT Message-Id: <201101130907.p0D97lX2063378@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #5834: Planner - cost for hash scan too small From: "Pasman" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201101/92 X-Sequence-Number: 29114 The following bug has been logged online: Bug reference: 5834 Logged by: Pasman Email address: pasman.p@gmail.com PostgreSQL version: 8.4.6 Operating system: WinXP sp2 Description: Planner - cost for hash scan too small Details: Postgres not estimate cost of creating hash index when it plans hash join. Use case: create table test1 as select i,'aaaaaaaaaa'::text as t1 from generate_series(1,10000) g(i); analyze test1; create table test2 as select i,'aaaaaaaaaa'::text as t2 from generate_series(1,10000) g(i); analyze test2; explain analyze select * from test1 natural join test2; "Hash Join (cost=280.00..685.00 rows=10000 width=26) (actual time=48.914..125.526 rows=10000 loops=1)" " Hash Cond: (test1.i = test2.i)" " -> Seq Scan on test1 (cost=0.00..155.00 rows=10000 width=15) (actual time=0.032..21.693 rows=10000 loops=1)" " -> Hash (cost=155.00..155.00 rows=10000 width=15) (actual time=48.835..48.835 rows=10000 loops=1)" " -> Seq Scan on test2 (cost=0.00..155.00 rows=10000 width=15) (actual time=0.018..24.045 rows=10000 loops=1)" "Total runtime: 146.291 ms" Cost for creating hash (155.00) is equal to cost of sequential scan on test2 but real time is 2 times bigger. I think that cost of Hash node ought to include costs of calculating hash function and inserting tuple into index: cost of seq scan + numtuples*cpu_operator_cost + numtuples*cpu_index_tuple_cost