Skip to content

Commit 7e74aaf

Browse files
committed
Fix default signature length for gist_ltree_ops
911e702 implemented operator class parameters including the signature length in ltree. Previously, the signature length for gist_ltree_ops was 8. Because of bug 911e702 the default signature length for gist_ltree_ops became 28 for ltree 1.1 (where options method is NOT provided) and 8 for ltree 1.2 (where options method is provided). This commit changes the default signature length for ltree 1.1 to 8. Existing gist_ltree_ops indexes might be corrupted in various scenarios. Thus, we have to recommend reindexing all the gist_ltree_ops indexes after the upgrade. Reported-by: Victor Yegorov Reviewed-by: Tomas Vondra, Tom Lane, Andres Freund, Nikita Glukhov Reviewed-by: Andrew Dunstan Author: Tomas Vondra, Alexander Korotkov Discussion: https://postgr.es/m/17406-71e02820ae79bb40%40postgresql.org Discussion: https://postgr.es/m/d80e0a55-6c3e-5b26-53e3-3c4f973f737c%40enterprisedb.com
1 parent 46d9bfb commit 7e74aaf

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

contrib/ltree/ltree.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,13 @@ int ltree_strncasecmp(const char *a, const char *b, size_t s);
229229

230230
/* GiST support for ltree */
231231

232-
#define SIGLEN_MAX GISTMaxIndexKeySize
233-
#define SIGLEN_DEFAULT (2 * sizeof(int32))
234232
#define BITBYTE 8
235-
#define SIGLEN (sizeof(int32) * SIGLENINT)
236233
#define SIGLENBIT(siglen) ((siglen) * BITBYTE)
234+
#define LTREE_SIGLEN_DEFAULT (2 * sizeof(int32))
235+
#define LTREE_SIGLEN_MAX GISTMaxIndexKeySize
236+
#define LTREE_GET_SIGLEN() (PG_HAS_OPCLASS_OPTIONS() ? \
237+
((LtreeGistOptions *) PG_GET_OPCLASS_OPTIONS())->siglen : \
238+
LTREE_SIGLEN_DEFAULT)
237239

238240
typedef unsigned char *BITVECP;
239241

contrib/ltree/ltree_gist.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ltree_same(PG_FUNCTION_ARGS)
130130
ltree_gist *a = (ltree_gist *) PG_GETARG_POINTER(0);
131131
ltree_gist *b = (ltree_gist *) PG_GETARG_POINTER(1);
132132
bool *result = (bool *) PG_GETARG_POINTER(2);
133-
int siglen = LTREE_GET_ASIGLEN();
133+
int siglen = LTREE_GET_SIGLEN();
134134

135135
*result = false;
136136
if (LTG_ISONENODE(a) != LTG_ISONENODE(b))
@@ -190,7 +190,7 @@ ltree_union(PG_FUNCTION_ARGS)
190190
{
191191
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
192192
int *size = (int *) PG_GETARG_POINTER(1);
193-
int siglen = LTREE_GET_ASIGLEN();
193+
int siglen = LTREE_GET_SIGLEN();
194194
BITVECP base = palloc0(siglen);
195195
int32 i,
196196
j;
@@ -260,7 +260,7 @@ ltree_penalty(PG_FUNCTION_ARGS)
260260
ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
261261
ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
262262
float *penalty = (float *) PG_GETARG_POINTER(2);
263-
int siglen = LTREE_GET_ASIGLEN();
263+
int siglen = LTREE_GET_SIGLEN();
264264
int32 cmpr,
265265
cmpl;
266266

@@ -292,7 +292,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
292292
{
293293
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
294294
GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
295-
int siglen = LTREE_GET_ASIGLEN();
295+
int siglen = LTREE_GET_SIGLEN();
296296
OffsetNumber j;
297297
int32 i;
298298
RIX *array;
@@ -618,7 +618,7 @@ ltree_consistent(PG_FUNCTION_ARGS)
618618

619619
/* Oid subtype = PG_GETARG_OID(3); */
620620
bool *recheck = (bool *) PG_GETARG_POINTER(4);
621-
int siglen = LTREE_GET_ASIGLEN();
621+
int siglen = LTREE_GET_SIGLEN();
622622
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
623623
void *query = NULL;
624624
bool res = false;
@@ -724,7 +724,7 @@ ltree_gist_options(PG_FUNCTION_ARGS)
724724
init_local_reloptions(relopts, sizeof(LtreeGistOptions));
725725
add_local_int_reloption(relopts, "siglen",
726726
"signature length in bytes",
727-
SIGLEN_DEFAULT, 1, SIGLEN_MAX,
727+
LTREE_SIGLEN_DEFAULT, 1, LTREE_SIGLEN_MAX,
728728
offsetof(LtreeGistOptions, siglen));
729729

730730
PG_RETURN_VOID();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy