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

JSON_OBJECT_FILTER_KEYS does not evaluate array_keys per row

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.4, 11.8, 12.3, 13.0, 13.0.1
    • 11.4, 11.8, 12.3, 13.0
    • JSON
    • - Docker-based MariaDB 13.0.1 runtime
      - Exact image ID, host OS/architecture, compiler/build data, storage-engine settings, and `my.cnf` were not retained
      - The runtime image was not built from the reviewed source snapshot
    • Unexpected results

    Description

      Description

      When the `array_keys` argument of `JSON_OBJECT_FILTER_KEYS(obj, array_keys)` comes from a table column, the function returns NULL for every row instead of evaluating that argument per row. A literal key array works correctly.

      The source path reviewed for the lightweight report evaluates `args[1]` while fixing result metadata and only reevaluates `args[0]` during row execution. The relevant locations are `sql/item_jsonfunc.cc:6227-6270` and `sql/item_jsonfunc.cc:6274-6318`. This implementation observation is supplemental; the externally observed behavior is the reporting basis.

      How to Repeat

      CREATE TABLE json_filter_test (
        obj LONGTEXT CHECK (JSON_VALID(obj)),
        keys_json LONGTEXT CHECK (JSON_VALID(keys_json))
      );
       
      INSERT INTO json_filter_test VALUES
        ('{"a":1,"b":2,"c":3}', '["b"]'),
        ('{"a":10,"b":20,"c":30}', '["a","c"]');
       
      -- Negative control.
      SELECT JSON_OBJECT_FILTER_KEYS('{"a":1,"b":2}', '["b"]');
       
      -- Positive case.
      SELECT JSON_OBJECT_FILTER_KEYS(obj, keys_json)
      FROM json_filter_test
      ORDER BY obj;
       
      CREATE VIEW json_filter_view AS
      SELECT JSON_OBJECT_FILTER_KEYS(obj, keys_json) AS filtered
      FROM json_filter_test;
      SHOW COLUMNS FROM json_filter_view;
      

      Actual Result

      The literal call returns `

      {"b": 2}

      `. Both table-column calls return NULL, and the view column is described as `binary(0)`.

      Expected Result

      The function should evaluate `array_keys` for each input row. The result should be equivalent to:

      {"b": 2}
      {"a": 10, "c": 30}
      

      The view metadata should describe a normal JSON/string result width rather than `binary(0)`.

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              Mizuki Zhang Baoren
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.