Skip to content

MDEV-41067 wrong result with json_overlaps when one of the arguments has an empty nested array element - #5711

Open
DerZc wants to merge 1 commit into
MariaDB:11.4from
DerZc:fix-mdev-41067
Open

DerZc wants to merge 1 commit into
MariaDB:11.4from
DerZc:fix-mdev-41067

Conversation

@DerZc

@DerZc DerZc commented Sep 21, 2026 •

Copy link
Copy Markdown

JSON_OVERLAPS can report an overlap between unequal nested arrays, including JSON_OVERLAPS('[[1]]','[[]]'), which must return 0.

Bug report: https://jira.mariadb.org/browse/MDEV-41067

Root cause

The nested-container comparison treats reaching the end of one input as sufficient for equality, without also requiring the other input to reach its matching end.

Changes

  • Require both JSON parser states to be at their array/object end before accepting the nested-container match.
  • Retain the existing cleanup that advances both parsers after the comparison.

Regression coverage

The regression is integrated into the existing main.func_json test.

The regression checks that [[1]] and [[]] have no equal nested element and that JSON_OVERLAPS returns 0.

  • mysql-test/main/func_json.test
  • mysql-test/main/func_json.result

Validation

On 11.4 at d10e5d726799b1cd57cc866f40aad68c720803da:

  • The server build passed.
  • The complete main.func_json test, including the integrated regression, failed on the unchanged target branch at the regression case and passed with this fix.
  • Existing MTR tests passed: main.func_json, main.select.
  • MTR reported no test-state cleanup failures.
  • The full regression suite was not run.

@CLAassistant

CLAassistant commented Sep 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Sep 23, 2026
@gkodinov gkodinov self-assigned this Sep 23, 2026

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

Please squash your two commits into a single one. Otherwise: a very good analysis and a good looking fix!

…has an empty nested array element

JSON_OVERLAPS can report an overlap between unequal nested arrays,
including JSON_OVERLAPS('[[1]]','[[]]'), which must return 0.

The nested-container comparison treats reaching the end of one input as
sufficient for equality, without also requiring the other input to reach
its matching end.

Require both JSON parser states to be at their array/object end before
accepting the nested-container match. Retain the existing cleanup that
advances both parsers after the comparison.

The regression checks that [[1]] and [[]] have no equal nested element
and that JSON_OVERLAPS returns 0.

Bug report: https://jira.mariadb.org/browse/MDEV-41067

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! LGTM. Please stand by for the final review.

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

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

4 participants