Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 1228719BA3A5 for ; Thu, 31 May 2012 02:57:34 -0300 (ADT) Received: from nm7-vm4.bullet.mail.ne1.yahoo.com ([98.138.91.167]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SZyO4-0003GA-2g for pgsql-bugs@postgresql.org; Thu, 31 May 2012 05:57:34 +0000 Received: from [98.138.90.49] by nm7.bullet.mail.ne1.yahoo.com with NNFMP; 31 May 2012 05:57:18 -0000 Received: from [98.138.89.162] by tm2.bullet.mail.ne1.yahoo.com with NNFMP; 31 May 2012 05:57:18 -0000 Received: from [127.0.0.1] by omp1018.mail.ne1.yahoo.com with NNFMP; 31 May 2012 05:57:17 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 898940.62527.bm@omp1018.mail.ne1.yahoo.com Received: (qmail 61281 invoked by uid 60001); 31 May 2012 05:57:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1338443837; bh=6qNVl82ZNJAbzccfddFpW121vLeJB8HRCHBU6BLdzkA=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=MS8SEjdEgQ1kUKyIReDUltQDbitKAVCCpQRqPCVJk5k5odAP2vvwb0uR9v/FrVS8s3ooH0/YV+qJZ4B48weBa04RHR1WrLoPTb+7/b5Bi9mqpsGFOVylJU1Nb5chmDu5hok/UiMye4VrMy5fOsdco7itpHzigcxwmsBUMjbLtvM= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type; b=dfC7gQpI4sRJQ9Iox3BBzNm5i19dhn8Ed9Ya68rQF/39h0mWoipubPiE6NCoFEjnf4mevzg+62MXaNMoB3OOycU53JrXBjUqJ2yajxRjvClvT5F/FkorbpIz/95yjOk2lXBlzkKf8rlJvqtyuX67ck8SW853gcyG0H4od39lZ3c=; X-YMail-OSG: NeLhBBkVM1nD3zMXlzkG1XDCW5R9KVcf9gqikKI12Cj.j2q NivUpg9cpNMnVXi1JYqRwwKFsUFXdj_YP7u6qqQCIXwX5Np18.4OdkG.wVJb eLJOvWoUveJCYSI4d3kXIp1FF_a9kNdt6Wy2HLCqToHa_Q4xwwIb_xQOKs7_ VWcmFoVDbCHo_Ocyvegy.y.k0vmS.C_ZPn0euaEMqmpfTGZvB_XW09nupZbu hXqGaBuXPqPcsOBz.wOl8QNJdWgcq5Tvnz78YIJ0pu1thyrvhsKKyJ29VSuC R0kRGhx03ZJEUvDObq4Zf3BCMBbRYmwCCtf8vM_kHgnEZYiLM9Gt54_UuukZ sPKM8aFNdjfrZJmdAyfJKcET5TIvjVS0JOo5Mwqpf6MN1U5R.r3xRzAJQwTd 5DIeaN6vFBfMDUAbLBzAYc6kXs3SE Received: from [69.181.249.16] by web121105.mail.ne1.yahoo.com via HTTP; Wed, 30 May 2012 22:57:17 PDT X-Mailer: YahooMailWebService/0.8.118.349524 References: <28259.1338440604@sss.pgh.pa.us> Message-ID: <1338443837.61025.YahooMailNeo@web121105.mail.ne1.yahoo.com> Date: Wed, 30 May 2012 22:57:17 -0700 (PDT) From: Postgres User Reply-To: Postgres User Subject: Re: BUG #6668: hashjoin cost problem To: Tom Lane Cc: "pgsql-bugs@postgresql.org" In-Reply-To: <28259.1338440604@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="212935561-1935218553-1338443837=:61025" X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201205/241 X-Sequence-Number: 33212 --212935561-1935218553-1338443837=:61025 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Why is cost_hashjoin estimating 50 billion tuple comparisons for 10K rows o= f output though?=0A=0A=0A=0A________________________________=0A From: Tom L= ane =0ATo: postgresuser@yahoo.com =0ACc: pgsql-bugs@post= gresql.org =0ASent: Wednesday, May 30, 2012 10:03 PM=0ASubject: Re: [BUGS] = BUG #6668: hashjoin cost problem =0A =0Apostgresuser@yahoo.com writes:=0A> = create table small(i) as select (g/1000) * 1000 from=0A> generate_series(1,= 10000) g;=0A> create table large(i) as select generate_series(1,100000000);= =0A=0A> It doesn't matter how big the big table is... for this distribution= large=0A> table is hashed.=0A=0AI don't think that's wrong.=A0 If it hashe= s the small table, there cannot=0Abe less than 1000 entries on each populat= ed hash chain; adding more=0Awork_mem doesn't help.=A0 The planner is desig= ned to avoid hashing such=0Aunfriendly distributions as that.=A0 The fact t= hat you can get a somewhat=0Asmaller runtime by forcing hashing in the othe= r direction suggests that=0Aits cost factors are not quite right for your s= pecific case --- but it's=0Aa long way from that observation to deciding th= at we should change the=0Acost factors for everyone.=A0 In any case, the si= zes of the tables are not=0Athe only determinant of which one should be has= hed.=0A=0A=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 regards, tom lane --212935561-1935218553-1338443837=:61025 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Why is cos= t_hashjoin estimating 50 billion tuple comparisons for 10K rows of output t= hough?


From: Tom Lane <tgl@sss.pgh.pa.us>
= To: postgresuser@yahoo.com=
Cc: pgsql-bugs@postgr= esql.org
Sent: Wednes= day, May 30, 2012 10:03 PM
Subjec= t: Re: [BUGS] BUG #6668: hashjoin cost problem

=0Apostgresuser@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);
<= br>> 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 ea= ch populated hash chain; adding more
work_mem doesn't help.  The pl= anner 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 qu= ite right for your specific case --- but it's
a long way from that obser= vation to deciding that we should change the
cost factors for everyone.&= nbsp; In any case, the sizes of the tables are not
the only determinant of wh= ich one should be hashed.

        &nbs= p;   regards, tom lane


--212935561-1935218553-1338443837=:61025--