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

IN lists with ≥2 elements are constantly false (single element works, OR expansion works)

    XMLWordPrintable

Details

    Description

      The single-element IN matching shows it goes through the = JSON-semantic path (compare_e_json_str); with ≥2 elements the multi-value comparison path of Item_func_in falls back to plain string comparison (quoted JSON text "abc" vs the bare value abc, not equal), constantly false. The semantically equivalent OR expansion and IN give different results, and it is incompatible with MySQL.

      CREATE TABLE t(j JSON);
      INSERT INTO t VALUES ('{"a":"abc"}'), ('{"a":"xyz"}');
       
      SELECT COUNT(*) FROM t WHERE j->'$.a' = 'abc';                 -- 1  ✓ single = correct
      SELECT COUNT(*) FROM t WHERE j->'$.a' IN ('abc');              -- 1  ✓ single-element IN correct
      SELECT COUNT(*) FROM t WHERE j->'$.a' IN ('abc','ABC');        -- 0  ✗ two-element broken!
      SELECT COUNT(*) FROM t WHERE j->'$.a' IN ('xyz','abc','qqq');  -- 0  ✗ three-element broken!
      SELECT COUNT(*) FROM t WHERE j->'$.a' = 'abc' OR j->'$.a' = 'ABC';  -- 1 ✓ OR expansion correct
      SELECT ('{"a":"abc"}'->'$.a') IN ('abc','ABC');                -- 0  ✗ broken in constant context too
      SELECT COUNT(*) FROM t WHERE j->>'$.a' IN ('abc','ABC');       -- 1  ✓ ->> correct (control group)
       
      -- MySQL reference (trunk 26.7.0):
      SELECT COUNT(*) FROM t WHERE JSON_EXTRACT(j,'$.a') IN ('abc','ABC');  -- 1

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              chunlingqin chunlingqin
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.