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

Wrong result for query with window function when all tables are optimized away

Details

    Description

      For the following table

      create table t1 (id int);
      insert into t1 values (1), (2), (3), (2);
      

      the query

      select sum(max(id)) over (order by max(id)) from t1;
      

      returns the correct result:

      MariaDB [test]> select sum(max(id)) over (order by max(id)) from t1;
      +--------------------------------------+
      | sum(max(id)) over (order by max(id)) |
      +--------------------------------------+
      | 3                                    |
      +--------------------------------------+
      

      However after creation of an index on t1(id) the same query returns a wrong result:

       
      MariaDB [test]> create index idx on t1(id);
      Query OK, 0 rows affected (0.05 sec)
      Records: 0  Duplicates: 0  Warnings: 0
       
      MariaDB [test]> select sum(max(id)) over (order by max(id)) from t1;
      +--------------------------------------+
      | sum(max(id)) over (order by max(id)) |
      +--------------------------------------+
      | NULL                                 |
      +--------------------------------------+
      

      Attachments

        Issue Links

          Activity

            igor Igor Babaev (Inactive) created issue -
            igor Igor Babaev (Inactive) made changes -
            Field Original Value New Value
            Component/s Optimizer - Window functions [ 13502 ]
            Affects Version/s 10.2.3 [ 22115 ]
            Description For the following table
            {noformat}
            create table t1 (id int);
            insert into t1 values (1), (2), (3), (2);
            {noformat}
            the query
            {noformat}
            select sum(max(id)) over (order by max(id)) from t1;
            {noformat}
            returns the correct result:
            {noformat}
            MariaDB [test]> select sum(max(id)) over (order by max(id)) from t1;
            +--------------------------------------+
            | sum(max(id)) over (order by max(id)) |
            +--------------------------------------+
            | 3 |
            +--------------------------------------+
            {noformat}
            However after creation of an index on t1(id) the same query returns a wrong result:
            {noformat}
             
            MariaDB [test]> create index idx on t1(id);
            Query OK, 0 rows affected (0.05 sec)
            Records: 0 Duplicates: 0 Warnings: 0

            MariaDB [test]> select sum(max(id)) over (order by max(id)) from t1;
            +--------------------------------------+
            | sum(max(id)) over (order by max(id)) |
            +--------------------------------------+
            | NULL |
            +--------------------------------------+
            {noformat}

            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ]
            igor Igor Babaev (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            igor Igor Babaev (Inactive) made changes -
            Summary Wrong result for query with window function when all tables are optimized away t
            igor Igor Babaev (Inactive) made changes -
            Summary t Wrong result for query with window function when all tables are optimized away
            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Vicentiu Ciorbaru [ cvicentiu ]
            Status In Progress [ 3 ] In Review [ 10002 ]

            Ok to push.

            cvicentiu Vicențiu Ciorbaru added a comment - Ok to push.
            cvicentiu Vicențiu Ciorbaru made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            cvicentiu Vicențiu Ciorbaru made changes -
            Assignee Vicentiu Ciorbaru [ cvicentiu ] Igor Babaev [ igor ]

            The fix for this bug was pushed into the 10.2 tree.

            igor Igor Babaev (Inactive) added a comment - The fix for this bug was pushed into the 10.2 tree.
            igor Igor Babaev (Inactive) made changes -
            Fix Version/s 10.2.6 [ 22527 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            elenst Elena Stepanova made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 79512 ] MariaDB v4 [ 151662 ]

            People

              igor Igor Babaev (Inactive)
              igor Igor Babaev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.