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

View returns a wrong result set if its definition contains JSON_ARRAYAGG

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • None
    • 10.5.4
    • JSON
    • None

    Description

      Create and populate table t1 with commands:

      create table t1 (o_id int, attribute varchar(16), value varchar(16));
      insert into t1 values (2,'color','red'),(2,'fabric','silk'),(3,'color','green'),(3,'shape','square');
      

      Define view v1:

      create view v1 as SELECT o_id, JSON_ARRAYAGG(attribute) AS attributes FROM t1 GROUP BY o_id order by attribute;
      

      The query

      select * from v1;
      

      returns

      MariaDB [test]> select * from v1;
      +------+--------------+
      | o_id | attributes   |
      +------+--------------+
      |    2 | color,fabric |
      |    3 | color,shape  |
      +------+--------------+
      

      while the query used in the definition of v1 returns

      MariaDB [test]> SELECT o_id, JSON_ARRAYAGG(attribute) AS attributes FROM t1 GROUP BY o_id order by attribute;
      +------+--------------------+
      | o_id | attributes         |
      +------+--------------------+
      |    2 | ["color","fabric"] |
      |    3 | ["color","shape"]  |
      +------+--------------------+
      

      We also have:

      MariaDB [test]> show create view v1;
      +------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
      | View | Create View                                                                                                                                                                                                                | character_set_client | collation_connection |
      +------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
      | v1   | CREATE ALGORITHM=UNDEFINED DEFINER=`` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`o_id` AS `o_id`,group_concat(`t1`.`attribute` separator ',') AS `attributes` from `t1` group by `t1`.`o_id` order by `t1`.`attribute` | utf8                 | utf8_general_ci      |
      +------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
      

      The bug happens because the class Item_func_json_arrayagg lacks an implementation of the print method.

      Attachments

        Activity

          People

            holyfoot Alexey Botchkov
            igor Igor Babaev
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.