pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #10207: Simple select query returns duplicate row - Critical issue
4+ messages / 4 participants
[nested] [flat]

* BUG #10207: Simple select query returns duplicate row - Critical issue
@ 2014-05-03 11:04  vetri_2020@yahoo.com
  0 siblings, 2 replies; 4+ messages in thread

From: vetri_2020@yahoo.com @ 2014-05-03 11:04 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      10207
Logged by:          Vetri
Email address:      vetri_2020@yahoo.com
PostgreSQL version: 9.2.4
Operating system:   Windows 7
Description:        

I'd encountered an issue in select query when using order by and limit.

When I sort by a column which have same values for some data,then the row
that appears in first page also appears in next page.

For example,

select * from table order by col2 limit 10;

| col1                                   | col2   |
+----------------------------------------+--------+
| {74414578-F65E-48D1-BB4A-8350A6688989} | test1  |
| {B2695B59-FE6D-4CA3-AB6C-CB773FF02A34} | test10 |
| {11239516-1A8B-4028-AA54-0E1F091F439E} | test10 |
| {CE68934B-72C7-4D5A-99F3-819A5293785F} | test13 |
| {BDAFF881-CA4A-4F0F-85AF-36B7C2200A9D} | test13 |
| {6C5EC468-25C9-49AC-8FFA-F27DB2DACDF3} | test13 |
| {B87C76A9-F450-47FC-8727-8C7F3657F885} | test13 |
| {811B5B81-4D75-4B6E-91E7-E791E56A223C} | test2  |
| {2A6C9270-ADC5-4059-A0A1-677D27E26AB9} | test3  |
| {A2F91E6F-7589-4239-BDF8-C90B11E35487} | test4  |
| {B435F056-59FE-46F3-9CE0-7C9019F38885} | test4  |
| {4EDAC233-BA9C-4058-80E0-374E02B36D06} | test5  |
| {A28B6BC7-BAED-4C7E-90E1-06A253B83D20} | test7  |
| {B8201EF9-DCEC-407E-A8E2-775CB246A0BE} | test8  |
| {1D0A1EB4-9DCD-4CAE-B66C-13EE853E41D7} | test9  |
+----------------------------------------+--------+

returns 10 rows correctly where 5th and 6th row contains same data for
col2.

Now, when I execute this query ,

select * from testsort order by col2 limit 5
;

+----------------------------------------+--------+
| col1                                   | col2   |
+----------------------------------------+--------+
| {74414578-F65E-48D1-BB4A-8350A6688989} | test1  |
| {B2695B59-FE6D-4CA3-AB6C-CB773FF02A34} | test10 |
| {11239516-1A8B-4028-AA54-0E1F091F439E} | test10 |
| {6C5EC468-25C9-49AC-8FFA-F27DB2DACDF3} | test13 |
| {BDAFF881-CA4A-4F0F-85AF-36B7C2200A9D} | test13 |
+----------------------------------------+--------+

And when I execute the below query, the issue occurs.

+----------------------------------------+--------+
| col1                                   | col2   |
+----------------------------------------+--------+
| {6C5EC468-25C9-49AC-8FFA-F27DB2DACDF3} | test13 |
| {B87C76A9-F450-47FC-8727-8C7F3657F885} | test13 |
| {811B5B81-4D75-4B6E-91E7-E791E56A223C} | test2  |
| {2A6C9270-ADC5-4059-A0A1-677D27E26AB9} | test3  |
| {A2F91E6F-7589-4239-BDF8-C90B11E35487} | test4  |
+----------------------------------------+--------+

Look at the results.This row '{6C5EC468-25C9-49AC-8FFA-F27DB2DACDF3}' occurs
two times..One in first page and also in next page.

This key '{CE68934B-72C7-4D5A-99F3-819A5293785F}' is missing in results.

Appreciate your prompt response !

Col datatype - citext




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #10207: Simple select query returns duplicate row - Critical issue
@ 2014-05-03 17:22  Marko Tiikkaja <marko@joh.to>
  parent: vetri_2020@yahoo.com
  1 sibling, 1 reply; 4+ messages in thread

From: Marko Tiikkaja @ 2014-05-03 17:22 UTC (permalink / raw)
  To: vetri_2020@yahoo.com; pgsql-bugs

On 5/3/14, 1:04 PM, vetri_2020@yahoo.com wrote:
> I'd encountered an issue in select query when using order by and limit.
>
> When I sort by a column which have same values for some data,then the row
> that appears in first page also appears in next page.

This is not a bug.  The sort order of identical values is undefined 
unless disambiguated by adding more sort expressions.

> And when I execute the below query, the issue occurs.

You didn't show the query you used here, but I'm assuming it had OFFSET 
5 or something similar.  And yes, that's still undefined behaviour, and 
not a bug.



Regards,
Marko Tiikkaja


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #10207: Simple select query returns duplicate row - Critical issue
@ 2014-05-03 17:31  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Marko Tiikkaja <marko@joh.to>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2014-05-03 17:31 UTC (permalink / raw)
  To: Marko Tiikkaja <marko@joh.to>; +Cc: vetri_2020@yahoo.com; pgsql-bugs

Marko Tiikkaja <marko@joh.to> writes:
> On 5/3/14, 1:04 PM, vetri_2020@yahoo.com wrote:
>> I'd encountered an issue in select query when using order by and limit.
>> 
>> When I sort by a column which have same values for some data,then the row
>> that appears in first page also appears in next page.

> This is not a bug.  The sort order of identical values is undefined 
> unless disambiguated by adding more sort expressions.

Somebody else asked this identical question just a couple days ago:

http://www.postgresql.org/message-id/flat/20140428192320.2661.1832@wrigleys.postgresql.org

It's not random in the sense of having any indeterminate behavior,
but the output ordering of equal-keyed elements *can* change depending
on the LIMIT value.

			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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #10207: Simple select query returns duplicate row - Critical issue
@ 2014-05-03 22:32  David G Johnston <david.g.johnston@gmail.com>
  parent: vetri_2020@yahoo.com
  1 sibling, 0 replies; 4+ messages in thread

From: David G Johnston @ 2014-05-03 22:32 UTC (permalink / raw)
  To: pgsql-bugs

The fact that two executions of a query can return the same data is not
anything like what your subject describes.  Now, if a single execution
returned a duplicate row (based on a PK) then what you said would be true.

If you need definite order you need to sort on a primary key - or something
equivalent.

David J.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-10207-Simple-select-query-returns-duplicate-row-Critical...
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2014-05-03 22:32 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-05-03 11:04 BUG #10207: Simple select query returns duplicate row - Critical issue vetri_2020@yahoo.com
2014-05-03 17:22 ` Marko Tiikkaja <marko@joh.to>
2014-05-03 17:31   ` Tom Lane <tgl@sss.pgh.pa.us>
2014-05-03 22:32 ` David G Johnston <david.g.johnston@gmail.com>

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