Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T3IsA-0002nL-KF for pgsql-bugs@postgresql.org; Mon, 20 Aug 2012 03:41:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T3Is7-0005sI-CP for pgsql-bugs@postgresql.org; Mon, 20 Aug 2012 03:41:50 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q7K3fima005049; Sun, 19 Aug 2012 23:41:44 -0400 (EDT) From: Tom Lane 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 ..." In-reply-to: References: Comments: In-reply-to lirex.software@gmail.com message dated "Sun, 19 Aug 2012 18:46:55 -0000" Date: Sun, 19 Aug 2012 23:41:44 -0400 Message-ID: <5048.1345434104@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/140 X-Sequence-Number: 33864 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