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

Commit2ffa740

Browse files
committed
Fix ruleutils to cope with conflicts from adding/dropping/renaming columns.
In commit11e1318, we improved therule/view dumping code so that it would produce valid query representationseven if some of the tables involved in a query had been renamed since thequery was parsed. This patch extends that idea to fix problems that occurwhen individual columns are renamed, or added or dropped. As before, thecore of the fix is to assign unique new aliases when a name conflict hasbeen created. This is complicated by the JOIN USING feature, whichrequires the same column alias to be used in both input relations, but wecan handle that with a sufficiently complex approach to assigning aliases.A fortiori, this patch takes care of situations where the query didn't haveunique column names to begin with, such as in a recent complaint from BryanNuse. (Because of expansion of "SELECT *", re-parsing a dumped query canrequire column name uniqueness even though the original text did not.)
1 parent7eb559a commit2ffa740

File tree

5 files changed

+1764
-254
lines changed

5 files changed

+1764
-254
lines changed

‎src/backend/commands/explain.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,9 @@ elapsed_time(instr_time *starttime)
653653
* Prescan the planstate tree to identify which RTEs are referenced
654654
*
655655
* Adds the relid of each referenced RTE to *rels_used. The result controls
656-
* which RTEs are assigned aliases by select_rtable_names_for_explain.This
657-
* ensures that we don't confusingly assign un-suffixed aliases to RTEs that
658-
* never appear in the EXPLAIN output (such as inheritance parents).
656+
* which RTEs are assigned aliases by select_rtable_names_for_explain.
657+
*Thisensures that we don't confusingly assign un-suffixed aliases to RTEs
658+
*thatnever appear in the EXPLAIN output (such as inheritance parents).
659659
*/
660660
staticvoid
661661
ExplainPreScanNode(PlanState*planstate,Bitmapset**rels_used)
@@ -1954,6 +1954,8 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es)
19541954

19551955
rte=rt_fetch(rti,es->rtable);
19561956
refname= (char*)list_nth(es->rtable_names,rti-1);
1957+
if (refname==NULL)
1958+
refname=rte->eref->aliasname;
19571959

19581960
switch (nodeTag(plan))
19591961
{
@@ -2026,8 +2028,7 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es)
20262028
quote_identifier(objectname));
20272029
elseif (objectname!=NULL)
20282030
appendStringInfo(es->str," %s",quote_identifier(objectname));
2029-
if (refname!=NULL&&
2030-
(objectname==NULL||strcmp(refname,objectname)!=0))
2031+
if (objectname==NULL||strcmp(refname,objectname)!=0)
20312032
appendStringInfo(es->str," %s",quote_identifier(refname));
20322033
}
20332034
else
@@ -2036,8 +2037,7 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es)
20362037
ExplainPropertyText(objecttag,objectname,es);
20372038
if (namespace!=NULL)
20382039
ExplainPropertyText("Schema",namespace,es);
2039-
if (refname!=NULL)
2040-
ExplainPropertyText("Alias",refname,es);
2040+
ExplainPropertyText("Alias",refname,es);
20412041
}
20422042
}
20432043

‎src/backend/commands/typecmds.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,7 @@ DefineDomain(CreateDomainStmt *stmt)
888888
*/
889889
defaultValue=
890890
deparse_expression(defaultExpr,
891-
deparse_context_for(domainName,
892-
InvalidOid),
893-
false, false);
891+
NIL, false, false);
894892
defaultValueBin=nodeToString(defaultExpr);
895893
}
896894
}
@@ -2143,9 +2141,7 @@ AlterDomainDefault(List *names, Node *defaultRaw)
21432141
* easier for pg_dump).
21442142
*/
21452143
defaultValue=deparse_expression(defaultExpr,
2146-
deparse_context_for(NameStr(typTup->typname),
2147-
InvalidOid),
2148-
false, false);
2144+
NIL, false, false);
21492145

21502146
/*
21512147
* Form an updated tuple with the new default and write it back.
@@ -2941,14 +2937,9 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
29412937

29422938
/*
29432939
* Deparse it to produce text for consrc.
2944-
*
2945-
* Since VARNOs aren't allowed in domain constraints, relation context
2946-
* isn't required as anything other than a shell.
29472940
*/
29482941
ccsrc=deparse_expression(expr,
2949-
deparse_context_for(domainName,
2950-
InvalidOid),
2951-
false, false);
2942+
NIL, false, false);
29522943

29532944
/*
29542945
* Store the constraint in pg_constraint

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp