[MDEV-24247] EXPLAIN EXTENDED does not show condition in HAVING Created: 2020-11-18  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.4, 10.5

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: None


 Description   

create table t1 (a int);
insert into t1 values (1),(2),(1);
explain extended select a, count(*) c from t1 group by a having c < 2;
show warnings;
drop table t1;

10.2 c048053c

MariaDB [test]> explain extended select a, count(*) c from t1 group by a having c < 2;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+---------------------------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra                           |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+---------------------------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    3 |   100.00 | Using temporary; Using filesort |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+---------------------------------+
1 row in set, 1 warning (0.091 sec)
 
MariaDB [test]> show warnings;
+-------+------+--------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                          |
+-------+------+--------------------------------------------------------------------------------------------------+
| Note  | 1003 | select `test`.`t1`.`a` AS `a`,count(0) AS `c` from `test`.`t1` group by `test`.`t1`.`a` having 1 |
+-------+------+--------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

Note having 1 in the output above.

10.1 displays the condition:

10.1 da9081d1

MariaDB [test]> explain extended select a, count(*) c from t1 group by a having c < 2;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+---------------------------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra                           |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+---------------------------------+
|    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    3 |   100.00 | Using temporary; Using filesort |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+---------------------------------+
1 row in set, 1 warning (0.000 sec)
 
MariaDB [test]> show warnings;
+-------+------+----------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                  |
+-------+------+----------------------------------------------------------------------------------------------------------+
| Note  | 1003 | select `test`.`t1`.`a` AS `a`,count(0) AS `c` from `test`.`t1` group by `test`.`t1`.`a` having (`c` < 2) |
+-------+------+----------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

The difference appeared in very early 10.2 branch after this merge:

commit b532be9f8ce4872be4a3f1ef2fa296a1de347859 (HEAD)
Merge: a4c81986aad 0f62eee2f87
Author: Sergei Petrunia
Date:   Tue Apr 12 00:00:53 2016 +0200
 
    Merge ../10.2-window-funcs-r12 into 10.2



 Comments   
Comment by Igor Babaev [ 2020-12-06 ]

count(0) is a constant. If the value of this constant is less then 2 then 'having 1' in the explain output is OK.

Comment by Igor Babaev [ 2020-12-06 ]

count(0) is a constant. If the value of this constant is less then 2 then 'having 1' in the explain output is OK.

Generated at Thu Feb 08 09:28:32 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.