v31-0006-Optimize-auxiliary-index-handling.patch
application/octet-stream
Filename: v31-0006-Optimize-auxiliary-index-handling.patch
Type: application/octet-stream
Part: 5
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v31-0006
Subject: Optimize auxiliary index handling
| File | + | − |
|---|---|---|
| src/backend/catalog/index.c | 11 | 0 |
| src/backend/executor/execIndexing.c | 4 | 1 |
From bb56f91df5a44c7865e6f599738cdec476497021 Mon Sep 17 00:00:00 2001
From: Mikhail Nikalayeu <mihailnikalayeu@gmail.com>
Date: Mon, 30 Dec 2024 16:37:12 +0100
Subject: [PATCH v31 6/7] 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.
---
src/backend/catalog/index.c | 11 +++++++++++
src/backend/executor/execIndexing.c | 5 ++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 4b6a0f76c81..2d7d25f1986 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2917,6 +2917,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 9d071e495c6..ce76a213556 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -438,8 +438,11 @@ 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.
+ *
+ * For auxiliary indexes, always pass false to skip value comparison checks,
+ * since auxiliary indexes only store TIDs and don't track value changes.
*/
- indexUnchanged = ((flags & EIIT_IS_UPDATE) &&
+ indexUnchanged = ((flags & EIIT_IS_UPDATE) && likely(!indexInfo->ii_Auxiliary) &&
index_unchanged_by_update(resultRelInfo,
estate,
indexInfo,
--
2.43.0