Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id AFD1619BA3A5 for ; Thu, 31 May 2012 02:03:37 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SZxXs-0006ZG-Pl for pgsql-bugs@postgresql.org; Thu, 31 May 2012 05:03:37 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q4V53OrH028260; Thu, 31 May 2012 01:03:24 -0400 (EDT) To: postgresuser@yahoo.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6668: hashjoin cost problem In-reply-to: References: Comments: In-reply-to postgresuser@yahoo.com message dated "Thu, 31 May 2012 00:24:49 -0000" Date: Thu, 31 May 2012 01:03:24 -0400 Message-ID: <28259.1338440604@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/234 X-Sequence-Number: 33205 postgresuser@yahoo.com writes: > create table small(i) as select (g/1000) * 1000 from > generate_series(1,10000) g; > create table large(i) as select generate_series(1,100000000); > It doesn't matter how big the big table is... for this distribution large > table is hashed. I don't think that's wrong. If it hashes the small table, there cannot be less than 1000 entries on each populated hash chain; adding more work_mem doesn't help. The planner is designed to avoid hashing such unfriendly distributions as that. The fact that you can get a somewhat smaller runtime by forcing hashing in the other direction suggests that its cost factors are not quite right for your specific case --- but it's a long way from that observation to deciding that we should change the cost factors for everyone. In any case, the sizes of the tables are not the only determinant of which one should be hashed. regards, tom lane