diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2022-03-16 11:41:18 +0300 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2022-03-16 11:41:30 +0300 |
commit | 7d30f59da714ab25f82f4bc24f30cba1022d8cb9 (patch) | |
tree | bad426e2b8c07fba6201f953f6e88ba15e30c31a | |
parent | 26e00793980996fada8d61181d45070ce9fee600 (diff) | |
download | postgresql-7d30f59da714ab25f82f4bc24f30cba1022d8cb9.tar.gz postgresql-7d30f59da714ab25f82f4bc24f30cba1022d8cb9.zip |
Fix default signature length for gist_ltree_ops
911e702077 implemented operator class parameters including the signature length
in ltree. Previously, the signature length for gist_ltree_ops was 8. Because
of bug 911e702077 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
-rw-r--r-- | contrib/ltree/ltree.h | 8 | ||||
-rw-r--r-- | contrib/ltree/ltree_gist.c | 12 |
2 files changed, 11 insertions, 9 deletions
diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h index dc68a0c212f..83fc705ef86 100644 --- a/contrib/ltree/ltree.h +++ b/contrib/ltree/ltree.h @@ -216,11 +216,13 @@ int ltree_strncasecmp(const char *a, const char *b, size_t s); /* GiST support for ltree */ -#define SIGLEN_MAX GISTMaxIndexKeySize -#define SIGLEN_DEFAULT (2 * sizeof(int32)) #define BITBYTE 8 -#define SIGLEN (sizeof(int32) * SIGLENINT) #define SIGLENBIT(siglen) ((siglen) * BITBYTE) +#define LTREE_SIGLEN_DEFAULT (2 * sizeof(int32)) +#define LTREE_SIGLEN_MAX GISTMaxIndexKeySize +#define LTREE_GET_SIGLEN() (PG_HAS_OPCLASS_OPTIONS() ? \ + ((LtreeGistOptions *) PG_GET_OPCLASS_OPTIONS())->siglen : \ + LTREE_SIGLEN_DEFAULT) typedef unsigned char *BITVECP; diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c index 6cf181bc530..d384e1f5762 100644 --- a/contrib/ltree/ltree_gist.c +++ b/contrib/ltree/ltree_gist.c @@ -130,7 +130,7 @@ ltree_same(PG_FUNCTION_ARGS) ltree_gist *a = (ltree_gist *) PG_GETARG_POINTER(0); ltree_gist *b = (ltree_gist *) PG_GETARG_POINTER(1); bool *result = (bool *) PG_GETARG_POINTER(2); - int siglen = LTREE_GET_ASIGLEN(); + int siglen = LTREE_GET_SIGLEN(); *result = false; if (LTG_ISONENODE(a) != LTG_ISONENODE(b)) @@ -190,7 +190,7 @@ ltree_union(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); int *size = (int *) PG_GETARG_POINTER(1); - int siglen = LTREE_GET_ASIGLEN(); + int siglen = LTREE_GET_SIGLEN(); BITVECP base = palloc0(siglen); int32 i, j; @@ -260,7 +260,7 @@ ltree_penalty(PG_FUNCTION_ARGS) ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); float *penalty = (float *) PG_GETARG_POINTER(2); - int siglen = LTREE_GET_ASIGLEN(); + int siglen = LTREE_GET_SIGLEN(); int32 cmpr, cmpl; @@ -292,7 +292,7 @@ ltree_picksplit(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); - int siglen = LTREE_GET_ASIGLEN(); + int siglen = LTREE_GET_SIGLEN(); OffsetNumber j; int32 i; RIX *array; @@ -618,7 +618,7 @@ ltree_consistent(PG_FUNCTION_ARGS) /* Oid subtype = PG_GETARG_OID(3); */ bool *recheck = (bool *) PG_GETARG_POINTER(4); - int siglen = LTREE_GET_ASIGLEN(); + int siglen = LTREE_GET_SIGLEN(); ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key); void *query = NULL; bool res = false; @@ -724,7 +724,7 @@ ltree_gist_options(PG_FUNCTION_ARGS) init_local_reloptions(relopts, sizeof(LtreeGistOptions)); add_local_int_reloption(relopts, "siglen", "signature length in bytes", - SIGLEN_DEFAULT, 1, SIGLEN_MAX, + LTREE_SIGLEN_DEFAULT, 1, LTREE_SIGLEN_MAX, offsetof(LtreeGistOptions, siglen)); PG_RETURN_VOID(); |