Skip to content

MDEV-40180 Cache constant args in JSON_EQUALS and JSON_OVERLAPS#5455

Open
VasuBhakt wants to merge 1 commit into
MariaDB:10.11from
VasuBhakt:MDEV-40180-compare-nested-object
Open

MDEV-40180 Cache constant args in JSON_EQUALS and JSON_OVERLAPS#5455
VasuBhakt wants to merge 1 commit into
MariaDB:10.11from
VasuBhakt:MDEV-40180-compare-nested-object

Conversation

@VasuBhakt

Copy link
Copy Markdown

Fixes MDEV-40180

Problem

JSON_EQUALS evaluates and parses constant arguments per-row. JSON_OVERLAPS caches constant arguments in fix_length_and_dec, which fails to recalculate during --ps-protocol executions with changing bound parameters.

Solution

Migrated constant argument caching logic to ::val_bool() for both functions:

  1. Item_func_json_equals: Added deep-copy caching of the normalized DYNAMIC_STRING upon first evaluation of a constant argument. Subsequent evaluations bypass json_normalize_engine and reuse the cached string.
  2. Item_func_json_overlaps: Removed flawed a2_constant caching from fix_length_and_dec and implemented per-execution caching of the evaluated string inside val_bool().
  3. Prepared Statements: Overrode cleanup() in both classes to reset boolean caching flags, ensuring correct cache invalidation between executions.

(Note: The nested object short-circuit evaluation will be addressed in a follow-up incremental PR).

Tests

Executed the json, json_equals, and json_normalize MTR suites (both standard and --ps-protocol) to verify behavior preservation and resolution of the prepared statement cache bug.

Version

The change is directed at versions 10.11, 11.4, 11.8, and 12.3. The PR is based on branch 10.11, being the lowest affected branch.

* Optimize JSON_EQUALS by caching the normalized DYNAMIC_STRING of
  constant arguments within val_bool(), preventing redundant re-parsing.
* Fix JSON_OVERLAPS constant caching, which was improperly cached in
  fix_length_and_dec (causing --ps-protocol failures), by moving it to
  val_bool().
* Ensure cleanup() correctly resets caching state for both functions
  for prepared statements.
* Note: This commit intentionally skips the nested objects short-circuit
  logic, which will be implemented incrementally in a future update.

Signed-off-by: VasuBhakt <cpswastik31@gmail.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant