Skip to content

Commit 2704898

Browse files
committed
Re-enable error for "SELECT ... OFFSET -1".
The executor has thrown errors for negative OFFSET values since 8.4 (see commit bfce56e), but in a moment of brain fade I taught the planner that OFFSET with a constant negative value was a no-op (commit 1a1832e). Reinstate the former behavior by only discarding OFFSET with a value of exactly 0. In passing, adjust a planner comment that referenced the ancient behavior. Back-patch to 9.3 where the mistake was introduced.
1 parent 27cef0a commit 2704898

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ preprocess_limit(PlannerInfo *root, double tuple_fraction,
23352335
{
23362336
*offset_est = DatumGetInt64(((Const *) est)->constvalue);
23372337
if (*offset_est < 0)
2338-
*offset_est = 0; /* less than 0 is same as 0 */
2338+
*offset_est = 0; /* treat as not present */
23392339
}
23402340
}
23412341
else
@@ -2496,9 +2496,8 @@ limit_needed(Query *parse)
24962496
{
24972497
int64 offset = DatumGetInt64(((Const *) node)->constvalue);
24982498

2499-
/* Executor would treat less-than-zero same as zero */
2500-
if (offset > 0)
2501-
return true; /* OFFSET with a positive value */
2499+
if (offset != 0)
2500+
return true; /* OFFSET with a nonzero value */
25022501
}
25032502
}
25042503
else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy