[MDEV-768] LP:844997 - Wrong query result with SELECT const_table_column, aggregate_func, implict grouping and empty resultset Created: 2011-09-08  Updated: 2022-11-29

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 5.1.67, 5.2.14, 5.3.12, 5.5.36, 10.0.9, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 5.5, 10.3

Type: Bug Priority: Trivial
Reporter: Sergei Petrunia Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: 11.0-sel, Launchpad, upstream

Attachments: XML File LPexportBug844997.xml    

 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



 Comments   
Comment by Sergei Petrunia [ 2011-09-08 ]

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

Comment by Rasmus Johansson (Inactive) [ 2012-03-22 ]

Launchpad bug id: 844997

Comment by Elena Stepanova [ 2014-03-26 ]

Reproducible on MySQL 5.1-5.7.

Generated at Thu Feb 08 06:31:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.