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

Commit3a94e78

Browse files
committed
Subselects in FROM clause, per ISO syntax: FROM (SELECT ...) [AS] alias.
(Don't forget that an alias is required.) Views reimplemented as expandingto subselect-in-FROM. Grouping, aggregates, DISTINCT in views actuallywork now (he says optimistically). No UNION support in subselects/viewsyet, but I have some ideas about that. Rule-related permissions checkingmoved out of rewriter and into executor.INITDB REQUIRED!
1 parent6f64c2e commit3a94e78

File tree

77 files changed

+3138
-2623
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3138
-2623
lines changed

‎src/backend/catalog/heap.c

Lines changed: 21 additions & 7 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.144 2000/09/1221:06:46 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.145 2000/09/29 18:21:25 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1543,8 +1543,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
15431543
rte->eref->relname=RelationGetRelationName(rel);
15441544
rte->inh= false;
15451545
rte->inFromCl= true;
1546-
rte->skipAcl= false;
1547-
adsrc=deparse_expression(expr,lcons(lcons(rte,NIL),NIL), false);
1546+
adsrc=deparse_expression(expr,makeList1(makeList1(rte)), false);
15481547

15491548
values[Anum_pg_attrdef_adrelid-1]=RelationGetRelid(rel);
15501549
values[Anum_pg_attrdef_adnum-1]=attnum;
@@ -1626,8 +1625,7 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin)
16261625
rte->eref->relname=RelationGetRelationName(rel);
16271626
rte->inh= false;
16281627
rte->inFromCl= true;
1629-
rte->skipAcl= false;
1630-
ccsrc=deparse_expression(expr,lcons(lcons(rte,NIL),NIL), false);
1628+
ccsrc=deparse_expression(expr,makeList1(makeList1(rte)), false);
16311629

