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

Commit16d69ec

Browse files
committed
Remove buggy and dead code from CreateTriggerFiringOn
Here we remove some dead code from CreateTriggerFiringOn() which wasattempting to find the relevant child partition index corresponding to thegiven indexOid. As it turned out, thanks to -Wshadow=compatible-local,this code was buggy as the code which was finding the child indexesassigned those to a shadowed variable that directly went out of scope.The code which thought it was looking at the List of child indexes wasalways referencing an empty List.On further investigation, this code is dead. We never callCreateTriggerFiringOn() passing a valid indexOid in a way that thefunction would actually ever execute the code in question. So, for lackof a way to test if a fix actually works, let's just remove the dead codeinstead.As a reminder, if there is ever a need to resurrect this code, an Assert()has been added to remind future feature developers that they might need towrite some code to find the corresponding child index.Reported-by: Justin PryzbyReviewed-by: Justin PryzbyDiscussion:https://postgr.es/m/20220819211824.GX26426@telsasoft.com
1 parent8c06a28 commit16d69ec

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

‎src/backend/commands/trigger.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,6 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
11471147
if (partition_recurse)
11481148
{
11491149
PartitionDescpartdesc=RelationGetPartitionDesc(rel, true);
1150-
List*idxs=NIL;
1151-
List*childTbls=NIL;
11521150
inti;
11531151
MemoryContextoldcxt,
11541152
perChildCxt;
@@ -1158,53 +1156,23 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
11581156
ALLOCSET_SMALL_SIZES);
11591157

11601158
/*
1161-
*When a trigger is being created associated withan index, we'll
1162-
*need to associate the trigger in each child partition with the
1163-
* correspondingindex on it.
1159+
*We don't currently expect to be called witha valid indexOid. If
1160+
*that ever changes then we'll need to quite code here to find the
1161+
* correspondingchild index.
11641162
*/
1165-
if (OidIsValid(indexOid))
1166-
{
1167-
ListCell*l;
1168-
List*idxs=NIL;
1169-
1170-
idxs=find_inheritance_children(indexOid,ShareRowExclusiveLock);
1171-
foreach(l,idxs)
1172-
childTbls=lappend_oid(childTbls,
1173-
IndexGetRelation(lfirst_oid(l),
1174-
false));
1175-
}
1163+
Assert(!OidIsValid(indexOid));
11761164

11771165
oldcxt=MemoryContextSwitchTo(perChildCxt);
11781166

11791167
/* Iterate to create the trigger on each existing partition */
11801168
for (i=0;i<partdesc->nparts;i++)
11811169
{
1182-
OidindexOnChild=InvalidOid;
1183-
ListCell*l;
1184-
ListCell*l2;
11851170
CreateTrigStmt*childStmt;
11861171
RelationchildTbl;
11871172
Node*qual;
11881173

11891174
childTbl=table_open(partdesc->oids[i],ShareRowExclusiveLock);
11901175

1191-
/* Find which of the child indexes is the one on this partition */
1192-
if (OidIsValid(indexOid))
1193-
{
1194-
forboth(l,idxs,l2,childTbls)
1195-
{
1196-
if (lfirst_oid(l2)==partdesc->oids[i])
1197-
{
1198-
indexOnChild=lfirst_oid(l);
1199-
break;
1200-
}
1201-
}
1202-
if (!OidIsValid(indexOnChild))
1203-
elog(ERROR,"failed to find index matching index \"%s\" in partition \"%s\"",
1204-
get_rel_name(indexOid),
1205-
get_rel_name(partdesc->oids[i]));
1206-
}
1207-
12081176
/*
12091177
* Initialize our fabricated parse node by copying the original
12101178
* one, then resetting fields that we pass separately.
@@ -1224,7 +1192,7 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
12241192

12251193
CreateTriggerFiringOn(childStmt,queryString,
12261194
partdesc->oids[i],refRelOid,
1227-
InvalidOid,indexOnChild,
1195+
InvalidOid,InvalidOid,
12281196
funcoid,trigoid,qual,
12291197
isInternal, true,trigger_fires_when);
12301198

@@ -1235,8 +1203,6 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString,
12351203

12361204
MemoryContextSwitchTo(oldcxt);
12371205
MemoryContextDelete(perChildCxt);
1238-
list_free(idxs);
1239-
list_free(childTbls);
12401206
}
12411207

12421208
/* Keep lock on target rel until end of xact */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp