v23-only-part-3-0005-Optimize-auxiliary-index-handling.patch_
application/octet-stream
Filename: v23-only-part-3-0005-Optimize-auxiliary-index-handling.patch_
Type: application/octet-stream
Part: 11
From f2de252cc52cff5e24bc9db6bb4e20bec2c47fba Mon Sep 17 00:00:00 2001
From: Mikhail Nikalayeu <mihailnikalayeu@gmail.com>
Date: Mon, 30 Dec 2024 16:37:12 +0100
Subject: [PATCH v23-only-part-3 5/6] Optimize auxiliary index handling
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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.
---
src/backend/catalog/index.c | 11 +++++++++++
src/backend/executor/execIndexing.c | 11 +++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index db7802a9a2c..d13f77b0de7 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2916,6 +2916,17 @@ FormIndexDatum(IndexInfo *indexInfo,
ListCell *indexpr_item;
int i;
+ /* Auxiliary index does not need any values to be computed */
+ if (unlikely(indexInfo->ii_Auxiliary))
+ {
+ for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
+ {
+ values[i] = PointerGetDatum(NULL);
+ isnull[i] = true;
+ }
+ return;
+ }
+
if (indexInfo->ii_Expressions != NIL &&
indexInfo->ii_ExpressionsState == NIL)
{
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index 0edf54e852d..09b9b811def 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -440,11 +440,14 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
* There's definitely going to be an index_insert() call for this
* index. If we're being called as part of an UPDATE statement,
* consider if the 'indexUnchanged' = true hint should be passed.
+ *
+ * In case of auxiliary index always pass false as optimisation.
*/
- indexUnchanged = update && index_unchanged_by_update(resultRelInfo,
- estate,
- indexInfo,
- indexRelation);
+ indexUnchanged = update && likely(!indexInfo->ii_Auxiliary) &&
+ index_unchanged_by_update(resultRelInfo,
+ estate,
+ indexInfo,
+ indexRelation);
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
--
2.43.0