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

LP:844997 - Wrong query result with SELECT const_table_column, aggregate_func, implict grouping and empty resultset

    Details

    • Type: Bug
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 5.1.67, 5.2.14, 5.3.12, 5.5.36, 10.0.9
    • Fix Version/s: 10.0, 5.5
    • Component/s: None

      Description

      Consider the below: it shows how changing const table to non-const will change the resultset. This is a bug.

      create table t11 (a int primary key, b int);
      insert into t11 values (1,1),(2,2);
      
      create table t10 (a int, b int, c int);
      insert into t10 values (10, NULL, NULL), (10, NULL, NULL);
      
      MariaDB [j12]> explain select t11.b, max(t10.b) from t10, t11 where t10.c<1 and t11.a=2;
      +----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
      | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
      +----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
      | 1 | SIMPLE | t11 | const | PRIMARY | PRIMARY | 4 | const | 1 | |
      | 1 | SIMPLE | t10 | ALL | NULL | NULL | NULL | NULL | 2 | Using where |
      +----+-------------+-------+-------+---------------+---------+---------+-------+------+-------------+
      2 rows in set (2.63 sec)
      
      MariaDB [j12]> select t11.b, max(t10.b) from t10, t11 where t10.c<1 and t11.a=2;
      +------+------------+
      | b | max(t10.b) |
      +------+------------+
      | 2 | NULL |
      +------+------------+
      1 row in set (3.31 sec)
      
      MariaDB [j12]> alter table t11 drop primary key;
      Query OK, 2 rows affected (0.01 sec)
      Records: 2 Duplicates: 0 Warnings: 0
      
      MariaDB [j12]> select t11.b, max(t10.b) from t10, t11 where t10.c<1 and t11.a=2;
      +------+------------+
      | b | max(t10.b) |
      +------+------------+
      | NULL | NULL |
      +------+------------+
      1 row in set (3.66 sec)
      

      The bug can be repeated on current mysql-5.1

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            psergey Sergei Petrunia added a comment -

            Re: Wrong query result with SELECT const_table_column, aggregate_func, implict grouping and empty resultset
            This problem was branched off bug# 613029

            Show
            psergey Sergei Petrunia added a comment - Re: Wrong query result with SELECT const_table_column, aggregate_func, implict grouping and empty resultset This problem was branched off bug# 613029
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 844997

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 844997
            Hide
            elenst Elena Stepanova added a comment -

            Reproducible on MySQL 5.1-5.7.

            Show
            elenst Elena Stepanova added a comment - Reproducible on MySQL 5.1-5.7.

              People

              • Assignee:
                Unassigned
                Reporter:
                psergey Sergei Petrunia
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: