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

Commit588867b

Browse files
committed
Create SubLink nodes in parser for Vadim.
1 parent691dc28 commit588867b

File tree

10 files changed

+133
-43
lines changed

10 files changed

+133
-43
lines changed

‎src/backend/parser/analyze.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.65 1998/01/15 18:59:56 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.66 1998/01/19 05:06:13 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -53,7 +53,7 @@ List *extras = NIL;
5353
*
5454
*/
5555
QueryTreeList*
56-
parse_analyze(List*pl)
56+
parse_analyze(List*pl,ParseState*parentParseState)
5757
{
5858
QueryTreeList*result;
5959
ParseState*pstate;
@@ -65,7 +65,7 @@ parse_analyze(List *pl)
6565

6666
while (pl!=NIL)
6767
{
68-
pstate=make_parsestate();
68+
pstate=make_parsestate(parentParseState);
6969
result->qtrees[i++]=transformStmt(pstate,lfirst(pl));
7070
if (extras!=NIL)
7171
{

‎src/backend/parser/gram.y

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.93 1998/01/17 05:01:34 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.94 1998/01/19 05:06:15 momjian Exp $
1414
*
1515
* HISTORY
1616
* AUTHORDATEMAJOR EVENT
@@ -48,7 +48,7 @@
4848

4949
static char saved_relname[NAMEDATALEN]; /* need this for complex attributes */
5050
static bool QueryIsRule = FALSE;
51-
staticNode *saved_In_Expr;
51+
staticList *saved_In_Expr = NIL;
5252
static Oid*param_type_info;
5353
static intpfunc_num_args;
5454
extern List *parsetree;
@@ -242,7 +242,7 @@ Oidparam_type(int t); /* used in parse_expr.c */
242242
*/
243243

244244
/* Keywords (in SQL92 reserved words) */
245-
%tokenACTION, ADD, ALL, ALTER, AND, AS, ASC,
245+
%tokenACTION, ADD, ALL, ALTER, AND,ANYAS, ASC,
246246
BEGIN_TRANS, BETWEEN, BOTH, BY,
247247
CASCADE, CAST, CHAR, CHARACTER, CHECK, CLOSE, COLLATE, COLUMN, COMMIT,
248248
CONSTRAINT, CREATE, CROSS, CURRENT, CURRENT_DATE, CURRENT_TIME,
@@ -2871,24 +2871,52 @@ row_expr: '(' row_descriptor ')' IN '(' SubSelect ')'
28712871
{
28722872
SubLink *n = makeNode(SubLink);
28732873
n->lefthand = $2;
2874-
n->subLinkType = IN_SUBLINK;
2874+
n->oper = lcons("=",NIL);
2875+
n->useor = false;
2876+
n->subLinkType = ANY_SUBLINK;
28752877
n->subselect = $6;
28762878
$$ = (Node *)n;
28772879
}
28782880
| '(' row_descriptor ')' NOT IN '(' SubSelect ')'
28792881
{
28802882
SubLink *n = makeNode(SubLink);
28812883
n->lefthand = $2;
2882-
n->subLinkType = NOTIN_SUBLINK;
2884+
n->oper = lcons("<>",NIL);
2885+
n->useor = true;
2886+
n->subLinkType = ALL_SUBLINK;
2887+
n->subselect = $7;
2888+
$$ = (Node *)n;
2889+
}
2890+
| '(' row_descriptor ')' Op ANY '(' SubSelect ')'
2891+
{
2892+
SubLink *n = makeNode(SubLink);
2893+
n->lefthand = $2;
2894+
n->oper = lcons($4,NIL);
2895+
n->useor = false;
2896+
n->subLinkType = ANY_SUBLINK;
2897+
n->subselect = $7;
2898+
$$ = (Node *)n;
2899+
}
2900+
| '(' row_descriptor ')' Op ALL '(' SubSelect ')'
2901+
{
2902+
SubLink *n = makeNode(SubLink);
2903+
n->lefthand = $2;
2904+
n->oper = lcons($4,NIL);
2905+
n->useor = false;
2906+
n->subLinkType = ALL_SUBLINK;
28832907
n->subselect = $7;
28842908
$$ = (Node *)n;
28852909
}
28862910
| '(' row_descriptor ')' Op '(' SubSelect ')'
28872911
{
28882912
SubLink *n = makeNode(SubLink);
28892913
n->lefthand = $2;
2890-
n->subLinkType = OPER_SUBLINK;
28912914
n->oper = lcons($4, NIL);
2915+
if (strcmp($4,"<>") == 0)
2916+
n->useor = true;
2917+
else
2918+
n->useor = false;
2919+
n->subLinkType = EXPR_SUBLINK;
28922920
n->subselect = $6;
28932921
$$ = (Node *)n;
28942922
}
@@ -3114,17 +3142,13 @@ a_expr: attr opt_indirection
31143142
n->args = NIL;
31153143
$$ = (Node *)n;
31163144
}
3117-
/* We probably need to define an "exists" node,
3118-
*since the optimizer could choose to find only one match.
3119-
* Perhaps the first implementation could just check for
3120-
*count(*) > 0? - thomas 1997-07-19
3121-
*/
31223145
| EXISTS '(' SubSelect ')'
31233146
{
31243147
SubLink *n = makeNode(SubLink);
31253148
n->lefthand = NIL;
3126-
n->subLinkType =EXISTS_SUBLINK;
3149+
n->useor =false;
31273150
n->oper = NIL;
3151+
n->subLinkType = EXISTS_SUBLINK;
31283152
n->subselect = $3;
31293153
$$ = (Node *)n;
31303154
}
@@ -3239,26 +3263,52 @@ a_expr: attr opt_indirection
32393263
makeA_Expr(OP, "<", $1, $4),
32403264
makeA_Expr(OP, ">", $1, $6));
32413265
}
3242-
| a_expr IN { saved_In_Expr =$1; } '(' in_expr ')'
3266+
| a_expr IN { saved_In_Expr =lcons($1,saved_In_Expr); } '(' in_expr ')' { saved_In_Expr = lnext(saved_In_Expr); }
32433267
{
32443268
if (nodeTag($5) == T_SubLink)
32453269
{
3246-
((SubLink *)$5)->lefthand = lcons($1, NIL);
3247-
((SubLink *)$5)->subLinkType = IN_SUBLINK;
3248-
$$ = (Node *)$5;
3270+
SubLink *n = (SubLink *)$5;
3271+
n->lefthand = lcons($1, NIL);
3272+
n->oper = lcons("=",NIL);
3273+
n->useor = false;
3274+
n->subLinkType = ANY_SUBLINK;
3275+
$$ = (Node *)n;
32493276
}
32503277
else$$ = $5;
32513278
}
3252-
| a_expr NOT IN { saved_In_Expr =$1; } '(' not_in_expr ')'
3279+
| a_expr NOT IN { saved_In_Expr =lcons($1,saved_In_Expr); } '(' not_in_expr ')' { saved_In_Expr = lnext(saved_In_Expr); }
32533280
{
32543281
if (nodeTag($6) == T_SubLink)
32553282
{
3256-
((SubLink *)$6)->lefthand = lcons($1, NIL);
3257-
((SubLink *)$6)->subLinkType = NOTIN_SUBLINK;
3258-
$$ = (Node *)$6;
3283+
SubLink *n = (SubLink *)$6;
3284+
n->lefthand = lcons($1, NIL);
3285+
n->oper = lcons("<>",NIL);
3286+
n->useor = false;
3287+
n->subLinkType = ALL_SUBLINK;
3288+
$$ = (Node *)n;
32593289
}
32603290
else$$ = $6;
32613291
}
3292+
| a_expr Op ANY '(' SubSelect ')'
3293+
{
3294+
SubLink *n = makeNode(SubLink);
3295+
n->lefthand = lcons($1,NIL);
3296+
n->oper = lcons($2,NIL);
3297+
n->useor = false;
3298+
n->subLinkType = ANY_SUBLINK;
3299+
n->subselect = $5;
3300+
$$ = (Node *)n;
3301+
}
3302+
| a_expr Op ALL '(' SubSelect ')'
3303+
{
3304+
SubLink *n = makeNode(SubLink);
3305+
n->lefthand = lcons($1, NULL);
3306+
n->oper = lcons($2,NIL);
3307+
n->useor = false;
3308+
n->subLinkType = ALL_SUBLINK;
3309+
n->subselect = $5;
3310+
$$ = (Node *)n;
3311+
}
32623312
| a_expr AND a_expr
32633313
{$$ = makeA_Expr(AND, NULL, $1, $3); }
32643314
| a_expr OR a_expr
@@ -3480,10 +3530,10 @@ in_expr: SubSelect
34803530
;
34813531

