Bug #84720 WITH ROLLUP not providing expected NULL values

Submitted: 30 Jan 2017 12:09 Modified: 30 Jan 2017 12:42
Reporter: Simon Mudd Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.6.27,5.7, 5.7.17 OS:Any
Assigned to: CPU Architecture:Any
Tags: rollup

[30 Jan 2017 12:09] Simon Mudd
Description:
WITH ROLLUP is not providing the expected NULL column. See test case below.

How to repeat:
CREATE TABLE `rollup_enum_bug` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tablename` varchar(60) NOT NULL,
  `action` enum('INSERT','UPDATE','DELETE') NOT NULL,
  `at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC COMMENT='test';

INSERT INTO rollup_enum_bug (tablename, action) VALUES ("foo", "INSERT"),("foo","UPDATE"),("bar","INSERT"),("bar","UPDATE");
INSERT INTO rollup_enum_bug (tablename, action) SELECT tablename, action FROM rollup_enum_bug;
INSERT INTO rollup_enum_bug (tablename, action) SELECT tablename, action FROM rollup_enum_bug;

SELECT CONCAT(LEFT(`at`,15),'0') AS _ymd_HM, action, tablename, COUNT(*) FROM rollup_enum_bug GROUP BY 1,0+action,3 WITH ROLLUP;

+------------------+--------+-----------+----------+
| _ymd_HM          | action | tablename | COUNT(*) |
+------------------+--------+-----------+----------+
| 2017-01-30 12:50 | INSERT | bar       |        4 |
| 2017-01-30 12:50 | INSERT | foo       |        4 |
| 2017-01-30 12:50 | INSERT | NULL      |        8 |
| 2017-01-30 12:50 | UPDATE | bar       |        4 |
| 2017-01-30 12:50 | UPDATE | foo       |        4 |
| 2017-01-30 12:50 | UPDATE | NULL      |        8 |
| 2017-01-30 12:50 | UPDATE | NULL      |       16 |
| NULL             | UPDATE | NULL      |       16 |
+------------------+--------+-----------+----------+
8 rows in set (0.00 sec)

The second column of the last row should be NULL.

Suggested fix:
Fix the result to match what is expected.
[30 Jan 2017 12:14] Simon Mudd
Correction: The second column of the last 2 rows should be NULL.
[30 Jan 2017 12:15] Simon Mudd
Adjust Synopsis
[30 Jan 2017 12:42] MySQL Verification Team
Hello Simon,

Thank you for the report and test case.

Thanks,
Umesh
[30 Jan 2017 13:04] Ruud H.G. van Tol
Found a non-enum test case:

SELECT tablename
, 10*((0+`at`) DIV 1000) AS _ymd_HM
, action
, COUNT(*) 
FROM rollup_enum_bug 
GROUP BY 1
,10.0*((0+`at`) DIV 1000),3 WITH ROLLUP;

The column-definition has '10', 
but the 'group by' definition has '10.0'.
[30 Jan 2017 13:13] Ruud H.G. van Tol
Same with the '0' and '0.0' in this one:

SELECT tablename, 0+`at` AS _at, COUNT(*) 
FROM rollup_enum_bug 
GROUP BY 1, 0.0+`at` WITH ROLLUP;

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.