Re: [PATCH v1] Match jsonpath variable names exactly when checking mutability

From: Tomás Senart <ts(at)perfloop(dot)ai>
To: Joao Rito <joaovictor(dot)rito(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH v1] Match jsonpath variable names exactly when checking mutability
Date: 2026-11-21 02:53:43
Message-ID: CAEEBa3UzqQhK0mkvaJygjWnHNEBJJ-43R-41yT21deBdodgHKg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Joao,

Thanks for testing the patch and for the careful notes.

1. Agreed. v2 adds a comment above the second test: it was rejected
before the fix too, and it guards the reverse match. The code and the
other tests do not change.
2. I checked this. The stored jsonpath string ends with a NUL byte
(flattenJsonPathParseItem() appends one), so strcmp() would also work.
I kept the length comparison because GetJsonPathVar() makes the same
check at execution time (namelen == varNameLen && strncmp(...)), so
the two places match.
3. Thanks, I kept the upgrade note.

I also ran the items you listed as not tested. All builds have
assertions enabled.

- Wrong result on unpatched master (4892c94): a table of 1000 rows
with js = '"08:00 +00"', and an index on JSON_QUERY(js,
'$.datetime("HH:MI TZH") < $x' PASSING '12:34+00'::timetz AS xx,
'12:34'::time AS x), built with TimeZone = 'UTC'. With UTC, the index
scan and the sequential scan both return 1000 rows. With Asia/Tokyo,
the index scan returns 1000 rows and the sequential scan returns 0.
With the patch, CREATE INDEX fails.
- make check and make installcheck pass on master (243 tests).
- REL_18_STABLE and REL_17_STABLE: the v1 expected output does not
apply there, because these branches do not print the "LINE 1:" context
for this error. The attached back-branch patch has the same code and
tests, with only the expected output changed. It applies to both
branches, and make check passes (235 tests on 18, 229 on 17).
- JSON_QUERY, JSON_VALUE and JSON_EXISTS, each in an index expression
and in a stored generated column, with three PASSING names where each
is a prefix of the next (x, xx, xxx): all 6 orders, the time value on
each name, and each name referenced, plus the two-name cases. That is
348 statements. With the patch, every statement is rejected exactly
when the referenced variable is the time value. On unpatched master,
96 of the 348 give the wrong answer.
- The same 348 statements with non-ASCII names, in a UTF8 database (é,
éé, ééé) and in an EUC_JP database (あ, ああ, あああ), give the same results
with the patch.
- jsonb_path_exists(), jsonb_path_query_first() and jsonb_path_match()
with a vars argument are rejected in index expressions with and
without the patch. The patch does not change them.

I did not test the upgrade case, performance, or other compilers,
Windows or meson.

Regards,
Tomás

Attachment Content-Type Size
v2-REL_17-0001-Match-jsonpath-variable-names-exactly-when-checki.patch.txt text/plain 5.0 KB
v2-0001-Match-jsonpath-variable-names-exactly-when-checki.patch text/x-patch 5.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2026-11-21 03:04:23 Re: Three more loops that let a function drop a not-yet-processed index/partition
Previous Message Tender Wang 2026-11-21 02:42:10 Re: MERGE fails to reject source references in NOT MATCHED BY SOURCE actions