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

JSON_OBJECTAGG produces an invalid JSON document with duplicate keys (aggregate variant of MDEV-40979)

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • None
    • N/A
    • JSON
    • None
    • Not for Release Notes

    Description

      Like the non-aggregate JSON_OBJECT (MDEV-40979), JSON_OBJECTAGG emits an object with duplicate keys when the aggregated key column contains the same key more than once, which violates RFC 8259 ("names within an object should be unique").

      Reproduced on 10.11.19 and on 13.1 (debug builds):

      CREATE TABLE mo (id INT, k VARCHAR(4), v INT);
      INSERT INTO mo VALUES (1,'a',1),(3,'a',3),(2,'b',2);
       
      SELECT JSON_OBJECTAGG(k, v) FROM mo WHERE id IN (1,3);
      -- {"a":1, "a":3}
       
      SELECT JSON_VALID(JSON_OBJECTAGG(k, v)) FROM mo WHERE id IN (1,3);
      -- 1

      The result has two members named "a", and JSON_VALID accepts it. MySQL 8.0 returns "a": 3 for the same aggregate (the last value wins). The aggregate takes a separate code path from the JSON_OBJECT constructor (Item_func_json_objectagg), so the fix for MDEV-40979 will not cover it.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              chunlingqin chunlingqin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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