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

Commit4a94cbd

Browse files
committed
Fix some more cases of missed GENERATED-column updates.
If UPDATE is forced to retry after an EvalPlanQual check, it neglectedto repeat GENERATED-column computations, even though those might wellhave changed since we're dealing with a different tuple than before.Fixing this is mostly a matter of looping back a bit further whenwe retry. In v15 and HEAD that's most easily done by altering the APIof ExecUpdateAct so that it includes computing GENERATED expressions.Also, if an UPDATE in a partitioned table turns into a cross-partitionINSERT operation, we failed to recompute GENERATED columns. That's abug since8bf6ec3 allowed partitions to have different generationexpressions; although it seems to have no ill effects before that.Fixing this is messier because we can now have situations where the samequery needs both the UPDATE-aligned set of GENERATED columns and theINSERT-aligned set, and it's unclear which set will be generated first(else we could hack things by forcing the INSERT-aligned set to begenerated, which is indeed howfe9e658 made it work for MERGE).The best fix seems to be to build and store separate sets of expressionsfor the INSERT and UPDATE cases. That would create ABI issues in theback branches, but so far it seems we can leave this alone in the backbranches.Per bug #17823 from Hisahiro Kauchi. The first part of this affects allbranches back to v12 where GENERATED columns were added.Discussion:https://postgr.es/m/17823-b64909cf7d63de84@postgresql.org
1 parenta0f55fc commit4a94cbd

File tree

6 files changed

+210
-165
lines changed

6 files changed

+210
-165
lines changed

‎src/backend/executor/execUtils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
12861286
{
12871287
ListCell*lc;
12881288

1289-
/*In some code paths wecan reach here before initializing the info */
1289+
/*Compute the info if wedidn't already */
12901290
if (relinfo->ri_GeneratedExprs==NULL)
12911291
ExecInitStoredGenerated(relinfo,estate,CMD_UPDATE);
12921292
foreach(lc,estate->es_resultrelinfo_extra)

‎src/backend/executor/nodeModifyTable.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,15 @@ ExecUpdate(ModifyTableState *mtstate,
12761276
boolpartition_constraint_failed;
12771277
boolupdate_indexes;
12781278

1279+
/*
1280+
* If we generate a new candidate tuple after EvalPlanQual testing, we
1281+
* must loop back here to try again. (We don't need to redo triggers,
1282+
* however. If there are any BEFORE triggers then trigger.c will have
1283+
* done table_tuple_lock to lock the correct tuple, so there's no need
1284+
* to do them again.)
1285+
*/
1286+
lreplace:
1287+
12791288
/*
12801289
* Constraints and GENERATED expressions might reference the tableoid
12811290
* column, so (re-)initialize tts_tableOid before evaluating them.
@@ -1289,17 +1298,6 @@ ExecUpdate(ModifyTableState *mtstate,
12891298
resultRelationDesc->rd_att->constr->has_generated_stored)
12901299
ExecComputeStoredGenerated(estate,slot,CMD_UPDATE);
12911300

1292-
/*
1293-
* Check any RLS UPDATE WITH CHECK policies
1294-
*
1295-
* If we generate a new candidate tuple after EvalPlanQual testing, we
1296-
* must loop back here and recheck any RLS policies and constraints.
1297-
* (We don't need to redo triggers, however. If there are any BEFORE
1298-
* triggers then trigger.c will have done table_tuple_lock to lock the
1299-
* correct tuple, so there's no need to do them again.)
1300-
*/
1301-
lreplace:;
1302-
13031301
/* ensure slot is independent, consider e.g. EPQ */
13041302
ExecMaterializeSlot(slot);
13051303

@@ -1314,6 +1312,7 @@ lreplace:;
13141312
resultRelInfo->ri_PartitionCheck&&
13151313
!ExecPartitionCheck(resultRelInfo,slot,estate, false);
13161314

1315+
/* Check any RLS UPDATE WITH CHECK policies */
13171316
if (!partition_constraint_failed&&
13181317
resultRelInfo->ri_WithCheckOptions!=NIL)
13191318
{
@@ -2549,11 +2548,12 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
25492548

25502549
/*
25512550
* For INSERT and UPDATE, prepare to evaluate any generated columns.
2552-
*We must do this now, even if we never insert or update any rows,
2553-
*because we have to fill resultRelInfo->ri_extraUpdatedCols for
2554-
*possible use by the trigger machinery.
2551+
*(This is probably not necessary any longer, but we'll refrain from
2552+
*changing it in back branches, in case extension code expects it.)
2553+
*During EPQ eval, it might have been done already in an earlier EPQ.
25552554
*/
2556-
if (operation==CMD_INSERT||operation==CMD_UPDATE)
2555+
if ((operation==CMD_INSERT||operation==CMD_UPDATE)&&
2556+
resultRelInfo->ri_GeneratedExprs==NULL)
25572557
ExecInitStoredGenerated(resultRelInfo,estate,operation);
25582558

25592559
resultRelInfo++;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp