Remarks on GIN numeric textual storage
authorPeter Geoghegan <[email protected]>
Fri, 14 Mar 2014 06:34:31 +0000 (23:34 -0700)
committerPeter Geoghegan <[email protected]>
Fri, 14 Mar 2014 06:34:31 +0000 (23:34 -0700)
src/backend/utils/adt/jsonb_gin.c
src/backend/utils/adt/numeric.c

index bac94739a151b80e070bf3b67f8b648950663f17..8fddd581c9f1e6d69d39dbaa85e1f967d10adfe1 100644 (file)
@@ -425,6 +425,11 @@ make_scalar_text_key(const JsonbValue * v, char flag)
            /*
             * A normalized textual representation, free of trailing zeroes is
             * is required.
+            *
+            * It isn't ideal that numerics are stored in a relatively bulky
+            * textual format.  However, it's a notationally convenient way of
+            * storing a "union" type in the GIN B-Tree, and indexing Jsonb
+            * strings take precedence.
             */
            cstr = numeric_normalize(v->numeric);
            item = make_text_key(cstr, strlen(cstr), flag);
index 92e3528c8fb02922d41588af715c556e6f612762..a4d5b0369f7ba7eedb582ff79e679843fee02a3c 100644 (file)
@@ -652,14 +652,14 @@ numeric_normalize(Numeric num)
 
    for (;;)
    {
-       if (str[last] != '0')
+       if (last == 0 || str[last] != '0')
            break;
 
        str[last] = '\0';
        last--;
    }
 
-   if (str[last] == '.')
+   if (last != 0 && str[last] == '.')
        str[last] = '\0';
 
    return str;