pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: Hitoshi Harada <umi.tanuki@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6139: LIMIT doesn't return correct result when the value is huge
Date: Tue, 02 Aug 2011 10:49:05 +0300
Message-ID: <4E37ABF1.5080609@enterprisedb.com> (raw)
In-Reply-To: <201108020625.p726PZr2034481@wwwmaster.postgresql.org>
References: <201108020625.p726PZr2034481@wwwmaster.postgresql.org>

On 02.08.2011 09:25, Hitoshi Harada wrote:
> db1=# select count(*) from test_xy;
>   count
> -------
>      31
> (1 row)
>
> db1=# select * from test_xy order by x LIMIT 9223372036854775807 OFFSET 6;
>   gid |         x          |         y
> -----+--------------------+--------------------
>    13 | -0.591943957968476 | -0.481611208406305
> (1 row)

The bug seems to occur when LIMIT + OFFSET >= 2^63. In ExecLimit 
function, we check if current position >= offset + limit, and that 
overflows.

I'll commit the attached patch to fix that. Thanks for the report

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

Attachments:

fix-large-limit+offset.patch (text/x-diff, 498B) download diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c index 85d1a6e..f2d356d 100644 --- a/src/backend/executor/nodeLimit.c +++ b/src/backend/executor/nodeLimit.c @@ -127,7 +127,7 @@ ExecLimit(LimitState *node) * the state machine state to record having done so. */ if (!node->noCount && - node->position >= node->offset + node->count) + node->position - node->offset >= node->count) { node->lstate = LIMIT_WINDOWEND; return NULL;

view thread (3+ messages)

Message-ID: <4E37ABF1.5080609@enterprisedb.com>
Permalink:  ../4E37ABF1.5080609@enterprisedb.com/
Also on:    postgresql.org/message-id/4E37ABF1.5080609@enterprisedb.com

 ·  · 

reply

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: heikki.linnakangas@enterprisedb.com, umi.tanuki@gmail.com
  Subject: Re: BUG #6139: LIMIT doesn't return correct result when the value is huge
  In-Reply-To: <4E37ABF1.5080609@enterprisedb.com>
  References: <201108020625.p726PZr2034481@wwwmaster.postgresql.org> <4E37ABF1.5080609@enterprisedb.com>

* 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