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

select field group by field with rollup

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.1.14, 5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL)
    • 10.11, 11.4, 11.8
    • OTHER
    • Linux

    Description

      I tested this issue with MsSQL server, on identical data and table. In MsSQL it works correctly.

      Suppose you have a table with field1, field2, etc.
      if you do a query like

      select field1, sum(field2)
      group by field1
      with rollup
      

      in MariaDB the result is correct and looks like this, where x and y are the contents of columns field1 and field2

      x, sum(y)
      x1,sum(y)
      null, sum(y)
      

      That is: the null on the lower left indicates that this is the grouping field.

      However, suppose that this column is a string, and then we are grouping on a part of the column. Here is a concrete example.

      CREATE TABLE demo(field1 varchar(100) PRIMARY KEY,field2 int(11));
      INSERT demo(field1,field2) VALUES('192.168.1.20-Servere1',100),('192.168.1.3-Server3',200),('192.168.1.20-Server1',100),('192.168.1.3-Server2',400);
       select * from demo;
      

          SELECT SUBSTRING(field1,1,instr(field1, '-')-1) AS Name, SUM(field2)
          FROM demo
          GROUP BY SUBSTRING(field1,1,instr(field1, '-')-1)
          WITH rollup
      

      • RESULT IS INCORRECT, THE LOWER LEFT NULL IS NOT PRESENT

      By contrast, in MsSQL, this identical query is correct:

        SELECT SUBSTRING(field1,1, charINDEX('-',field1, 0)-1) AS Mycol, SUM(field2)
          FROM demo
          GROUP BY SUBSTRING(field1,1, charINDEX('-',field1, 0)-1)
          WITH ROLLUP
      

      Attachments

        Issue Links

          Activity

            People

              psergei Sergei Petrunia
              philip_38 Philip orleans
              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.