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

LAG() Window Function Error with ONLY_FULL_GROUP_BY

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.4.12, 10.5.5, 10.4(EOL), 10.5
    • 10.5
    • None
    • 10.4.12-MariaDB is running on Centos 7.8.2003
      10.5.5-MariaDB-1:10.5.5+maria~focal is running in Docker using the official MariaDB image

    Description

      The LAG() window function incorrectly triggers an error when the SQL_MODE "ONLY_FULL_GROUP_BY" is enabled.

      The error message reads:

      Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
      SQLState: 42000
      ErrorCode: 1140

      This error should not occur because LAG() is not an aggregate function - it is a window function - and so there is no requirement for a GROUP BY clause.

      Example

      -- Works as expected
      set @@sql_mode = '';
      with cte as (
      	select 1 as id
      )
      select id, lag(id) over (order by id) from cte;
       
      -- Throws unexpected error: "Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause"
      set @@sql_mode = 'ONLY_FULL_GROUP_BY';
      with cte as (
      	select 1 as id
      )
      select id, lag(id) over (order by id) from cte;
      

      Attachments

        Activity

          Thanks for the report.

          A version of the same without CTE (if needed for comparison with other databases):

          create table t1 (id int);
          set sql_mode='';
          select id, lag(id) over (order by id) from t1;
          set sql_mode='ONLY_FULL_GROUP_BY';
          select id, lag(id) over (order by id) from t1;
          drop table t1;
          

          At line 5: query 'select id, lag(id) over (order by id) from t1' failed: 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
          

          elenst Elena Stepanova added a comment - Thanks for the report. A version of the same without CTE (if needed for comparison with other databases): create table t1 (id int ); set sql_mode= '' ; select id, lag(id) over ( order by id) from t1; set sql_mode= 'ONLY_FULL_GROUP_BY' ; select id, lag(id) over ( order by id) from t1; drop table t1; At line 5: query 'select id, lag(id) over (order by id) from t1' failed: 1140: Mixing of GROUP columns ( MIN (), MAX (), COUNT (),...) with no GROUP columns is illegal if there is no GROUP BY clause

          This issue is resolved on 10.11.6-MariaDB-1:10.11.6+maria~ubu2204

          brandonkirsch Brandon Kirsch added a comment - This issue is resolved on 10.11.6-MariaDB-1:10.11.6+maria~ubu2204

          People

            psergei Sergei Petrunia
            brandonkirsch Brandon Kirsch
            Votes:
            1 Vote for this issue
            Watchers:
            3 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.