34823532
in_expr_nodes: AexprConst
3483-
{$$ = makeA_Expr(OP, "=", saved_In_Expr, $1); }
3533+
{$$ = makeA_Expr(OP, "=",lfirst(saved_In_Expr), $1); }
34843534
| in_expr_nodes ',' AexprConst
34853535
{$$ = makeA_Expr(OR, NULL, $1,
3486-
makeA_Expr(OP, "=", saved_In_Expr, $3));
3536+
makeA_Expr(OP, "=",lfirst(saved_In_Expr), $3));
34873537
}
34883538
;
34893539

@@ -3498,10 +3548,10 @@ not_in_expr: SubSelect
34983548
;
34993549

35003550
not_in_expr_nodes: AexprConst
3501-
{$$ = makeA_Expr(OP, "<>", saved_In_Expr, $1); }
3551+
{$$ = makeA_Expr(OP, "<>",lfirst(saved_In_Expr), $1); }
35023552
| not_in_expr_nodes ',' AexprConst
35033553
{$$ = makeA_Expr(AND, NULL, $1,
3504-
makeA_Expr(OP, "<>", saved_In_Expr, $3));
3554+
makeA_Expr(OP, "<>",lfirst(saved_In_Expr), $3));
35053555
}
35063556
;
35073557

‎src/backend/parser/keywords.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.29 1998/01/05 03:32:22 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.30 1998/01/19 05:06:16 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -39,6 +39,7 @@ static ScanKeyword ScanKeywords[] = {
3939
{"alter",ALTER},
4040
{"analyze",ANALYZE},
4141
{"and",AND},
42+
{"any",ANY},
4243
{"append",APPEND},
4344
{"archive",ARCHIVE},
4445
{"as",AS},

‎src/backend/parser/parse_clause.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.8 1998/01/06 23:58:05 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.9 1998/01/19 05:06:17 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -387,7 +387,7 @@ transformUnionClause(List *unionClause, List *targetlist)
387387

388388
if (unionClause)
389389
{
390-
qlist=parse_analyze(unionClause);
390+
qlist=parse_analyze(unionClause,NULL);
391391

392392
for (i=0;i<qlist->len;i++)
393393
union_list=lappend(union_list,qlist->qtrees[i]);

‎src/backend/parser/parse_expr.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.7 1998/01/16 23:20:18 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.8 1998/01/19 05:06:18 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -22,6 +22,7 @@
2222
#include"nodes/params.h"
2323
#include"nodes/relation.h"
2424
#include"parse.h"
25+
#include"parser/analyze.h"
2526
#include"parser/gramparse.h"
2627
#include"parser/parse_expr.h"
2728
#include"parser/parse_func.h"
@@ -249,6 +250,42 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
249250
precedence);
250251
break;
251252
}
253+
caseT_SubLink:
254+
{
255+
SubLink*sublink= (SubLink*)expr;
256+
QueryTreeList*qtree;
257+
Query*subselect;
258+
259+
qtree=parse_analyze(lcons(sublink->subselect,NIL),pstate);
260+
261+
Assert(qtree->len==1);
262+
263+
sublink->subselect= (Node*)subselect=qtree->qtrees[0];
264+
265+
if (length(sublink->lefthand)!=
266+
length(subselect->targetList))
267+
elog(ERROR,"Subselect has too many or too few fields.");
268+
269+
if (sublink->subLinkType!=EXISTS_SUBLINK)
270+
{
271+
char*op=lfirst(sublink->oper);
272+
List*left_expr=sublink->lefthand;
273+
List*right_expr=subselect->targetList;
274+
List*elist;
275+
276+
foreach(elist,left_expr)
277+
{
278+
Node*lexpr=transformExpr(pstate,lfirst(elist),precedence);
279+
Node*rexpr=lfirst(right_expr);
280+
Expr*op_expr;
281+
282+
op_expr=make_op(op,lexpr,rexpr);
283+
sublink->oper=lappend(sublink->oper,op_expr->oper);
284+
right_expr=lnext(right_expr);
285+
}
286+
}
287+
break;
288+
}
252289
default:
253290
/* should not reach here */
254291
elog(ERROR,"transformExpr: does not know how to transform node %d",

‎src/backend/parser/parse_node.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.7 1998/01/17 04:53:19 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.8 1998/01/19 05:06:19 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -42,15 +42,16 @@ static Node *make_operand(char *opname,
4242
*/
4343

4444
ParseState*
45-
make_parsestate(void)
45+
make_parsestate(ParseState*parentParseState)
4646
{
4747
ParseState*pstate;
4848

4949
pstate=palloc(sizeof(ParseState));
5050
MemSet(pstate,0,sizeof(ParseState));
5151

5252
pstate->p_last_resno=1;
53-
53+
pstate->parentParseState=parentParseState;
54+
5455
return (pstate);
5556
}
5657

‎src/backend/parser/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.31 1997/12/22 05:42:25 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.32 1998/01/19 05:06:20 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -61,7 +61,7 @@ parser(char *str, Oid *typev, int nargs)
6161
if (yyresult)/* error */
6262
return ((QueryTreeList*)NULL);
6363

64-
queryList=parse_analyze(parsetree);
64+
queryList=parse_analyze(parsetree,NULL);
6565

6666
#ifdefSETS_FIXED
6767

‎src/include/nodes/primnodes.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: primnodes.h,v 1.13 1998/01/17 04:53:42 momjian Exp $
9+
* $Id: primnodes.h,v 1.14 1998/01/19 05:06:36 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -281,8 +281,7 @@ typedef struct Aggreg
281281
*/
282282
typedefenumSubLinkType
283283
{
284-
EXISTS_SUBLINK,ALL_SUBLINK,ANY_SUBLINK,EXPR_SUBLINK,
285-
IN_SUBLINK,NOTIN_SUBLINK,OPER_SUBLINK
284+
EXISTS_SUBLINK,ALL_SUBLINK,ANY_SUBLINK,EXPR_SUBLINK
286285
}SubLinkType;
287286

288287

‎src/include/parser/analyze.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: analyze.h,v 1.2 1997/11/26 01:13:56 momjian Exp $
8+
* $Id: analyze.h,v 1.3 1998/01/19 05:06:39 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -14,6 +14,6 @@
1414

1515
#include<parser/parse_node.h>
1616

17-
externQueryTreeList*parse_analyze(List*pl);
17+
externQueryTreeList*parse_analyze(List*pl,ParseState*parentParseState);
1818

1919
#endif/* ANALYZE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp