Skip to content

Commit f077360

Browse files
michail-nikolaevCommitfest Bot
authored andcommitted
Optimize auxiliary index handling
Skip unnecessary computations for auxiliary indices by: - in the index‐insert path, detect auxiliary indexes and bypass Datum value computation - set indexUnchanged=false for auxiliary indices to avoid redundant checks These optimizations reduce overhead during concurrent index operations.
1 parent 506c7e1 commit f077360

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/backend/catalog/index.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,17 @@ FormIndexDatum(IndexInfo *indexInfo,
29342934
ListCell *indexpr_item;
29352935
int i;
29362936

2937+
/* Auxiliary index does not need any values to be computed */
2938+
if (unlikely(indexInfo->ii_Auxiliary))
2939+
{
2940+
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
2941+
{
2942+
values[i] = PointerGetDatum(NULL);
2943+
isnull[i] = true;
2944+
}
2945+
return;
2946+
}
2947+
29372948
if (indexInfo->ii_Expressions != NIL &&
29382949
indexInfo->ii_ExpressionsState == NIL)
29392950
{

src/backend/executor/execIndexing.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,14 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
440440
* There's definitely going to be an index_insert() call for this
441441
* index. If we're being called as part of an UPDATE statement,
442442
* consider if the 'indexUnchanged' = true hint should be passed.
443+
*
444+
* In case of auxiliary index always pass false as optimisation.
443445
*/
444-
indexUnchanged = update && index_unchanged_by_update(resultRelInfo,
445-
estate,
446-
indexInfo,
447-
indexRelation);
446+
indexUnchanged = update && likely(!indexInfo->ii_Auxiliary) &&
447+
index_unchanged_by_update(resultRelInfo,
448+
estate,
449+
indexInfo,
450+
indexRelation);
448451

449452
satisfiesConstraint =
450453
index_insert(indexRelation, /* index relation */

0 commit comments

Comments
 (0)