From: Peter Geoghegan Date: Fri, 7 Mar 2014 09:31:47 +0000 (-0800) Subject: Fix jsonb_exists_all X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=cf54296036b082b4ea99a0bd943f479bb0051a60;p=users%2Fandresfreund%2Fpostgres.git Fix jsonb_exists_all --- diff --git a/src/backend/utils/adt/jsonb_op.c b/src/backend/utils/adt/jsonb_op.c index 50fc834d14..8bb589ee16 100644 --- a/src/backend/utils/adt/jsonb_op.c +++ b/src/backend/utils/adt/jsonb_op.c @@ -151,12 +151,13 @@ jsonb_exists_any(PG_FUNCTION_ARGS) Datum jsonb_exists_all(PG_FUNCTION_ARGS) { - Jsonb *js = PG_GETARG_JSONB(0); - ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1); - JsonbValue *v = arrayToJsonbSortedArray(keys); + Jsonb *js = PG_GETARG_JSONB(0); + ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1); + JsonbValue *v = arrayToJsonbSortedArray(keys); + uint32 *plowbound = NULL; + uint32 lowbound = 0; + bool res = true; int i; - uint32 *plowbound = NULL, lowbound = 0; - bool res = false; if (JB_ISEMPTY(js) || v == NULL || v->array.nelems == 0) { @@ -170,7 +171,7 @@ jsonb_exists_all(PG_FUNCTION_ARGS) plowbound = &lowbound; /* - * we exploit the fact that the pairs list is already sorted into strictly + * We exploit the fact that the pairs list is already sorted into strictly * increasing order to narrow the findUncompressedJsonbValue search; each * search can start one entry past the previous "found" entry, or at the * lower bound of the last search. @@ -180,9 +181,9 @@ jsonb_exists_all(PG_FUNCTION_ARGS) if (findUncompressedJsonbValueByValue(VARDATA(js), JB_FLAG_OBJECT | JB_FLAG_ARRAY, plowbound, - v->array.elems + i) != NULL) + v->array.elems + i) == NULL) { - res = true; + res = false; break; } } diff --git a/src/backend/utils/adt/jsonb_support.c b/src/backend/utils/adt/jsonb_support.c index f55c4da64b..e695b892c6 100644 --- a/src/backend/utils/adt/jsonb_support.c +++ b/src/backend/utils/adt/jsonb_support.c @@ -306,15 +306,15 @@ compareJsonbBinaryValue(char *a, char *b) return res; } -/**************************************************************************** - * find string key in object or element by value in array * - ****************************************************************************/ +/* + * Find string key in object or element by value in array + */ JsonbValue * findUncompressedJsonbValueByValue(char *buffer, uint32 flags, uint32 *lowbound, JsonbValue *key) { - uint32 header = *(uint32 *) buffer; - static JsonbValue r; + uint32 header = *(uint32 *) buffer; + static JsonbValue r; Assert((header & (JB_FLAG_ARRAY | JB_FLAG_OBJECT)) != (JB_FLAG_ARRAY | JB_FLAG_OBJECT));