pgsql: Fix PASSING of toasted text values in JSON query functions - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Fix PASSING of toasted text values in JSON query functions
Date
Msg-id E1x7t33-00000000ONi-0rtL@gemulon.postgresql.org
Whole thread
List pgsql-committers
Fix PASSING of toasted text values in JSON query functions

The PASSING arguments of JSON_EXISTS(), JSON_QUERY(), JSON_VALUE() and
JSON_TABLE() are evaluated by plain expression steps and given to the
jsonpath executor as-is.

When dealing with a varlena, JsonItemFromDatum() was building a
jbvString directly the contents of a varlena.  For a varatt_external
(varatt_external[oid/oid8] on HEAD), this ignored that the contents of
the varlena need to be detoasted, leading to incorrect contents
returned.

Let's detoast the value, like the jsonb and json cases.  b0feda79fdf0
has fixed the same issue for subscript values in jsonb.

Note that the results of DatumGetTextPP() are allocated in the memory
context used for the evaluation of the expression, which is reset once
per row.

Oversight in 6185c9737cf4.

Author: Chaitanya Choudhary <chaitanyyachoudhary@gmail.com>
Author: Shihao Zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/19693-2ecd2b52c838b3e5@postgresql.org
Backpatch-through: 17

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ab713cdcdbfd05b72a6959ff17aad56cf075ae31

Modified Files
--------------
src/backend/utils/adt/jsonpath_exec.c            | 12 +++++++----
src/test/regress/expected/sqljson_queryfuncs.out | 26 ++++++++++++++++++++++++
src/test/regress/sql/sqljson_queryfuncs.sql      | 16 +++++++++++++++
3 files changed, 50 insertions(+), 4 deletions(-)


pgsql-committers by date:

Previous
From: Amit Langote
Date:
Subject: Re: pgsql: Invalidate RI fast-path metadata on operator family changes
Next
From: Richard Guo
Date:
Subject: pgsql: Fix preprocessing of PHV copies pushed down into subqueries