| From: | Joao Rito <joaovictor(dot)rito(at)gmail(dot)com> |
|---|---|
| To: | Tomás Senart <ts(at)perfloop(dot)ai> |
| 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-18 20:21:09 |
| Message-ID: | 20261118202109.28678-1-joaovictor.rito@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Tomás,
Thank you for the patch. I may be wrong on some points, so please correct me.
I tested v1 on a current master (19ab0ba), built with --enable-cassert.
Without the patch, this statement is accepted:
CREATE INDEX ON test_jsonb_mutability (JSON_QUERY(js,
'$.datetime("HH:MI TZH") < $x'
PASSING '12:34'::timetz AS xx, '12:34'::time AS x));
With the patch, it fails with "functions in index expression must be marked IMMUTABLE". I think this is the expected result, because `$x` is a `time` value and the comparison depends on TimeZone.
The patch applies cleanly. `make check` passes (243 tests).
Some small notes, which may be only my taste:
1. The second new test (`$xx` with `AS x` and `AS xx`) gives the same error on master, so it does not fail without the fix. It still looks useful to me as a guard for the other direction. Maybe a short comment could say this.
2. In the new condition, `strlen(varname->sval) != len || strncmp(...) != 0`, I first wondered if `strcmp` would be simpler. I think `name` may not be NUL-terminated, so `len` is needed and your version looks fine to me. I did not check this in detail.
3. The commit message says previously accepted indexes may need to be dropped and that a dump restore can fail. I think this is a good thing to keep, since it is an upgrade note.
What I did not test:
- Your wrong-result example with different TimeZone settings (Tokyo vs UTC). I only tested that CREATE INDEX is rejected.
- `make installcheck`. I ran only `make check`.
- Other branches (the patch says backpatch to 17). I only tested master.
- The upgrade case: an index created on an older minor version, then pg_dump / restore on a patched server.
- Other jsonpath functions (JSON_EXISTS, JSON_VALUE, jsonb_path_* in index or generated column expressions).
- Variables with names that are prefixes in a longer list of PASSING items (3 or more names).
- Non-ASCII variable names and multibyte encodings.
- Performance (I expect no effect).
- Build with other compilers, Windows, or meson.
Thank you for your time.
Best regards,
Joao Rito
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tristan Partin | 2026-11-18 20:35:48 | Re: Add ids to catalog/view columns in documentation |
| Previous Message | Andres Freund | 2026-11-18 20:07:47 | Re: CI slowdown due to PG_TEST_INITDB_EXTRA_OPTS |