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

Commita344a6e

Browse files
author
Thomas G. Lockhart
committed
Carry column aliases from the parser frontend. Enables queries like
SELECT a FROM t1 tx (a);Allow join syntax, including queries like SELECT * FROM t1 NATURAL JOIN t2;Update RTE structure to hold column aliases in an Attr structure.
1 parent92c8437 commita344a6e

27 files changed

+1098
-320
lines changed

‎src/backend/catalog/heap.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.120 2000/01/31 04:35:48 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.121 2000/02/15 03:36:34 thomas Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -53,6 +53,7 @@
5353
#include"optimizer/planmain.h"
5454
#include"optimizer/tlist.h"
5555
#include"optimizer/var.h"
56+
#include"nodes/makefuncs.h"
5657
#include"parser/parse_clause.h"
5758
#include"parser/parse_expr.h"
5859
#include"parser/parse_relation.h"
@@ -1719,7 +1720,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
17191720
*/
17201721
rte=makeNode(RangeTblEntry);
17211722
rte->relname=RelationGetRelationName(rel);
1722-
rte->refname=RelationGetRelationName(rel);
1723+
rte->ref=makeNode(Attr);
1724+
rte->ref->relname=RelationGetRelationName(rel);
17231725
rte->relid=RelationGetRelid(rel);
17241726
rte->inh= false;
17251727
rte->inFromCl= true;
@@ -1798,7 +1800,8 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin)
17981800
*/
17991801
rte=makeNode(RangeTblEntry);
18001802
rte->relname=RelationGetRelationName(rel);
1801-
rte->refname=RelationGetRelationName(rel);
1803+
rte->ref=makeNode(Attr);
1804+
rte->ref->relname=RelationGetRelationName(rel);
18021805
rte->relid=RelationGetRelid(rel);
18031806
rte->inh= false;
18041807
rte->inFromCl= true;
@@ -1919,8 +1922,8 @@ AddRelationRawConstraints(Relation rel,
19191922
* its sole rangetable entry. We need a ParseState for transformExpr.
19201923
*/
19211924
pstate=make_parsestate(NULL);
1922-
makeRangeTable(pstate,NULL,NULL);
1923-
addRangeTableEntry(pstate,relname,relname, false, true, true);
1925+
makeRangeTable(pstate,NULL);
1926+
addRangeTableEntry(pstate,relname,makeAttr(relname,NULL), false, true, true);
19241927

19251928
/*
19261929
* Process column default expressions.

‎src/backend/commands/explain.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
66
* Portions Copyright (c) 1994-5, Regents of the University of California
77
*
8-
* $Id: explain.c,v 1.52 2000/01/26 05:56:13 momjian Exp $
8+
* $Id: explain.c,v 1.53 2000/02/15 03:36:39 thomas Exp $
99
*
1010
*/
1111

@@ -230,12 +230,12 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
230230
RangeTblEntry*rte=nth(((Scan*)plan)->scanrelid-1,es->rtable);
231231

232232
appendStringInfo(str," on ");
233-
if (strcmp(rte->refname,rte->relname)!=0)
233+
if (strcmp(rte->ref->relname,rte->relname)!=0)
234234
{
235235
appendStringInfo(str,"%s ",
236236
stringStringInfo(rte->relname));
237237
}
238-
appendStringInfo(str,stringStringInfo(rte->refname));
238+
appendStringInfo(str,stringStringInfo(rte->ref->relname));
239239
}
240240
break;
241241
caseT_TidScan:
@@ -244,12 +244,12 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
244244
RangeTblEntry*rte=nth(((TidScan*)plan)->scan.scanrelid-1,es->rtable);
245245

246246
appendStringInfo(str," on ");
247-
if (strcmp(rte->refname,rte->relname)!=0)
247+
if (strcmp(rte->ref->relname,rte->relname)!=0)
248248
{
249249
appendStringInfo(str,"%s ",
250250
stringStringInfo(rte->relname));
251251
}
252-
appendStringInfo(str,stringStringInfo(rte->refname));
252+
appendStringInfo(str,stringStringInfo(rte->ref->relname));
253253
}
254254
break;
255255
default:

