X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D6F4F52A1E for ; Fri, 15 Jul 2005 00:50:19 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89667-03 for ; Fri, 15 Jul 2005 03:50:10 +0000 (GMT) Received: from crestone.coronasolutions.com (crestone.coronasolutions.com [66.45.104.24]) by svr1.postgresql.org (Postfix) with ESMTP id CA5D752CC2 for ; Fri, 15 Jul 2005 00:50:07 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by crestone.coronasolutions.com (Postfix) with ESMTP id 407E564424D for ; Thu, 14 Jul 2005 21:49:43 -0600 (MDT) Received: from crestone.coronasolutions.com ([127.0.0.1]) by localhost (crestone.coronasolutions.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13970-09 for ; Thu, 14 Jul 2005 21:49:41 -0600 (MDT) Received: from [192.168.1.12] (c-24-9-24-35.hsd1.co.comcast.net [24.9.24.35]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by crestone.coronasolutions.com (Postfix) with ESMTP id 05D15644238 for ; Thu, 14 Jul 2005 21:49:41 -0600 (MDT) Mime-Version: 1.0 (Apple Message framework v730) In-Reply-To: <42D70E42.90403@arbash-meinel.com> References: <46AF8F35-B735-4DFA-BA0A-AC82B5DA3CCE@drivefaster.net> <42D687E5.7080202@arbash-meinel.com> <42D6F177.3000002@arbash-meinel.com> <42D70E42.90403@arbash-meinel.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Dan Harris Subject: Re: slow joining very large table to smaller ones Date: Thu, 14 Jul 2005 21:49:50 -0600 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.730) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at drivefaster.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200507/203 X-Sequence-Number: 13444 On Jul 14, 2005, at 7:15 PM, John A Meinel wrote: > > > Is the distribution of your rows uneven? Meaning do you have more rows > with a later id than an earlier one? > There are definitely some id's that will have many times more than the others. If I group and count them, the top 10 are fairly dominant in the table. >> > > Hmm.. How to do it permanantly? Well you could always issue "set > join_collapse set 1; select * from ...." > But obviously that isn't what you prefer. :) > > I think there are things you can do to make merge join more expensive > than a nested loop, but I'm not sure what they are. Maybe someone else has some ideas to encourage this behavior for future work? Setting it on a per-connection basis is doable, but would add some burden to us in code. > > What I really don't understand is that the estimates dropped as well. > The actual number of estimate rows drops to 3k instead of > 1M. > The real question is why does the planner think it will be so > expensive? > > >> select count(*) from k_b join k_r using (incidentid) where k_b.id=107 >> and k_r.id=94; >> count >> ------- >> 373 >> >> > > Well, this says that they are indeed much more selective. > Each one has > 1k rows, but together you end up with only 400. > Is this a bad thing? Is this not "selective enough" to make it much faster? Overall, I'm much happier now after seeing the new plan come about, if I can find a way to make that join_collapse behavior permanent, I can certainly live with these numbers. Thanks again for your continued efforts. -Dan