16321630
values[Anum_pg_relcheck_rcrelid-1]=RelationGetRelid(rel);
16331631
values[Anum_pg_relcheck_rcname-1]=DirectFunctionCall1(namein,
@@ -1750,7 +1748,7 @@ AddRelationRawConstraints(Relation rel,
17501748
pstate=make_parsestate(NULL);
17511749
makeRangeTable(pstate,NULL);
17521750
rte=addRangeTableEntry(pstate,relname,NULL, false, true);
1753-
addRTEtoJoinTree(pstate,rte);
1751+
addRTEtoJoinList(pstate,rte);
17541752

17551753
/*
17561754
* Process column default expressions.
@@ -1774,6 +1772,14 @@ AddRelationRawConstraints(Relation rel,
17741772
if (contain_var_clause(expr))
17751773
elog(ERROR,"Cannot use attribute(s) in DEFAULT clause");
17761774

1775+
/*
1776+
* No subplans or aggregates, either...
1777+
*/
1778+
if (contain_subplans(expr))
1779+
elog(ERROR,"Cannot use subselect in DEFAULT clause");
1780+
if (contain_agg_clause(expr))
1781+
elog(ERROR,"Cannot use aggregate in DEFAULT clause");
1782+
17771783
/*
17781784
* Check that it will be possible to coerce the expression to the
17791785
* column's type. We store the expression without coercion,
@@ -1884,9 +1890,17 @@ AddRelationRawConstraints(Relation rel,
18841890
* Make sure no outside relations are referred to.
18851891
*/
18861892
if (length(pstate->p_rtable)!=1)
1887-
elog(ERROR,"Only relation'%s' can be referenced in CHECK",
1893+
elog(ERROR,"Only relation\"%s\" can be referenced in CHECK",
18881894
relname);
18891895

1896+
/*
1897+
* No subplans or aggregates, either...
1898+
*/
1899+
if (contain_subplans(expr))
1900+
elog(ERROR,"Cannot use subselect in CHECK clause");
1901+
if (contain_agg_clause(expr))
1902+
elog(ERROR,"Cannot use aggregate in CHECK clause");
1903+
18901904
/*
18911905
* Might as well try to reduce any constant expressions.
18921906
*/

‎src/backend/commands/command.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.103 2000/09/1221:06:47 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.104 2000/09/29 18:21:26 tgl Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -1135,7 +1135,7 @@ AlterTableAddConstraint(char *relationName,
11351135
else
11361136
name="<unnamed>";
11371137

1138-
constlist=lcons(constr,NIL);
1138+
constlist=makeList1(constr);
11391139

11401140
rel=heap_openr(relationName,AccessExclusiveLock);
11411141

@@ -1158,10 +1158,11 @@ AlterTableAddConstraint(char *relationName,
11581158
makeRangeTable(pstate,NULL);
11591159
rte=addRangeTableEntry(pstate,relationName,NULL,
11601160
false, true);
1161-
addRTEtoJoinTree(pstate,rte);
1161+
addRTEtoJoinList(pstate,rte);
11621162

11631163
/* Convert the A_EXPR in raw_expr into an EXPR */
1164-
expr=transformExpr(pstate,constr->raw_expr,EXPR_COLUMN_FIRST);
1164+
expr=transformExpr(pstate,constr->raw_expr,
1165+
EXPR_COLUMN_FIRST);
11651166

11661167
/*
11671168
* Make sure it yields a boolean result.
@@ -1185,14 +1186,14 @@ AlterTableAddConstraint(char *relationName,
11851186
/* And fix the opids */
11861187
fix_opids(expr);
11871188

1188-
qual=lcons(expr,NIL);
1189+
qual=makeList1(expr);
11891190

11901191
rte=makeNode(RangeTblEntry);
11911192
rte->relname=relationName;
11921193
rte->relid=RelationGetRelid(rel);
11931194
rte->eref=makeNode(Attr);
11941195
rte->eref->relname=relationName;
1195-
rtlist=lcons(rte,NIL);
1196+
rtlist=makeList1(rte);
11961197

11971198
/*
11981199
* Scan through the rows now, making the necessary things

‎src/backend/commands/explain.c

Lines changed: 73 additions & 58 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-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.58 2000/09/1221:06:47 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.59 2000/09/29 18:21:26 tgl Exp $
99
*
1010
*/
1111

@@ -176,6 +176,12 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
176176
caseT_IndexScan:
177177
pname="Index Scan";
178178
break;
179+
caseT_TidScan:
180+
pname="Tid Scan";
181+
break;
182+
caseT_SubqueryScan:
183+
pname="Subquery Scan";
184+
break;
179185
caseT_Material:
180186
pname="Materialize";
181187
break;
@@ -194,9 +200,6 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
194200
caseT_Hash:
195201
pname="Hash";
196202
break;
197-
caseT_TidScan:
198-
pname="Tid Scan";
199-
break;
200203
default:
201204
pname="???";
202205
break;
@@ -225,37 +228,27 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
225228
caseT_TidScan:
226229
if (((Scan*)plan)->scanrelid>0)
227230
{
228-
RangeTblEntry*rte=nth(((Scan*)plan)->scanrelid-1,es->rtable);
231+
RangeTblEntry*rte=rt_fetch(((Scan*)plan)->scanrelid,
232+
es->rtable);
233+
234+
/* Assume it's on a real relation */
235+
Assert(rte->relname);
229236

230237
appendStringInfo(str," on %s",
231238
stringStringInfo(rte->relname));
232-
if (rte->alias!=NULL)
233-
{
234-
if ((strcmp(rte->alias->relname,rte->relname)!=0)
235-
|| (length(rte->alias->attrs)>0))
236-
{
237-
appendStringInfo(str," %s",
238-
stringStringInfo(rte->alias->relname));
239-
240-
if (length(rte->alias->attrs)>0)
241-
{
242-
List*c;
243-
intfirstEntry= true;
244-
245-
appendStringInfo(str," (");
246-
foreach(c,rte->alias->attrs)
247-
{
248-
if (!firstEntry)
249-
{
250-
appendStringInfo(str,", ");
251-
firstEntry= false;
252-
}
253-
appendStringInfo(str,"%s",strVal(lfirst(c)));
254-
}
255-
appendStringInfo(str,")");
256-
}
257-
}
258-
}
239+
if (strcmp(rte->eref->relname,rte->relname)!=0)
240+
appendStringInfo(str," %s",
241+
stringStringInfo(rte->eref->relname));
242+
}
243+
break;
244+
caseT_SubqueryScan:
245+
if (((Scan*)plan)->scanrelid>0)
246+
{
247+
RangeTblEntry*rte=rt_fetch(((Scan*)plan)->scanrelid,
248+
es->rtable);
249+
250+
appendStringInfo(str," %s",
251+
stringStringInfo(rte->eref->relname));
259252
}
260253
break;
261254
default:
@@ -284,7 +277,8 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
284277
for (i=0;i<indent;i++)
285278
appendStringInfo(str," ");
286279
appendStringInfo(str," -> ");
287-
explain_outNode(str, ((SubPlan*)lfirst(lst))->plan,indent+2,es);
280+
explain_outNode(str, ((SubPlan*)lfirst(lst))->plan,
281+
indent+4,es);
288282
}
289283
es->rtable=saved_rtable;
290284
}
@@ -307,32 +301,12 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
307301
explain_outNode(str,innerPlan(plan),indent+3,es);
308302
}
309303

310-
/* subPlan-s */
311-
if (plan->subPlan)
312-
{
313-
List*saved_rtable=es->rtable;
314-
List*lst;
315-
316-
for (i=0;i<indent;i++)
317-
appendStringInfo(str," ");
318-
appendStringInfo(str," SubPlan\n");
319-
foreach(lst,plan->subPlan)
320-
{
321-
es->rtable= ((SubPlan*)lfirst(lst))->rtable;
322-
for (i=0;i<indent;i++)
323-
appendStringInfo(str," ");
324-
appendStringInfo(str," -> ");
325-
explain_outNode(str, ((SubPlan*)lfirst(lst))->plan,indent+4,es);
326-
}
327-
es->rtable=saved_rtable;
328-
}
329-
330-
if (nodeTag(plan)==T_Append)
304+
if (IsA(plan,Append))
331305
{
306+
Append*appendplan= (Append*)plan;
332307
List*saved_rtable=es->rtable;
333-
List*lst;
334308
intwhichplan=0;
335-
Append*appendplan= (Append*)plan;
309+
List*lst;
336310

337311
foreach(lst,appendplan->appendplans)
338312
{
@@ -351,14 +325,55 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
351325

352326
for (i=0;i<indent;i++)
353327
appendStringInfo(str," ");
354-
appendStringInfo(str,"-> ");
328+
appendStringInfo(str," -> ");
355329

356-
explain_outNode(str,subnode,indent+4,es);
330+
explain_outNode(str,subnode,indent+3,es);
357331

358332
whichplan++;
359333
}
360334
es->rtable=saved_rtable;
361335
}
336+
337+
if (IsA(plan,SubqueryScan))
338+
{
339+
SubqueryScan*subqueryscan= (SubqueryScan*)plan;
340+
Plan*subnode=subqueryscan->subplan;
341+
RangeTblEntry*rte=rt_fetch(subqueryscan->scan.scanrelid,
342+
es->rtable);
343+
List*saved_rtable=es->rtable;
344+
345+
Assert(rte->subquery!=NULL);
346+
es->rtable=rte->subquery->rtable;
347+
348+
for (i=0;i<indent;i++)
349+
appendStringInfo(str," ");
350+
appendStringInfo(str," -> ");
351+
352+
explain_outNode(str,subnode,indent+3,es);
353+
354+
es->rtable=saved_rtable;
355+
}
356+
357+
/* subPlan-s */
358+
if (plan->subPlan)
359+
{
360+
List*saved_rtable=es->rtable;
361+
List*lst;
362+
363+
for (i=0;i<indent;i++)
364+
appendStringInfo(str," ");
365+
appendStringInfo(str," SubPlan\n");
366+
foreach(lst,plan->subPlan)
367+
{
368+
es->rtable= ((SubPlan*)lfirst(lst))->rtable;
369+
for (i=0;i<indent;i++)
370+
appendStringInfo(str," ");
371+
appendStringInfo(str," -> ");
372+
explain_outNode(str, ((SubPlan*)lfirst(lst))->plan,
373+
indent+4,es);
374+
}
375+
es->rtable=saved_rtable;
376+
}
362377
}
363378

364379
staticchar*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp