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

Commit3850723

Browse files
committed
Don't mess up pstate->p_next_resno in transformOnConflictClause().
transformOnConflictClause incremented p_next_resno while generating thephony targetlist for the EXCLUDED pseudo-rel. Then that field gotincremented some more during transformTargetList, possibly leading tofree_parsestate concluding that we'd overrun the allowed length of a tlist,as reported by Justin Pryzby.We could fix this by resetting p_next_resno to 1 after using it for theEXCLUDED pseudo-rel tlist, but it seems easier and less coupled to otherplaces if we just don't use that field at all in this loop. (Note thatthis doesn't change anything about the resnos that end up appearing inthe main target list, because those are all replaced with target-columnnumbers by updateTargetListEntry.)In passing, fix incorrect type OID assigned to the whole-row Var for"EXCLUDED.*" (somehow this escaped having any bad consequences so far,but it's certainly wrong); remove useless assignment to var->location;pstrdup the column names in case of a relcache flush; and improvenearby comments.Back-patch to 9.5 where ON CONFLICT was introduced.Report:https://postgr.es/m/20161204163237.GA8030@telsasoft.com
1 parentd61aa6a commit3850723

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

‎src/backend/parser/analyze.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -996,11 +996,10 @@ transformOnConflictClause(ParseState *pstate,
996996
exclRelIndex=list_length(pstate->p_rtable);
997997

998998
/*
999-
* Build a targetlistfor theEXCLUDED pseudo relation. Have to be
1000-
* careful to use resnos that correspond to attnos of the underlying
1001-
* relation.
999+
* Build a targetlistrepresenting thecolumns of the EXCLUDED pseudo
1000+
*relation. Have to becareful to use resnos that correspond to
1001+
*attnos of the underlyingrelation.
10021002
*/
1003-
Assert(pstate->p_next_resno==1);
10041003
for (attno=0;attno<targetrel->rd_rel->relnatts;attno++)
10051004
{
10061005
Form_pg_attributeattr=targetrel->rd_att->attrs[attno];
@@ -1021,14 +1020,11 @@ transformOnConflictClause(ParseState *pstate,
10211020
attr->atttypid,attr->atttypmod,
10221021
attr->attcollation,
10231022
0);
1024-
var->location=-1;
1025-
1026-
name=NameStr(attr->attname);
1023+
name=pstrdup(NameStr(attr->attname));
10271024
}
10281025

1029-
Assert(pstate->p_next_resno==attno+1);
10301026
te=makeTargetEntry((Expr*)var,
1031-
pstate->p_next_resno++,
1027+
attno+1,
10321028
name,
10331029
false);
10341030

@@ -1037,15 +1033,16 @@ transformOnConflictClause(ParseState *pstate,
10371033
}
10381034

10391035
/*
1040-
* Additionally add a whole row tlist entry for EXCLUDED. That's
1041-
* really only needed for ruleutils' benefit, which expects to find
1042-
* corresponding entries in child tlists. Alternatively we could do
1043-
* this only when required, but that doesn't seem worth the trouble.
1036+
* Add a whole-row-Var entry to support references to "EXCLUDED.*".
1037+
* Like the other entries in exclRelTlist, its resno must match the
1038+
* Var's varattno, else the wrong things happen while resolving
1039+
* references in setrefs.c. This is against normal conventions for
1040+
* targetlists, but it's okay since we don't use this as a real tlist.
10441041
*/
10451042
var=makeVar(exclRelIndex,InvalidAttrNumber,
1046-
RelationGetRelid(targetrel),
1043+
targetrel->rd_rel->reltype,
10471044
-1,InvalidOid,0);
1048-
te=makeTargetEntry((Expr*)var,0,NULL, true);
1045+
te=makeTargetEntry((Expr*)var,InvalidAttrNumber,NULL, true);
10491046
exclRelTlist=lappend(exclRelTlist,te);
10501047

10511048
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp