Re: BUG #16548: Order by on array element giving disparity in result
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: manvendra2525@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2020-07-21T14:15:15Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> postgres=# select * from bint order by a[2] desc limit 5;
> a
> ---------------
> {14}
> {10}
> {14}
> {10,14,10,10}
> {10,14,14,14}
> (5 rows)
You failed to say what you think is a bug here, but I'm going
to guess that you're unhappy that this is not the same as
the first five rows of the not-limited sort output. We do not
consider that a bug, because the sort key is very underspecified
here. The first three rows share the same sort key (null) and
can legitimately come out in any order. Likewise, rows with
a[2] = 14 can come out in any order.
The underlying implementation reason why it acts differently
is that sort-with-limit uses a different sorting method.
regards, tom lane