aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonb_op.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-10-11 14:13:51 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-10-11 14:13:51 -0400
commit4a50de13127b7657f32f14dc17beb2e15a3a4777 (patch)
tree5df9de2e7f49d6267141dca6be0bec0dd9c3ea98 /src/backend/utils/adt/jsonb_op.c
parent733be2a5cd124b28a15d5d09de9b227691e6c5a0 (diff)
downloadpostgresql-4a50de13127b7657f32f14dc17beb2e15a3a4777.tar.gz
postgresql-4a50de13127b7657f32f14dc17beb2e15a3a4777.zip
Fix bogus optimization in JSONB containment tests.
When determining whether one JSONB object contains another, it's okay to make a quick exit if the first object has fewer pairs than the second: because we de-duplicate keys within objects, it is impossible that the first object has all the keys the second does. However, the code was applying this rule to JSONB arrays as well, where it does *not* hold because arrays can contain duplicate entries. The test was really in the wrong place anyway; we should do it within JsonbDeepContains, where it can be applied to nested objects not only top-level ones. Report and test cases by Alexander Korotkov; fix by Peter Geoghegan and Tom Lane.
Diffstat (limited to 'src/backend/utils/adt/jsonb_op.c')
-rw-r--r--src/backend/utils/adt/jsonb_op.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/backend/utils/adt/jsonb_op.c b/src/backend/utils/adt/jsonb_op.c
index 2d071b2523b..d9aaac9ac27 100644
--- a/src/backend/utils/adt/jsonb_op.c
+++ b/src/backend/utils/adt/jsonb_op.c
@@ -57,7 +57,7 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
for (i = 0; i < elem_count; i++)
{
- JsonbValue strVal;
+ JsonbValue strVal;
if (key_nulls[i])
continue;
@@ -90,7 +90,7 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
for (i = 0; i < elem_count; i++)
{
- JsonbValue strVal;
+ JsonbValue strVal;
if (key_nulls[i])
continue;
@@ -117,8 +117,7 @@ jsonb_contains(PG_FUNCTION_ARGS)
JsonbIterator *it1,
*it2;
- if (JB_ROOT_COUNT(val) < JB_ROOT_COUNT(tmpl) ||
- JB_ROOT_IS_OBJECT(val) != JB_ROOT_IS_OBJECT(tmpl))
+ if (JB_ROOT_IS_OBJECT(val) != JB_ROOT_IS_OBJECT(tmpl))
PG_RETURN_BOOL(false);
it1 = JsonbIteratorInit(&val->root);
@@ -137,8 +136,7 @@ jsonb_contained(PG_FUNCTION_ARGS)
JsonbIterator *it1,
*it2;
- if (JB_ROOT_COUNT(val) < JB_ROOT_COUNT(tmpl) ||
- JB_ROOT_IS_OBJECT(val) != JB_ROOT_IS_OBJECT(tmpl))
+ if (JB_ROOT_IS_OBJECT(val) != JB_ROOT_IS_OBJECT(tmpl))
PG_RETURN_BOOL(false);
it1 = JsonbIteratorInit(&val->root);