Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11f7b29

Browse files
committed
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 wouldexpect.
1 parent66436e6 commit11f7b29

File tree

8 files changed

+388
-218
lines changed

8 files changed

+388
-218
lines changed

‎src/backend/executor/nodeLimit.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeLimit.c,v 1.1 2000/10/26 21:35:15 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeLimit.c,v 1.2 2000/11/05 00:15:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -188,17 +188,11 @@ recompute_limits(Limit *node)
188188
econtext,
189189
&isNull,
190190
NULL));
191-
/* Interpret NULL count as no count */
191+
/* Interpret NULL count as no count(LIMIT ALL)*/
192192
if (isNull)
193193
limitstate->noCount= true;
194-
else
195-
{
196-
/* Currently, LIMIT 0 is specified as meaning no limit.
197-
* I think this is pretty bogus, but ...
198-
*/
199-
if (limitstate->count <=0)
200-
limitstate->noCount= true;
201-
}
194+
elseif (limitstate->count<0)
195+
limitstate->count=0;
202196
}
203197
else
204198
{

‎src/backend/nodes/copyfuncs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.128 2000/10/31 10:22:10 petere Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.129 2000/11/05 00:15:52 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1826,6 +1826,7 @@ _copySelectStmt(SelectStmt *from)
18261826
Node_Copy(from,newnode,distinctClause);
18271827
if (from->into)
18281828
newnode->into=pstrdup(from->into);
1829+
newnode->istemp=from->istemp;
18291830
Node_Copy(from,newnode,targetList);
18301831
Node_Copy(from,newnode,fromClause);
18311832
Node_Copy(from,newnode,whereClause);
@@ -1835,10 +1836,13 @@ _copySelectStmt(SelectStmt *from)
18351836
if (from->portalname)
18361837
newnode->portalname=pstrdup(from->portalname);
18371838
newnode->binary=from->binary;
1838-
newnode->istemp=from->istemp;
18391839
Node_Copy(from,newnode,limitOffset);
18401840
Node_Copy(from,newnode,limitCount);
18411841
Node_Copy(from,newnode,forUpdate);
1842+
newnode->op=from->op;
1843+
newnode->all=from->all;
1844+
Node_Copy(from,newnode,larg);
1845+
Node_Copy(from,newnode,rarg);
18421846

18431847
returnnewnode;
18441848
}

‎src/backend/nodes/equalfuncs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.78 2000/10/31 10:22:10 petere Exp $
23+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.79 2000/11/05 00:15:52 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -686,6 +686,8 @@ _equalSelectStmt(SelectStmt *a, SelectStmt *b)
686686
return false;
687687
if (!equalstr(a->into,b->into))
688688
return false;
689+
if (a->istemp!=b->istemp)
690+
return false;
689691
if (!equal(a->targetList,b->targetList))
690692
return false;
691693
if (!equal(a->fromClause,b->fromClause))
@@ -702,14 +704,20 @@ _equalSelectStmt(SelectStmt *a, SelectStmt *b)
702704
return false;
703705
if (a->binary!=b->binary)
704706
return false;
705-
if (a->istemp!=b->istemp)
706-
return false;
707707
if (!equal(a->limitOffset,b->limitOffset))
708708
return false;
709709
if (!equal(a->limitCount,b->limitCount))
710710
return false;
711711
if (!equal(a->forUpdate,b->forUpdate))
712712
return false;
713+
if (a->op!=b->op)
714+
return false;
715+
if (a->all!=b->all)
716+
return false;
717+
if (!equal(a->larg,b->larg))
718+
return false;
719+
if (!equal(a->rarg,b->rarg))
720+
return false;
713721

714722
return true;
715723
}

‎src/backend/optimizer/plan/planner.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.93 2000/10/26 21:36:09 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.94 2000/11/05 00:15:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -809,25 +809,26 @@ union_planner(Query *parse,
809809
if (IsA(parse->limitCount,Const))
810810
{
811811
Const*limitc= (Const*)parse->limitCount;
812-
intcount=(int)(limitc->constvalue);
812+
int32count=DatumGetInt32(limitc->constvalue);
813813

814814
/*
815-
*Theconstantcan legally be either 0 ("ALL") or a
816-
*positive integer. If it is not ALL, we also need
817-
* toconsidertheOFFSET part of LIMIT.
815+
*A NULL-constantLIMIT represents "LIMITALL",
816+
*which we treat the same as no limit (ie,
817+
*expecttoretrieve allthetuples).
818818
*/
819-
if (count>0)
819+
if (!limitc->constisnull&&count>0)
820820
{
821821
tuple_fraction= (double)count;
822+
/* We must also consider the OFFSET, if present */
822823
if (parse->limitOffset!=NULL)
823824
{
824825
if (IsA(parse->limitOffset,Const))
825826
{
826-
intoffset;
827+
int32offset;
827828

828829
limitc= (Const*)parse->limitOffset;
829-
offset=(int)(limitc->constvalue);
830-
if (offset>0)
830+
offset=DatumGetInt32(limitc->constvalue);
831+
if (!limitc->constisnull&&offset>0)
831832
tuple_fraction+= (double)offset;
832833
}
833834
else
@@ -850,14 +851,14 @@ union_planner(Query *parse,
850851
}
851852

852853
/*
853-
*Check for a retrieve-into-portal, ie DECLARE CURSOR.
854+
*If no LIMIT, check for retrieve-into-portal, ie DECLARE CURSOR.
854855
*
855856
* We have no real idea how many tuples the user will ultimately
856857
* FETCH from a cursor, but it seems a good bet that he
857858
* doesn't want 'em all. Optimize for 10% retrieval (you
858859
* gotta better number?)
859860
*/
860-
if (parse->isPortal)
861+
elseif (parse->isPortal)
861862
tuple_fraction=0.10;
862863
}
863864

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp