Revert "For jsonb_hash_ops, hash less"
authorPeter Geoghegan <[email protected]>
Wed, 19 Mar 2014 09:13:42 +0000 (02:13 -0700)
committerPeter Geoghegan <[email protected]>
Wed, 19 Mar 2014 09:13:42 +0000 (02:13 -0700)
This might be workable with another approach, but leave it for now. This
reverts commit b8199ee3c2506ab81b47a0b440363fc90c0d6956.

src/backend/utils/adt/jsonb_gin.c

index c7cec4ffc9968155226dda6b4dfbd35f950f6703..034f3935e6bebad581c56685ae55f283ee06af17 100644 (file)
@@ -22,7 +22,7 @@
 
 typedef struct PathHashStack
 {
-   uint32  hash;
+   uint32  hash_state;
    struct PathHashStack *next;
 }  PathHashStack;
 
@@ -493,12 +493,12 @@ gin_extract_jsonb_hash(PG_FUNCTION_ARGS)
    it = JsonbIteratorInit(VARDATA(jb));
 
    tail.next = NULL;
-   tail.hash = 0;
-
+   tail.hash_state = 0;
    stack = &tail;
 
    while ((r = JsonbIteratorNext(&it, &v, false)) != WJB_DONE)
    {
+       uint32          temphash;
        PathHashStack  *tmp;
 
        if (i >= total)
@@ -526,23 +526,15 @@ gin_extract_jsonb_hash(PG_FUNCTION_ARGS)
                break;
            case WJB_KEY:
                /* Calc hash of key and separated into preserved stack item */
-               stack->hash = stack->next->hash;
-               hash_scalar_value(&v, &stack->hash);
+               stack->hash_state = stack->next->hash_state;
+               hash_scalar_value(&v, &stack->hash_state);
                break;
            case WJB_VALUE:
            case WJB_ELEM:
-               /*
-                * Since jsonb_hash_ops does not support existence operator,
-                * it's okay to lump together pair values and elements.  For a
-                * key/value pair, the hash value has both values mixed in
-                * together.  For deeply nested key/value pairs (and elements)
-                * the container hash value is mixed in too.
-                */
-               stack->hash = stack->next->hash;
-               hash_scalar_value(&v, &stack->hash);
-               /* Only store entries at the least nested level */
-               if (!it->parent)
-                   entries[i++] = stack->hash;
+               stack->hash_state = stack->next->hash_state;
+               hash_scalar_value(&v, &stack->hash_state);
+               temphash = stack->hash_state;
+               entries[i++] = temphash;
                break;
            case WJB_END_ARRAY:
            case WJB_END_OBJECT: