Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-40708

JSON_OVERLAPS returns 0 for a pair that does overlap when the document breaks later, and cannot report failure at all

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3, 13.0
    • None
    • JSON

    Description

      JSON_OVERLAPS returns a boolean and has no way to say it could not read
      its arguments, so a failed read is returned as FALSE. Where the two
      documents do overlap, that is a wrong answer.

      SELECT JSON_OVERLAPS('{"a":1, "b":2 "c":3}', '{"a":1}') AS v;
      v
      0
      Warnings:
      Warning  4038  Syntax error in JSON text in argument 1
                    to function 'json_overlaps' at position 15

      "a":1 is common to both arguments, so the documented answer is true.
      The 0 is a genuine FALSE and not a NULL:

      SELECT JSON_OVERLAPS('{"a":1, "b":2 "c":3}', '{"a":1}') IS NULL AS is_it_null;
      is_it_null
      0

      Every sibling answers NULL on a failed read. On the same document,
      JSON_CONTAINS and JSON_EQUALS both return NULL with Warning 4038 at
      position 15. For JSON_OVERLAPS alone, "they do not overlap" and "I
      could not read that" are the same value.

      How to repeat

      -- an overlap that exists, reported as no overlap
      SELECT JSON_OVERLAPS('{"a":1, "b":2 "c":3}', '{"a":1}') AS wrong_answer;
      0
       
      -- and the other direction: a break that is never reported at all
      -- 1, silent
      SELECT JSON_OVERLAPS('[1,2,3 4]', '[3]')                     AS v;
      -- 1, silent
      SELECT JSON_OVERLAPS('[{"a":1},{"b":2 "c":3}]', '[{"a":1}]') AS v;

      Root cause

      The `error:` label in `Item_func_json_overlaps::val_bool()` returns 0
      without setting `null_value`, so the failure is indistinguishable from a
      computed FALSE.

      Contract, `scripts/fill_help_tables.sql:455`: *"returns true if they
      have at least one common key-value pair between two objects, array
      element common between two arrays, ..."*

      Not this bug

      SET @d32 = CONCAT(REPEAT('[', 32), '1', REPEAT(']', 32));
      SELECT JSON_OVERLAPS(@d32, @d32);

      crashes the server with signal 11 on 10.11. That is MDEV-40590, which
      is already filed and fixed, and is not part of this report.

      Affected versions

      JSON_OVERLAPS was added in 10.9.1.

      Verified on 10.11 only (10.11.19-MariaDB-debug, commit 1dab253482d).
      Other branches were not tested.

      Note

      Found while auditing the JSON functions against their documented
      contracts. Partial and it pins the defect:
      func_json_invalid.result:262 records JSON_OVERLAPS('[1,','[1]') = 1.
      The overlap-exists-but-the-answer-is-0 case is covered nowhere.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              arcivanov Arcadiy Ivanov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.