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

ONLY_FULL_GROUP_BY rejects outer column reference that is aggregated in correlated subquery

    XMLWordPrintable

Details

    Description

      Under ONLY_FULL_GROUP_BY, when a correlated subquery aggregates a column of an outer query, the server incorrectly raises ER_WRONG_FIELD_WITH_GROUP. For example:

      CREATE TABLE t1 (a INT, b INT);
      CREATE TABLE t2 (c INT, d INT);
      INSERT INTO t1 VALUES (1,10),(2,10),(3,20);
      INSERT INTO t2 VALUES (1,100),(2,200),(3,300);
       
      SET SQL_MODE=ONLY_FULL_GROUP_BY;
       
      SELECT b, (SELECT SUM(t2.d) + SUM(t1.a) FROM t2) AS sub FROM t1 GROUP BY b;
      

      The query should be accepted since t1.a appears inside SUM() and thus is aggregated. In MySQL the query returns:

      +------+------+
      | b    | sub  |
      +------+------+
      |   10 |  603 |
      |   20 |  603 |
      +------+------+
      

      But in MariaDB, we receive:

      ERROR 1055 (42000) at line 8: 'db.t1.a' isn't in GROUP BY
      

      Attachments

        Activity

          People

            Johnston Rex Johnston
            jaeheonshim Jaeheon Shim
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.