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

Range-type window frame supports only numeric datatype

Details

    Description

      create table t1 (a int, b varchar(5));
      insert into t1 values (1,'a'), (2, 'b'), (3, 'c');
       
      select sum(a) over (order by b range between unbounded preceding and current row) from t1;
      

      MariaDB [test]> select sum(a) over (order by b range between unbounded preceding and current row) from t1;
      ERROR 4021 (HY000): Numeric datatype is required for RANGE-type frame
      

      Mysql/Postgres return:

      mysql> select sum(a) over (order by b range between unbounded preceding and current row) from t1;
      +----------------------------------------------------------------------------+
      | sum(a) over (order by b range between unbounded preceding and current row) |
      +----------------------------------------------------------------------------+
      |                                                                          1 |
      |                                                                          3 |
      |                                                                          6 |
      +----------------------------------------------------------------------------+
      3 rows in set (0.00 sec)
      

      Also range-type frame always expects ORDER BY clause:

      MariaDB [test]> select sum(a) over (range between unbounded preceding and current row) from t1;
      ERROR 4019 (HY000): RANGE-type frame requires ORDER BY clause with single sort key
      

      Mysql 8.0.15:

      mysql> select sum(a) over (range between unbounded preceding and current row) from t1;
      +-----------------------------------------------------------------+
      | sum(a) over (range between unbounded preceding and current row) |
      +-----------------------------------------------------------------+
      |                                                               6 |
      |                                                               6 |
      |                                                               6 |
      +-----------------------------------------------------------------+
      3 rows in set (0.00 sec)
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa created issue -
            alice Alice Sherepa made changes -
            Field Original Value New Value
            Assignee Varun Gupta [ varun ]
            alice Alice Sherepa made changes -
            Description {code:sql}
            create table t1 (a int, b varchar(5));
            insert into t1 values (1,'a'), (2, 'b'), (3, 'c');

            select sum(a) over (order by b range between unbounded preceding and current row) from t1;
            {code}
            {noformat}
            MariaDB [test]> select sum(a) over (order by b range between unbounded preceding and current row) from t1;
            ERROR 4021 (HY000): Numeric datatype is required for RANGE-type frame
            {noformat}

            Mysql/Postgres return:
            {noformat}
            mysql> select sum(a) over (order by b range between unbounded preceding and current row) from t1;
            +----------------------------------------------------------------------------+
            | sum(a) over (order by b range between unbounded preceding and current row) |
            +----------------------------------------------------------------------------+
            | 1 |
            | 3 |
            | 6 |
            +----------------------------------------------------------------------------+
            3 rows in set (0.00 sec)
            {noformat}
            {code:sql}
            create table t1 (a int, b varchar(5));
            insert into t1 values (1,'a'), (2, 'b'), (3, 'c');

            select sum(a) over (order by b range between unbounded preceding and current row) from t1;
            {code}
            {noformat}
            MariaDB [test]> select sum(a) over (order by b range between unbounded preceding and current row) from t1;
            ERROR 4021 (HY000): Numeric datatype is required for RANGE-type frame
            {noformat}

            Mysql/Postgres return:
            {noformat}
            mysql> select sum(a) over (order by b range between unbounded preceding and current row) from t1;
            +----------------------------------------------------------------------------+
            | sum(a) over (order by b range between unbounded preceding and current row) |
            +----------------------------------------------------------------------------+
            | 1 |
            | 3 |
            | 6 |
            +----------------------------------------------------------------------------+
            3 rows in set (0.00 sec)
            {noformat}
            Also range-type frame always expects ORDER BY clause:

            {noformat}
            MariaDB [test]> select sum(a) over (range between unbounded preceding and current row) from t1;
            ERROR 4019 (HY000): RANGE-type frame requires ORDER BY clause with single sort key
            {noformat}

            Mysql 8.0.15: {noformat}
            mysql> select sum(a) over (range between unbounded preceding and current row) from t1;
            +-----------------------------------------------------------------+
            | sum(a) over (range between unbounded preceding and current row) |
            +-----------------------------------------------------------------+
            | 6 |
            | 6 |
            | 6 |
            +-----------------------------------------------------------------+
            3 rows in set (0.00 sec)
            {noformat}
            elenst Elena Stepanova made changes -
            Summary Range-typy window frame supports only numeric datatype Range-type window frame supports only numeric datatype
            alice Alice Sherepa added a comment -

            create table t1 (a int, b int);
            insert into t1 values (1,1), (1, 2), (1, 3), (2,1), (2,2);
             
            select sum(a) over (order by a,b range between unbounded preceding and current row) from t1;
            

            RANGE-type frame requires ORDER BY clause with single sort key, while in Mysql/Postgres this works:

            MariaDB [test]> select sum(a) over (order by a,b range between unbounded preceding and current row) from t1;
            ERROR 4019 (HY000): RANGE-type frame requires ORDER BY clause with single sort key
            ------------------------------------------------------------------------------------
             
            mysql> select sum(a) over (order by a,b range between unbounded preceding and current row) from t1;
            +------------------------------------------------------------------------------+
            | sum(a) over (order by a,b range between unbounded preceding and current row) |
            +------------------------------------------------------------------------------+
            |                                                                            1 |
            |                                                                            2 |
            |                                                                            3 |
            |                                                                            5 |
            |                                                                            7 |
            +------------------------------------------------------------------------------+
            5 rows in set (0.00 sec)
            

            alice Alice Sherepa added a comment - create table t1 (a int , b int ); insert into t1 values (1,1), (1, 2), (1, 3), (2,1), (2,2);   select sum (a) over ( order by a,b range between unbounded preceding and current row) from t1; RANGE-type frame requires ORDER BY clause with single sort key, while in Mysql/Postgres this works: MariaDB [test]> select sum(a) over (order by a,b range between unbounded preceding and current row) from t1; ERROR 4019 (HY000): RANGE-type frame requires ORDER BY clause with single sort key ------------------------------------------------------------------------------------   mysql> select sum(a) over (order by a,b range between unbounded preceding and current row) from t1; +------------------------------------------------------------------------------+ | sum(a) over (order by a,b range between unbounded preceding and current row) | +------------------------------------------------------------------------------+ | 1 | | 2 | | 3 | | 5 | | 7 | +------------------------------------------------------------------------------+ 5 rows in set (0.00 sec)
            alice Alice Sherepa made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            john-medeiros John Medeiros added a comment -

            Same behavior founded. Version: 10.3.21-MariaDB.

            john-medeiros John Medeiros added a comment - Same behavior founded. Version: 10.3.21-MariaDB.
            julien.fritsch Julien Fritsch made changes -
            Assignee Varun Gupta [ varun ] Sergei Petrunia [ psergey ]
            alice Alice Sherepa made changes -
            Affects Version/s 10.5 [ 23123 ]
            alice Alice Sherepa made changes -
            Component/s Optimizer - Window functions [ 13502 ]
            alice Alice Sherepa made changes -
            Fix Version/s 10.5 [ 23123 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 93531 ] MariaDB v4 [ 144126 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.2 [ 14601 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.3 [ 22126 ]
            danblack Daniel Black made changes -
            Assignee Sergei Petrunia [ psergey ] Daniel Black [ danblack ]
            danblack Daniel Black made changes -
            Status Confirmed [ 10101 ] In Progress [ 3 ]
            danblack Daniel Black added a comment - psergei , can I please get a review on https://github.com/MariaDB/server/pull/3334
            danblack Daniel Black made changes -
            Assignee Daniel Black [ danblack ] Sergei Petrunia [ psergey ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            danblack Daniel Black made changes -
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.11 [ 27614 ]
            Fix Version/s 10.4 [ 22408 ]
            danblack Daniel Black made changes -
            danblack Daniel Black added a comment -

            Not sure if it's compliant with standard or not but this change adds the following like alice put on the first comment:

            "select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) from t1" as a valid syntax.

            It seems to work properly, and MySQL 8.0 and Postgres support that syntax as well (results of the query are equal as well).

            danblack Daniel Black added a comment - Not sure if it's compliant with standard or not but this change adds the following like alice put on the first comment: "select a, b, sum(b) over (order by a desc, b range between unbounded preceding and current row) from t1" as a valid syntax. It seems to work properly, and MySQL 8.0 and Postgres support that syntax as well (results of the query are equal as well).

            Added my input with question for danblack

            psergei Sergei Petrunia added a comment - Added my input with question for danblack
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Daniel Black [ danblack ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            danblack Daniel Black added a comment -

            Thanks psergei

            danblack Daniel Black added a comment - Thanks psergei
            danblack Daniel Black made changes -
            Fix Version/s 10.5.26 [ 29832 ]
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.11 [ 27614 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            JIraAutomate JiraAutomate made changes -
            Fix Version/s 10.6.19 [ 29833 ]
            Fix Version/s 10.11.9 [ 29834 ]
            Fix Version/s 11.1.6 [ 29835 ]
            Fix Version/s 11.2.5 [ 29836 ]
            Fix Version/s 11.4.3 [ 29837 ]

            People

              danblack Daniel Black
              alice Alice Sherepa
              Votes:
              1 Vote for this issue
              Watchers:
              6 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.