Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 44F081F02EF3 for ; Thu, 26 Apr 2012 17:28:07 -0300 (ADT) Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SNVIM-0003Ii-1r for pgsql-performance@postgresql.org; Thu, 26 Apr 2012 20:28:06 +0000 X-Originating-IP: 217.70.178.138 Received: from mfilter9-d.gandi.net (mfilter9-d.gandi.net [217.70.178.138]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 986871720B8; Thu, 26 Apr 2012 22:27:42 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter9-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter9-d.gandi.net (mfilter9-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 9wBU2hKhTdZO; Thu, 26 Apr 2012 22:27:41 +0200 (CEST) X-Originating-IP: 98.27.54.176 Received: from [192.168.10.146] (cpe-098-027-054-176.nc.res.rr.com [98.27.54.176]) (Authenticated sender: adsend@dunslane.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 3E2251720A9; Thu, 26 Apr 2012 22:27:39 +0200 (CEST) Message-ID: <4F99AFBA.4090605@dunslane.net> Date: Thu, 26 Apr 2012 16:27:38 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 MIME-Version: 1.0 To: Tom Lane CC: Thomas Kellerer , pgsql-performance@postgresql.org Subject: Re: query optimization References: <12228.1335467838@sss.pgh.pa.us> <13222.1335470935@sss.pgh.pa.us> In-Reply-To: <13222.1335470935@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/170 X-Sequence-Number: 46816 On 04/26/2012 04:08 PM, Tom Lane wrote: > Thomas Kellerer writes: >> Tom Lane wrote on 26.04.2012 21:17: >>> Um ... did you analyze all the tables, or just some of them? I get >>> sub-millisecond runtimes if all four tables have been analyzed, but it >>> does seem to pick lousy plans if, say, only a and b have been analyzed. >> Here it's similar to Richard's experience: >> Before analyzing the four tables, the first statement yields this plan: >> [ merge joins ] >> This continues to stay the plan for about 10-15 repetitions, then it turns to this plan >> [ hash joins ] > Hmm. I see it liking the merge-join plan (with minor variations) with > or without analyze data, but if just some of the tables have been > analyzed, it goes for the hash plan which is a good deal slower. The > cost estimates aren't that far apart though. In any case, the only > reason the merge join is so fast is that the data is perfectly ordered > in each table; on a less contrived example, it could well be a lot > slower. > It's not so terribly contrived, is it? It's common enough to have tables which are append-only and to join them by something that corresponds to the append order (serial field, timestamp etc.) cheers andrew