Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WeuYs-0005gg-Rl for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Apr 2014 23:02:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WeuYr-0005tM-Ut for pgsql-bugs@arkaria.postgresql.org; Mon, 28 Apr 2014 23:02:09 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WeuYp-0005tD-SB for pgsql-bugs@postgresql.org; Mon, 28 Apr 2014 23:02:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WeuYm-0005od-PK for pgsql-bugs@postgresql.org; Mon, 28 Apr 2014 23:02:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s3SN23wu029990; Mon, 28 Apr 2014 19:02:03 -0400 From: Tom Lane To: sluggy.fan@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #10164: Inconsistent Order When Limit is Applied In-reply-to: <20140428192320.2661.1832@wrigleys.postgresql.org> References: <20140428192320.2661.1832@wrigleys.postgresql.org> Comments: In-reply-to sluggy.fan@gmail.com message dated "Mon, 28 Apr 2014 19:23:20 -0000" Date: Mon, 28 Apr 2014 19:02:03 -0400 Message-ID: <29989.1398726123@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) 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 sluggy.fan@gmail.com writes: > The documentation states that when the ordered fields all have the same > value, that the order is implementation-dependent, but shouldn't that > implementation be consistent no matter what the LIMIT is? Uh, no. The code is entitled to return the rows containing lower(field1) = 't' in any order, and there's no reason to think it will make the same decisions with different LIMITs. (The technical reason for this is that it's a heapsort with a bounded number of heap elements, so the exact contents of the heap at the end of the input scan will vary depending on your LIMIT, and heapsort isn't stable so the positions of equal-keyed elements after sorting can vary.) If you want a guaranteed ordering of the rows you'll need to specify additional sort columns to break ties. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs