Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a4aDj-0002uM-Tz for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Dec 2015 20:11:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a4aDj-0003dd-58 for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Dec 2015 20:11:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a4aDi-0003dA-Be for pgsql-bugs@postgresql.org; Thu, 03 Dec 2015 20:11:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a4aDf-0000v6-QJ for pgsql-bugs@postgresql.org; Thu, 03 Dec 2015 20:11:13 +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 tB3KB8UO024596; Thu, 3 Dec 2015 15:11:08 -0500 From: Tom Lane To: pbelbin@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13790: last row of limit/offset result produces duplicates In-reply-to: <20151202210220.5889.53393@wrigleys.postgresql.org> References: <20151202210220.5889.53393@wrigleys.postgresql.org> Comments: In-reply-to pbelbin@gmail.com message dated "Wed, 02 Dec 2015 21:02:20 +0000" Date: Thu, 03 Dec 2015 15:11:08 -0500 Message-ID: <24595.1449173468@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 pbelbin@gmail.com writes: > ... populated with rows where many of the 'code' rows contain the same value, > and then queried with something like: > select * from proxy_homing order by code limit 10 offset 40 > is returning the exact same result in the last row, regardless of the > offset. Sorry, this is not a bug. If you have an underspecified ORDER BY ordering, the sorting code is entitled to return equal-keyed rows in any order whatsoever, and there is no guarantee that changing the limit/offset parameters won't affect that. > changing the sorting so that it includes the match column appears to avoid > the issue, but, this is a bug. each row should only appear once if the > limit/offset values are looking at different portions of the result that > would be produced without the limit/offset options. We do not make any guarantee that that is how limit/offset works. You will only get consistent results across queries if the underlying result ordering is guaranteed consistent across queries, but that's not the case in this example. Postgres would be within its rights to return different rowsets on different executions even without any change in limit/offset, and indeed it can do so in some cases. (The technical reason why this happens in this particular case is that when using a bounded heap to do a top-N sort, which of the equal-keyed tuples survive to the end of the sort depends heavily on the exact heap size, ie the LIMIT+OFFSET sum; and the order in which the survivors end up getting output is also dependent on the exact heap size. But there are other mechanisms that could cause the results to be unstable.) 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