mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Allow ORDER BY, LIMIT in sub-selects. Fix most (not all) cases where
the grammar did not allow redundant parentheses around sub-selects. Distinguish LIMIT ALL from LIMIT 0; make the latter behave as one would expect.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.93 2000/10/26 21:36:09 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.94 2000/11/05 00:15:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -809,25 +809,26 @@ union_planner(Query *parse,
|
||||
if (IsA(parse->limitCount, Const))
|
||||
{
|
||||
Const *limitc = (Const *) parse->limitCount;
|
||||
int count = (int) (limitc->constvalue);
|
||||
int32 count = DatumGetInt32(limitc->constvalue);
|
||||
|
||||
/*
|
||||
* The constant can legally be either 0 ("ALL") or a
|
||||
* positive integer. If it is not ALL, we also need
|
||||
* to consider the OFFSET part of LIMIT.
|
||||
* A NULL-constant LIMIT represents "LIMIT ALL",
|
||||
* which we treat the same as no limit (ie,
|
||||
* expect to retrieve all the tuples).
|
||||
*/
|
||||
if (count > 0)
|
||||
if (!limitc->constisnull && count > 0)
|
||||
{
|
||||
tuple_fraction = (double) count;
|
||||
/* We must also consider the OFFSET, if present */
|
||||
if (parse->limitOffset != NULL)
|
||||
{
|
||||
if (IsA(parse->limitOffset, Const))
|
||||
{
|
||||
int offset;
|
||||
int32 offset;
|
||||
|
||||
limitc = (Const *) parse->limitOffset;
|
||||
offset = (int) (limitc->constvalue);
|
||||
if (offset > 0)
|
||||
offset = DatumGetInt32(limitc->constvalue);
|
||||
if (!limitc->constisnull && offset > 0)
|
||||
tuple_fraction += (double) offset;
|
||||
}
|
||||
else
|
||||
@ -850,14 +851,14 @@ union_planner(Query *parse,
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for a retrieve-into-portal, ie DECLARE CURSOR.
|
||||
* If no LIMIT, check for retrieve-into-portal, ie DECLARE CURSOR.
|
||||
*
|
||||
* We have no real idea how many tuples the user will ultimately
|
||||
* FETCH from a cursor, but it seems a good bet that he
|
||||
* doesn't want 'em all. Optimize for 10% retrieval (you
|
||||
* gotta better number?)
|
||||
*/
|
||||
if (parse->isPortal)
|
||||
else if (parse->isPortal)
|
||||
tuple_fraction = 0.10;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user