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

Group concat returns incorrect result when using DISTINCT and ORDER BY

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.2(EOL), 10.3(EOL), 10.4(EOL), 10.5, 11.6(EOL)
    • 10.5, 10.6, 10.11, 11.4
    • Optimizer
    • None

    Description

      Data set:

      create table t1 (a varchar(1000), b varchar(1000), c varchar(1000));
      insert t1 select seq,seq, seq from seq_1_to_9;
      insert t1 select seq,seq, seq from seq_1_to_9;
      

      set tmp_table_size=1024; // set so that unique tree is dumped to the disk
      

      Now lets run the query without DISTINCT in GROUP_CONCAT

      MariaDB [test]> select group_concat(c order by a,b) from t1;
      +-------------------------------------+
      | group_concat(c order by a,b)        |
      +-------------------------------------+
      | 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9 |
      +-------------------------------------+
      1 row in set (0.005 sec)
      

      Now running the query with DISTINCT in GROUP_CONCAT

      MariaDB [test]> select group_concat(distinct c order by a,b) from t1;
      +---------------------------------------+
      | group_concat(distinct c order by a,b) |
      +---------------------------------------+
      | 1                                     |
      +---------------------------------------+
      1 row in set (0.006 sec)
      

      This is observed on top of the branch 10.5-mdev11563 (also expected to fail on all other versions)

      So the issue here is when Unique does not fit in memory for DISTINCT we flush the unique tree to the disk but in such cases we get incorrect result

      Attachments

        Issue Links

          Activity

            Pushed a patch for this to the branch 10.5-mdev11563

            varun Varun Gupta (Inactive) added a comment - Pushed a patch for this to the branch 10.5-mdev11563

            The patch says:
            https://github.com/MariaDB/server/commit/300e28f1cfc835fd301414dac78315de8c854605#diff-fc18518f3f16df7a264a08d03cb2e9d9R3790

            // Currently JSON_ARRAYAGG does not support ORDER BY clause
            

            but the parser accepts this?

            psergei Sergei Petrunia added a comment - The patch says: https://github.com/MariaDB/server/commit/300e28f1cfc835fd301414dac78315de8c854605#diff-fc18518f3f16df7a264a08d03cb2e9d9R3790 // Currently JSON_ARRAYAGG does not support ORDER BY clause but the parser accepts this?

            (JSON_ARRAYAGG is already broken by the patch for MDEV-22011, see that MDEV for details)

            psergei Sergei Petrunia added a comment - (JSON_ARRAYAGG is already broken by the patch for MDEV-22011 , see that MDEV for details)
            varun Varun Gupta (Inactive) added a comment - New patch based on 10.5 https://github.com/MariaDB/server/commit/5a6da66e6f081877b78c81656db9fd2a7e34598a

            People

              psergei Sergei Petrunia
              varun Varun Gupta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.