Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WNm72-00006G-Lt for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Mar 2014 16:34:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WNm72-0006Xz-5m for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Mar 2014 16:34:36 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WNm71-0006Xs-3q for pgsql-bugs@postgresql.org; Wed, 12 Mar 2014 16:34:35 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WNm6y-0003aU-Li for pgsql-bugs@postgresql.org; Wed, 12 Mar 2014 16:34:34 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1WNm6x-0001j9-ND for pgsql-bugs@postgresql.org; Wed, 12 Mar 2014 09:34:31 -0700 Date: Wed, 12 Mar 2014 09:34:31 -0700 (PDT) From: David Johnston To: pgsql-bugs@postgresql.org Message-ID: <1394642071713-5795717.post@n5.nabble.com> In-Reply-To: <53206541.8060200@comcast.net> References: <30655A2C-145C-4DB1-8BF4-F5C3DF6772AB@wmaker.net> <53206541.8060200@comcast.net> Subject: Re: LIMIT causes huge slow down MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 4.5 (++++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Harry Rossignol wrote > hello > > i am just a lowly application developer, but i always include my 'where' > fields in my order by specification. > I.E. ORDER BY id_webzine,id_flickr,id_picasa,id_photo rather then just > id_photo You really should consider thinking about what you need rather than blindly adhering to a rule that puts additional burden on the system when it may not be necessary. WRT to question posed: probably the easiest workaround is to move the unlimited query to a WITH clause and then apply the limit separately. You should indicate what version of PostgreSQL you are using. Sorry I'm not much help on the how and why of the actual plan choices here. The sorting is constant but since the limit and the where clause target different tables a full evaluation is needed to determine a solution so picking individual rows, which is what I see happening, doesn't by you anything. But, for all I know your using an old version and this undesirable behavior has already been found and fixed. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/LIMIT-causes-huge-slow-down-tp5795640p5795717.html Sent from the PostgreSQL - bugs mailing list archive at Nabble.com. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs