Behavior of "OFFSET -1" - Mailing list pgsql-hackers

From Tom Lane
Subject Behavior of "OFFSET -1"
Date
Msg-id 28520.1406047777@sss.pgh.pa.us
Whole thread Raw
Responses Re: Behavior of "OFFSET -1"  (Robert Haas <robertmhaas@gmail.com>)
Re: Behavior of "OFFSET -1"  (David Fetter <david@fetter.org>)
List pgsql-hackers
Before 9.3, you got an error from this:

regression=# select * from tenk1 offset -1;
ERROR:  OFFSET must not be negative

But 9.3 and up ignore the negative OFFSET.  This seems to be a thinko in
my commit 1a1832eb.  limit_needed() thinks it can discard the Limit plan
node altogether, which of course prevents nodeLimit.c from complaining:
               /* Executor would treat less-than-zero same as zero */               if (offset > 0)
returntrue;    /* OFFSET with a positive value */
 

I don't recall the reasoning behind that comment for sure, but I imagine
I examined the behavior of ExecLimit() and failed to notice that there
was an error check in recompute_limits().

This seems to me to be a clear bug: we should reinstate the former
behavior by tightening this check so it only discards OFFSET with a
constant value of exactly 0.  Anyone think differently?
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [COMMITTERS] pgsql: Diagnose incompatible OpenLDAP versions during build and test.
Next
From: Andrew Dunstan
Date:
Subject: Re: Some bogus results from prairiedog