From: Tom Lane <tgl@sss.pgh.pa.us>
To: lirex.software@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7499: wrong data sorting if I use "...limit 1..." SQL clause along with "...order by ..."
Date: Sun, 19 Aug 2012 23:41:44 -0400
Message-ID: <5048.1345434104@sss.pgh.pa.us> (raw)
In-Reply-To: <E1T3AWV-0005oS-Ik@wrigleys.postgresql.org>
References: <E1T3AWV-0005oS-Ik@wrigleys.postgresql.org>
lirex.software@gmail.com writes:
> 3. select id, str_last_name from tbl_owners_individual order by
> str_last_name offset 53;
> ...
> 1 | Kolesnik
> 111 | Kolesnik
> 251 | XXXXXXXXXX
> 112 | XXXXX
> ...
> 4. select id, str_last_name from tbl_owners_individual order by
> str_last_name limit 1 offset 53;
> 111 | Kolesnik
This is not a bug. Your ORDER BY does not fully determine the order of
the rows (since all rows with str_last_name = 'Kolesnik' sort the same);
so Postgres is entitled to return equivalent rows in any order, or to
select any subset of the equivalent rows for a LIMIT query.
It's not completely nondeterministic, of course, but I suspect
if you examine EXPLAIN results you'll find that different query
plans got chosen for the queries with and without LIMIT.
regards, tom lane
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, lirex.software@gmail.com
Subject: Re: BUG #7499: wrong data sorting if I use "...limit 1..." SQL clause along with "...order by ..."
In-Reply-To: <5048.1345434104@sss.pgh.pa.us>
References: <E1T3AWV-0005oS-Ik@wrigleys.postgresql.org> <5048.1345434104@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