Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 1EC739FB6A6 for ; Mon, 25 Jun 2007 22:07:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 05193-07 for ; Mon, 25 Jun 2007 22:07:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 1A4899FB63F for ; Mon, 25 Jun 2007 22:07:16 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l5Q17E2e008931; Mon, 25 Jun 2007 21:07:14 -0400 (EDT) To: Ed Tyrrill cc: pgsql-performance@postgresql.org Subject: Re: In-reply-to: <1182816598.6477.31.camel@nickel.avamar.com> References: <7008.1182809415@sss.pgh.pa.us> <1182816598.6477.31.camel@nickel.avamar.com> Comments: In-reply-to Ed Tyrrill message dated "Mon, 25 Jun 2007 17:09:58 -0700" Date: Mon, 25 Jun 2007 21:07:14 -0400 Message-ID: <8930.1182820034@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/595 X-Sequence-Number: 25628 Ed Tyrrill writes: > It seems to me that the first plan is the optimal one for this case, but > when the planner has more information about the table it chooses not to > use it. Do you think that if work_mem were higher it might choose the > first plan again? It's worth fooling around with work_mem just to see what happens. The other thing that would be interesting is to force the other plan (set enable_mergejoin = off) just to see what the planner is costing it at. My suspicion is that the estimated costs are pretty close. The ANALYZE stats affect this choice only in second-order ways AFAIR. The planner penalizes hashes if it thinks there will be a lot of duplicate values in the inner relation, but IIRC there is also a penalty for inner duplicates in the mergejoin cost estimate. So I'm a bit surprised that there'd be a change. Can you show us the pg_stats rows for the join columns after analyzing at target 10 and target 100? regards, tom lane