Thread: pgsql: Fix bogus optimization in JSONB containment tests.

pgsql: Fix bogus optimization in JSONB containment tests.

From
Tom Lane
Date:
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.

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/86b889494a71bd6c9574de04d6612d367bc5a423

Modified Files
--------------
src/backend/utils/adt/jsonb_op.c      |   10 ++++-----
src/backend/utils/adt/jsonb_util.c    |   16 +++++++++++++--
src/test/regress/expected/jsonb.out   |   36 +++++++++++++++++++++++++++++++++
src/test/regress/expected/jsonb_1.out |   36 +++++++++++++++++++++++++++++++++
src/test/regress/sql/jsonb.sql        |    7 +++++++
5 files changed, 97 insertions(+), 8 deletions(-)