entries = (Datum *) repalloc(entries, sizeof(Datum) * total);
}
+ /*
+ * Serialize keys and elements as one. Array elements must be indexed
+ * as keys for the benefit of JsonbContainsStrategyNumber.
+ *
+ * Even though we bunch together keys and elements here, the resultant
+ * serialized text datum sufficiently reflects the original Jsonb
+ * structure, because Keys must have values, and elements cannot have
+ * keys.
+ */
switch (r)
{
case WJB_KEY:
- /*
- * 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(make_scalar_text_key(&v, KEYELEMFLAG));
break;
*nentries = 1;
entries = (Datum *) palloc(sizeof(Datum));
item = make_text_key(VARDATA_ANY(query), VARSIZE_ANY_EXHDR(query),
- KEYELEMFLAG);
+ KEYELEMFLAG);
entries[0] = PointerGetDatum(item);
}
else if (strategy == JsonbExistsAnyStrategyNumber ||
if (key_nulls[i])
continue;
item = make_text_key(VARDATA(key_datums[i]),
- VARSIZE(key_datums[i]) - VARHDRSZ,
- KEYELEMFLAG);
+ VARSIZE(key_datums[i]) - VARHDRSZ,
+ KEYELEMFLAG);
entries[j++] = PointerGetDatum(item);
}
* 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.
+ * strings takes precedence.
*/
cstr = numeric_normalize(v->numeric);
item = make_text_key(cstr, strlen(cstr), flag);
*
* Containment means that all of the values in the rhs "mContained" iterator's
* datum exist within the lhs "val" datum at the same nesting level (and, by
- * corollary, all sub-nesting levels).
+ * corollary, all sub-nesting levels on the rhs).
*/
bool
deepContains(JsonbIterator ** val, JsonbIterator ** mContained)
{
uint32 len;
char *val; /* Not necessarily null-terminated */
- } string;
+ } string; /* String primitive type */
struct
{
JsonbValue *elems;
bool scalar; /* Scalar actually shares representation with
* array */
- } array;
+ } array; /* Array container type */
struct
{
int nPairs;
JsonbPair *pairs;
- } object; /* Associative data structure */
+ } object; /* Associative container type */
struct
{
/* Jsonb varlena buffer (may or may not be root) */
char *buffer;
- /* Current item in buffer */
- int i;
-
/* Current value */
uint32 containerType; /* Never of value JB_FSCALAR, since
* scalars will appear in pseudo-arrays */
bool isScalar; /* Pseudo-array scalar value? */
JEntry *meta;
+ /* Current item in buffer ("nElems-wise" count) */
+ int i;
+
+
/*
* Data proper. Note that this points just past end of meta array. We use
* "meta" metadata (Jentrys) with JBE_OFF() macro to find appropriate
uint32 flags, uint32 i);
extern JsonbValue *pushJsonbValue(ToJsonbState ** state, int r, JsonbValue *v);
extern JsonbIterator *JsonbIteratorInit(JsonbSuperHeader buffer);
-extern int JsonbIteratorNext(JsonbIterator **it, JsonbValue *v, bool skipNested);
+extern int JsonbIteratorNext(JsonbIterator **it, JsonbValue *v,
+ bool skipNested);
extern Jsonb *JsonbValueToJsonb(JsonbValue *v);
extern bool deepContains(JsonbIterator ** val, JsonbIterator ** mContained);
extern JsonbValue *arrayToJsonbSortedArray(ArrayType *a);