Bug #101740 mysqldump and SHOW CREATE VIEW produce invalid syntax for VIEWs with ROLL UP
Submitted: 25 Nov 2020 0:44 Modified: 8 Dec 2020 15:14
Reporter: Jeff Van Boxtel Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S1 (Critical)
Version:8.0.22 OS:Any
Assigned to: CPU Architecture:Any

[25 Nov 2020 0:44] Jeff Van Boxtel
Description:
The SHOW CREATE VIEW command (and thus mysqldump) produces invalid syntax for VIEWS that were created with a ROLL UP clause. The VIEW query appears to have C function names like `rollup_sum_switcher` and `rollup_group_item` inserted into it.

Importantly, backups generated with mysqldump will not show an error but will fail when restored due to this bug. Failure may only be noticed later when a user attempts to access the view.

I've confirmed this bug on 8.0.21-0ubuntu0.20.04.4 for Linux on x86_64 but the bug is also reported to be an issue since > 18.0.18 on Mac see here: https://stackoverflow.com/questions/64985354/mysql-8-0-18-dump-restore-problems-with-views...

How to repeat:
DROP DATABASE IF EXISTS rollup_test;
CREATE DATABASE rollup_test;
USE rollup_test;

DROP TABLE IF EXISTS tmp_table_rollup;
CREATE TABLE tmp_table_rollup (
 id bigint(20) NOT NULL AUTO_INCREMENT,
 groupKey varchar(250)  DEFAULT NULL,
 groupValue varchar(250) DEFAULT NULL,
 PRIMARY KEY (id)
);

DROP VIEW IF EXISTS tmp_view_rollup;
CREATE VIEW tmp_view_rollup
  AS
    SELECT groupKey,
    COUNT(id) AS groupCount
    FROM tmp_table_rollup
    GROUP BY groupKey
    WITH ROLLUP;

SHOW CREATE VIEW tmp_view_rollup;

# Output is:
# CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `tmp_view_rollup` AS select rollup_group_item(`tmp_table_rollup`.`groupKey`,0) AS `groupKey`,rollup_sum_switcher(count(`tmp_table_rollup`.`id`)) AS `groupCount` from `tmp_table_rollup` group by `tmp_table_rollup`.`groupKey` with rollup

# Note the view definition contains C function names such as `rollup_sum_switcher` and `rollup_group_item` instead of the proper ROLL UP query. This bug causes mysqldump to produce invalid backups.
[25 Nov 2020 2:19] MySQL Verification Team
Thank you for the bug report.
[8 Dec 2020 15:14] Paul DuBois
Posted by developer:
 
Fixed in 8.0.24.

SHOW CREATE VIEW produced invalid syntax for views created with a
ROLLUP clause. This issue also affected mysqldump, which uses SHOW
CREATE VIEW.