Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZvpUi-0007QV-2f for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Nov 2015 16:40:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZvpUh-0000zY-8f for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Nov 2015 16:40:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZvhXk-0002Cv-Fd for pgsql-bugs@postgresql.org; Mon, 09 Nov 2015 08:11:12 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZvhXe-0005WI-2P for pgsql-bugs@postgresql.org; Mon, 09 Nov 2015 08:11:08 +0000 MIME-Version: 1.0 Subject: BUG #13760: order by . offset .. limit bug? when order by column has same value To: pgsql-bugs@postgresql.org From: digoal@126.com Date: Mon, 09 Nov 2015 08:10:50 +0000 Message-ID: <20151109081050.2569.72184@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13760 Logged by: digoal Email address: digoal@126.com PostgreSQL version: 9.4.5 Operating system: CentOS 6.x x64 Description: when order by column has same values, there will return (0,1) all times whatever offset x. postgres=# create table t(id int); CREATE TABLE postgres=# insert into t select 1 from generate_series(1,500); INSERT 0 500 postgres=# select row_number() over(),ctid,* from t order by id desc offset 0 limit 5; row_number | ctid | id ------------+-------+---- 2 | (0,2) | 1 3 | (0,3) | 1 4 | (0,4) | 1 5 | (0,5) | 1 1 | (0,1) | 1 (5 rows) postgres=# select row_number() over(),ctid,* from t order by id desc offset 1 limit 5; row_number | ctid | id ------------+-------+---- 3 | (0,3) | 1 4 | (0,4) | 1 5 | (0,5) | 1 6 | (0,6) | 1 1 | (0,1) | 1 (5 rows) postgres=# select row_number() over(),ctid,* from t order by id desc offset 100 limit 5; row_number | ctid | id ------------+---------+---- 102 | (0,102) | 1 103 | (0,103) | 1 104 | (0,104) | 1 105 | (0,105) | 1 1 | (0,1) | 1 (5 rows) postgres=# explain select row_number() over(),ctid,* from t order by id desc offset 100 limit 5; QUERY PLAN ---------------------------------------------------------------------- Limit (cost=33.79..33.80 rows=5 width=10) -> Sort (cost=33.54..34.79 rows=500 width=10) Sort Key: id DESC -> WindowAgg (cost=0.00..14.25 rows=500 width=10) -> Seq Scan on t (cost=0.00..8.00 rows=500 width=10) (5 rows) -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs