{
case WJB_KEY:
/*
- * An element of an array is serialized as a key for our
- * purposes. This is necessary because array elements are also
- * keys.
+ * Serialize keys and elements as one. This is necessary
+ * because array elements must be indexed as keys for the
+ * benefit of JsonbContainsStrategyNumber.
*/
case WJB_ELEM:
entries[i++] = PointerGetDatum(makeitemFromValue(&v, KEYELEMFLAG));
DatumGetPointer(DirectFunctionCall2(gin_extract_jsonb,
PG_GETARG_DATUM(0),
PointerGetDatum(nentries)));
- /* ... except that "contains {}" requires a full index scan */
+ /* ...except for "contains {}", which requires a full index scan */
if (entries == NULL)
*searchMode = GIN_SEARCH_MODE_ALL;
}
{
/*
* Index doesn't have information about correspondence of keys and
- * values, so we must recheck. However, if all of the keys are not
- * present, we can fail immediately.
+ * values, so invariably we recheck. However, if all of the keys are
+ * not present, that's sufficient reason to return false and finish
+ * immediately.
*/
*recheck = true;
for (i = 0; i < nkeys; i++)
if (strategy == JsonbContainsStrategyNumber)
{
/*
- * Index doesn't have information about correspondence of keys and
- * values, so we must recheck. However, if not all of the keys are
- * present, we can fail immediately.
+ * jsonb_hash_ops index doesn't have information about correspondence
+ * of keys and values, so invariably we recheck. However, if all of
+ * the keys are not present, that's sufficient reason to return false
+ * and finish immediately.
*/
*recheck = true;
for (i = 0; i < nkeys; i++)
/*
* Calculate hashes of all key_1.key_2. ... .key_n.value paths as entries.
- * Order of array elements doesn't matter so array keys are empty in path.
+ * Order of array elements doesn't matter, so array keys are empty in path.
* For faster calculation of hashes, use a stack of precalculated hashes of
* prefixes.
*/
/* bigint defines */
#define BITBYTE 8
-#define SIGLENINT 4 /* >122 => key will toast, so very slow! */
+#define SIGLENINT 4 /* > 122 => key be will toasted */
#define SIGLEN (sizeof(int)*SIGLENINT)
#define SIGLENBIT (SIGLEN*BITBYTE)
for(i=0;i<SIGLENBIT;i++)
/* Beware of multiple evaluation of arguments to these macros! */
-#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
-#define GETBITBYTE(x,i) ( (*((char*)(x)) >> (i)) & 0x01 )
-#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
-#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
-#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
-#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
-#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
-
-#define ALLISTRUE 0x04
-#define ISALLTRUE(x) ( ((GISTTYPE*)x)->flag & ALLISTRUE )
-#define GTHDRSIZE (VARHDRSZ + sizeof(int32))
-#define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
-#define GETSIGN(x) ( (BITVECP)( (char*)x+GTHDRSIZE ) )
-
+#define GETBYTE(x,i) (*((BITVECP)(x) + (int)( (i) / BITBYTE )))
+#define GETBITBYTE(x,i) ((*((char*)(x)) >> (i)) & 0x01)
+#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ))
+#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ))
+#define GETBIT(x,i) ((GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01)
+#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
+#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
+
+#define ALLISTRUE 0x04
+#define ISALLTRUE(x) (((GISTTYPE*)x)->flag & ALLISTRUE)
+#define GTHDRSIZE (VARHDRSZ + sizeof(int32))
+#define CALCGTSIZE(flag) (GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN))
+#define GETSIGN(x) ((BITVECP)( (char*)x+GTHDRSIZE))
#define SUMBIT(val) ( \
GETBITBYTE((val),0) + \
GETBITBYTE((val),1) + \
GETBITBYTE((val),7) \
)
-#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer((vec)->vector[(pos)].key))
-#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
+#define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer((vec)->vector[(pos)].key))
+#define WISH_F(a,b,c) ((double) ( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c)))
typedef struct
{
{
case WJB_KEY:
/*
- * An element of an array is serialized as a key for our purposes.
- * This is necessary because array elements are also keys.
+ * Serialize keys and elements as one. This is necessary because
+ * array elements must be indexed as keys for the benefit of
+ * JsonbContainsStrategyNumber.
*/
case WJB_ELEM:
flag = KEYELEMFLAG;