From: Tom Lane <tgl@sss.pgh.pa.us>
To: pbelbin@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13790: last row of limit/offset result produces duplicates
Date: Thu, 03 Dec 2015 15:11:08 -0500
Message-ID: <24595.1449173468@sss.pgh.pa.us> (raw)
In-Reply-To: <20151202210220.5889.53393@wrigleys.postgresql.org>
References: <20151202210220.5889.53393@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, pbelbin@gmail.com
Subject: Re: BUG #13790: last row of limit/offset result produces duplicates
In-Reply-To: <24595.1449173468@sss.pgh.pa.us>
References: <20151202210220.5889.53393@wrigleys.postgresql.org> <24595.1449173468@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox