Skip to content

Commit 37370f8

Browse files
committed
Pass indexUnchanged to index_update method
1 parent a75d369 commit 37370f8

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/backend/access/index/indexam.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ index_update(Relation indexRelation,
269269
Datum oldTupleid,
270270
Relation heapRelation,
271271
IndexUniqueCheck checkUnique,
272+
bool indexUnchanged,
272273
IndexInfo *indexInfo)
273274
{
274275
RELATION_CHECKS;
@@ -285,6 +286,7 @@ index_update(Relation indexRelation,
285286
valuesOld, isnullOld, oldTupleid,
286287
heapRelation,
287288
checkUnique,
289+
indexUnchanged,
288290
indexInfo);
289291
}
290292

src/backend/executor/execIndexing.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ ExecUpdateIndexTuples(ResultRelInfo *resultRelInfo,
547547
IndexInfo *indexInfo;
548548
bool applyNoDupErr;
549549
IndexUniqueCheck checkUnique;
550+
bool indexUnchanged;
550551
bool satisfiesConstraint;
551552
bool new_valid = true;
552553

@@ -638,6 +639,16 @@ ExecUpdateIndexTuples(ResultRelInfo *resultRelInfo,
638639
else
639640
checkUnique = UNIQUE_CHECK_PARTIAL;
640641

642+
/*
643+
* There's definitely going to be an index_insert() call for this
644+
* index. If we're being called as part of an UPDATE statement,
645+
* consider if the 'indexUnchanged' = true hint should be passed.
646+
*/
647+
indexUnchanged = index_unchanged_by_update(resultRelInfo,
648+
estate,
649+
indexInfo,
650+
indexRelation);
651+
641652
if (indexRelation->rd_indam->ammvccaware)
642653
{
643654
Datum valuesOld[INDEX_MAX_KEYS];
@@ -699,22 +710,12 @@ ExecUpdateIndexTuples(ResultRelInfo *resultRelInfo,
699710
oldTupleidDatum,
700711
heapRelation, /* heap relation */
701712
checkUnique, /* type of uniqueness check to do */
713+
indexUnchanged, /* UPDATE without logical change? */
702714
indexInfo); /* index AM may need this */
703715

704716
}
705717
else
706718
{
707-
bool indexUnchanged;
708-
/*
709-
* There's definitely going to be an index_insert() call for this
710-
* index. If we're being called as part of an UPDATE statement,
711-
* consider if the 'indexUnchanged' = true hint should be passed.
712-
*/
713-
indexUnchanged = index_unchanged_by_update(resultRelInfo,
714-
estate,
715-
indexInfo,
716-
indexRelation);
717-
718719
satisfiesConstraint =
719720
index_insert(indexRelation, /* index relation */
720721
values, /* array of index Datums */
@@ -1207,9 +1208,10 @@ check_exclusion_or_unique_constraint(Relation heap, Relation index,
12071208
continue;
12081209
}
12091210
} else {
1210-
Assert(tupleidDatum > 0);
1211-
Pointer rowid = DatumGetPointer(tupleidDatum);
1211+
Pointer rowid;
12121212

1213+
Assert(tupleidDatum > 0);
1214+
rowid = DatumGetPointer(tupleidDatum);
12131215
if (PointerIsValid(rowid))
12141216
{
12151217
bool isnull;

src/include/access/amapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ typedef bool (*amupdate_function) (Relation indexRelation,
142142
Datum oldTupleid,
143143
Relation heapRelation,
144144
IndexUniqueCheck checkUnique,
145+
bool indexUnchanged,
145146
struct IndexInfo *indexInfo);
146147
/* delete this tuple */
147148
typedef bool (*amdelete_function) (Relation indexRelation,

src/include/access/genam.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ extern bool index_update(Relation indexRelation,
160160
Datum oldTupleid,
161161
Relation heapRelation,
162162
IndexUniqueCheck checkUnique,
163+
bool indexUnchanged,
163164
struct IndexInfo *indexInfo);
164165
extern bool index_delete(Relation indexRelation, Datum *values, bool *isnull,
165166
Datum tupleid, Relation heapRelation,

0 commit comments

Comments
 (0)