‎src/backend/commands/view.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Id: view.c,v 1.41 2000/01/26 05:56:14 momjian Exp $
9+
*$Id: view.c,v 1.42 2000/02/15 03:36:39 thomas Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,6 +17,7 @@
1717
#include"catalog/heap.h"
1818
#include"commands/creatinh.h"
1919
#include"commands/view.h"
20+
#include"nodes/makefuncs.h"
2021
#include"parser/parse_relation.h"
2122
#include"parser/parse_type.h"
2223
#include"rewrite/rewriteDefine.h"
@@ -225,9 +226,11 @@ UpdateRangeTableOfViewParse(char *viewName, Query *viewParse)
225226
* create the 2 new range table entries and form the new range
226227
* table... CURRENT first, then NEW....
227228
*/
228-
rt_entry1=addRangeTableEntry(NULL, (char*)viewName,"*CURRENT*",
229+
rt_entry1=addRangeTableEntry(NULL, (char*)viewName,
230+
makeAttr("*CURRENT*",NULL),
229231
FALSE, FALSE, FALSE);
230-
rt_entry2=addRangeTableEntry(NULL, (char*)viewName,"*NEW*",
232+
rt_entry2=addRangeTableEntry(NULL, (char*)viewName,
233+
makeAttr("*NEW*",NULL),
231234
FALSE, FALSE, FALSE);
232235
new_rt=lcons(rt_entry2,old_rt);
233236
new_rt=lcons(rt_entry1,new_rt);

‎src/backend/executor/execMain.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.108 2000/02/03 00:02:58 tgl Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.109 2000/02/15 03:36:49 thomas Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
@@ -1508,7 +1508,8 @@ ExecRelCheck(Relation rel, HeapTuple tuple, EState *estate)
15081508
slot->ttc_buffer=InvalidBuffer;
15091509
slot->ttc_whichplan=-1;
15101510
rte->relname=RelationGetRelationName(rel);
1511-
rte->refname=rte->relname;
1511+
rte->ref=makeNode(Attr);
1512+
rte->ref->relname=rte->relname;
15121513
rte->relid=RelationGetRelid(rel);
15131514
/* inh, inFromCl, inJoinSet, skipAcl won't be used, leave them zero */
15141515
rtlist=lcons(rte,NIL);

‎src/backend/nodes/copyfuncs.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.104 2000/02/07 04:40:56 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.105 2000/02/15 03:37:08 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -688,6 +688,18 @@ _copyVar(Var *from)
688688
returnnewnode;
689689
}
690690

691+
staticAttr*
692+
_copyAttr(Attr*from)
693+
{
694+
Attr*newnode=makeNode(Attr);
695+
696+
if (from->relname)
697+
newnode->relname=pstrdup(from->relname);
698+
Node_Copy(from,newnode,attrs);
699+
700+
returnnewnode;
701+
}
702+
691703
/* ----------------
692704
*_copyOper
693705
* ----------------
@@ -1327,8 +1339,8 @@ _copyRangeTblEntry(RangeTblEntry *from)
13271339

13281340
if (from->relname)
13291341
newnode->relname=pstrdup(from->relname);
1330-
if (from->refname)
1331-
newnode->refname=pstrdup(from->refname);
1342+
if (from->ref)
1343+
Node_Copy(from,newnode,ref);
13321344
newnode->relid=from->relid;
13331345
newnode->inh=from->inh;
13341346
newnode->inFromCl=from->inFromCl;
@@ -1571,6 +1583,9 @@ copyObject(void *from)
15711583
caseT_Var:
15721584
retval=_copyVar(from);
15731585
break;
1586+
caseT_Attr:
1587+
retval=_copyAttr(from);
1588+
break;
15741589
caseT_Oper:
15751590
retval=_copyOper(from);
15761591
break;

‎src/backend/nodes/equalfuncs.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.59 2000/02/07 04:40:57 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.60 2000/02/15 03:37:08 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -95,6 +95,17 @@ _equalExpr(Expr *a, Expr *b)
9595
return true;
9696
}
9797

98+
staticbool
99+
_equalAttr(Attr*a,Attr*b)
100+
{
101+
if (!strcmp(a->relname,b->relname))
102+
return false;
103+
if (length(a->attrs)!=length(b->attrs))
104+
return false;
105+
106+
returnequal(a->attrs,b->attrs);
107+
}
108+
98109
staticbool
99110
_equalVar(Var*a,Var*b)
100111
{
@@ -633,14 +644,14 @@ _equalRangeTblEntry(RangeTblEntry *a, RangeTblEntry *b)
633644
if (a->relname!=b->relname)
634645
return false;
635646
}
636-
if (a->refname&&b->refname)
647+
if (a->ref&&b->ref)
637648
{
638-
if (strcmp(a->refname,b->refname)!=0)
649+
if (!equal(a->ref,b->ref))
639650
return false;
640651
}
641652
else
642653
{
643-
if (a->refname!=b->refname)
654+
if (a->ref!=b->ref)
644655
return false;
645656
}
646657
if (a->relid!=b->relid)
@@ -845,6 +856,9 @@ equal(void *a, void *b)
845856
caseT_EState:
846857
retval=_equalEState(a,b);
847858
break;
859+
caseT_Attr:
860+
retval=_equalAttr(a,b);
861+
break;
848862
caseT_Integer:
849863
caseT_String:
850864
caseT_Float:

‎src/backend/nodes/freefuncs.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/Attic/freefuncs.c,v 1.34 2000/02/07 04:40:57 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/Attic/freefuncs.c,v 1.35 2000/02/15 03:37:08 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1013,8 +1013,19 @@ _freeRangeTblEntry(RangeTblEntry *node)
10131013
{
10141014
if (node->relname)
10151015
pfree(node->relname);
1016-
if (node->refname)
1017-
pfree(node->refname);
1016+
if (node->ref)
1017+
freeObject(node->ref);
1018+
1019+
pfree(node);
1020+
}
1021+
1022+
staticvoid
1023+
_freeAttr(Attr*node)
1024+
{
1025+
if (node->relname)
1026+
pfree(node->relname);
1027+
if (node->attrs)
1028+
freeObject(node->attrs);
10181029

10191030
pfree(node);
10201031
}
@@ -1308,6 +1319,9 @@ freeObject(void *node)
13081319
caseT_TypeCast:
13091320
_freeTypeCast(node);
13101321
break;
1322+
caseT_Attr:
1323+
_freeAttr(node);
1324+
break;
13111325

13121326
/*
13131327
* VALUE NODES
@@ -1332,3 +1346,10 @@ freeObject(void *node)
13321346
break;
13331347
}
13341348
}
1349+
1350+
1351+
1352+
1353+
1354+
1355+

‎src/backend/nodes/makefuncs.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.19 2000/01/26 05:56:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.20 2000/02/15 03:37:09 thomas Exp $
1212
*
1313
* NOTES
1414
* Creator functions in POSTGRES 4.2 are generated automatically. Most of
@@ -141,3 +141,26 @@ makeConst(Oid consttype,
141141
cnst->constiscast=constiscast;
142142
returncnst;
143143
}
144+
145+
/*
146+
* makeAttr -
147+
* creates an Attr node
148+
*/
149+
Attr*
150+
makeAttr(char*relname,char*attname)
151+
{
152+
Attr*a=makeNode(Attr);
153+
154+
a->relname=pstrdup(relname);
155+
a->paramNo=NULL;
156+
if (attname!=NULL)
157+
a->attrs=lcons(makeString(pstrdup(attname)),NIL);
158+
a->indirection=NULL;
159+
160+
returna;
161+
}
162+
163+
164+
165+
166+

‎src/backend/nodes/outfuncs.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.106 2000/02/07 04:40:57 tgl Exp $
9+
*$Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.107 2000/02/15 03:37:09 thomas Exp $
1010
*
1111
* NOTES
1212
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -954,8 +954,8 @@ _outRangeTblEntry(StringInfo str, RangeTblEntry *node)
954954
{
955955
appendStringInfo(str," RTE :relname ");
956956
_outToken(str,node->relname);
957-
appendStringInfo(str," :refname ");
958-
_outToken(str,node->refname);
957+
appendStringInfo(str," :ref ");
958+
_outNode(str,node->ref);
959959
appendStringInfo(str,
960960
" :relid %u :inh %s :inFromCl %s :inJoinSet %s :skipAcl %s",
961961
node->relid,
@@ -1273,18 +1273,10 @@ _outIdent(StringInfo str, Ident *node)
12731273
staticvoid
12741274
_outAttr(StringInfostr,Attr*node)
12751275
{
1276-
List*l;
1277-
1278-
appendStringInfo(str," ATTR ");
1276+
appendStringInfo(str," ATTR :relname ");
12791277
_outToken(str,node->relname);
1280-
appendStringInfo(str," (");
1281-
foreach(l,node->attrs)
1282-
{
1283-
_outNode(str,lfirst(l));
1284-
if (lnext(l))
1285-
appendStringInfo(str," ");
1286-
}
1287-
appendStringInfo(str,")");
1278+
appendStringInfo(str," :attrs ");
1279+
_outNode(str,node->attrs);
12881280
}
12891281

12901282
staticvoid

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp