X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A8EBD9FA2C8 for ; Wed, 17 May 2006 15:30:40 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 75954-07 for ; Wed, 17 May 2006 15:30:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 49BBD9FA279 for ; Wed, 17 May 2006 15:30:26 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k4HIUMnK024246; Wed, 17 May 2006 14:30:22 -0400 (EDT) To: Bruno Wolff III cc: "Craig A. James" , pgsql-performance@postgresql.org Subject: Re: Optimizer: limit not taken into account In-reply-to: <20060517174426.GA14567@wolff.to> References: <44699C6C.80302@tweakers.net> <4469D173.50406@sun.com> <4469D986.6090300@tweakers.net> <4469F55A.7040004@sun.com> <446A1520.2020601@tweakers.net> <446B0409.7050902@sun.com> <446B0ED2.5030909@tweakers.net> <446B474C.2050803@modgraph-usa.com> <20060517174426.GA14567@wolff.to> Comments: In-reply-to Bruno Wolff III message dated "Wed, 17 May 2006 12:44:26 -0500" Date: Wed, 17 May 2006 14:30:22 -0400 Message-ID: <24245.1147890622@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/368 X-Sequence-Number: 19155 Bruno Wolff III writes: > I suspect it wasn't intended to be a full table scan. But rather a sequential > scan until it found a matching row. If the data in the table is ordered by > by id, this strategy may not work out well. Where as if the data is randomly > ordered, it would be expected to find a match quickly. Right. You can see from the differential in the estimates for the SeqScan and the Limit nodes that the planner is not expecting the seqscan to run to completion, but rather to find a matching row quite quickly. There is not anything in there that considers whether the table's physical order is so nonrandom that the search will take much longer than it would given uniform distribution. It might be possible to do something with the correlation statistic in simple cases ... regards, tom lane