v1-0004-Avoid-dedup-and-sort-in-ginExtractEntries.patch
text/x-patch
Filename: v1-0004-Avoid-dedup-and-sort-in-ginExtractEntries.patch
Type: text/x-patch
Part: 4
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 v1-0004
Subject: Avoid dedup and sort in ginExtractEntries
| File | + | − |
|---|---|---|
| src/backend/access/gin/ginutil.c | 9 | 12 |
From e91198730d10d301857b1ef38670f506fc0749ca Mon Sep 17 00:00:00 2001
From: David Geier <geidav.pg@gmail.com>
Date: Mon, 10 Nov 2025 14:40:37 +0100
Subject: [PATCH v1 4/8] Avoid dedup and sort in ginExtractEntries
---
src/backend/access/gin/ginutil.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c
index f4139effd6e..9187264dbdc 100644
--- a/src/backend/access/gin/ginutil.c
+++ b/src/backend/access/gin/ginutil.c
@@ -498,13 +498,6 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
return entries;
}
- /*
- * If the extractValueFn didn't create a nullFlags array, create one,
- * assuming that everything's non-null.
- */
- if (nullFlags == NULL)
- nullFlags = (bool *) palloc0(*nentries * sizeof(bool));
-
/*
* If there's more than one key, sort and unique-ify.
*
@@ -512,8 +505,8 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
* pretty bad too. For small numbers of keys it'd likely be better to use
* a simple insertion sort.
*/
- if (*nentries > 1)
- {
+ if (*nentries > 1 && nullFlags != NULL)
+ {
keyEntryData *keydata;
cmpEntriesArg arg;
@@ -564,9 +557,13 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
/*
* Create GinNullCategory representation from nullFlags.
*/
- *categories = (GinNullCategory *) palloc0(*nentries * sizeof(GinNullCategory));
- for (i = 0; i < *nentries; i++)
- (*categories)[i] = (nullFlags[i] ? GIN_CAT_NULL_KEY : GIN_CAT_NORM_KEY);
+ StaticAssertStmt(GIN_CAT_NORM_KEY == 0, "Assuming GIN_CAT_NORM_KEY is 0");
+ *categories = palloc0_array(GinNullCategory, *nentries);
+
+ if (nullFlags != NULL)
+ for (i = 0; i < *nentries; i++)
+ if (nullFlags[i])
+ (*categories)[i] = GIN_CAT_NULL_KEY;
return entries;
}
--
2.51.0