]> granicus.if.org Git - postgresql/commit
Fix bogus optimization in JSONB containment tests.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 11 Oct 2014 18:13:51 +0000 (14:13 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 11 Oct 2014 18:13:51 +0000 (14:13 -0400)
commit4a50de13127b7657f32f14dc17beb2e15a3a4777
tree5df9de2e7f49d6267141dca6be0bec0dd9c3ea98
parent733be2a5cd124b28a15d5d09de9b227691e6c5a0
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.
src/backend/utils/adt/jsonb_op.c
src/backend/utils/adt/jsonb_util.c
src/test/regress/expected/jsonb.out
src/test/regress/expected/jsonb_1.out
src/test/regress/sql/jsonb.sql