Fix default signature length for gist_ltree_ops
authorAlexander Korotkov <akorotkov@postgresql.org>
Wed, 16 Mar 2022 08:41:18 +0000 (11:41 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Wed, 16 Mar 2022 08:41:18 +0000 (11:41 +0300)
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

contrib/ltree/ltree.h
contrib/ltree/ltree_gist.c

index 5b4be5e680a52487551ffa4d29bdaec9e6b442b4..10341d60212f6fad73438df07caaacb676e5e01a 100644 (file)
@@ -229,11 +229,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;
 
index 7c39ed4298e8204df4dd0b82794134d125f8d4da..36874e9c7263c8ba18eee40d661155b30358f3dd 100644 (file)
@@ -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();