Bug #111813 mysqlshell upgrade checker checkTableOutput stage mark view Corrupt
Submitted: 19 Jul 2023 10:36 Modified: 5 Sep 2023 15:05
Reporter: Shujun Chen Email Updates:
Status: Closed Impact on me:
None 
Category:Shell Upgrade Checker Severity:S3 (Non-critical)
Version:8.0.32, 8.0.34 OS:CentOS (CentOS Linux release 7.5.1804 (Core))
Assigned to: CPU Architecture:x86 (Intel(R) Xeon(R) CPU E5-4620 v2 @ 2.60GHz)
Tags: checkTableOutput, mysqlshell, upgrade checker, VIEW

[19 Jul 2023 10:36] Shujun Chen
Description:
We are planning to upgrade mysql from 5.7.32 to 8.0.34. We have executed mysqlshell upgrader checker which are showing below 

mysqlsh -- util checkForServerUpgrade zhenxing@10.186.64.136:5732 --target-version=8.0.34  --output-format=JSON --config-path=/data/mysql/5732/my.cnf.5732
--- output
...
        {
            "id": "checkTableOutput",
            "title": "Issues reported by 'check table x for upgrade' command",
            "status": "OK",
            "detectedProblems": [
                {
                    "level": "Notice",
                    "dbObject": "demo.audit_view_account",
                    "description": "No database selected"
                },
                {
                    "level": "Error",
                    "dbObject": "demo.audit_view_account",
                    "description": "Corrupt"
                }
            ]
        },
...
---

By comparing the view definitions in the database, it is found that the difference between the Corrupt view and the normal view is that the from statement of the Corrupt view has a table_schema prefix definition, while the normal view does not have a table_schema prefix

-- Corrupt view definition
root@localhost[demo]> show create view audit_view_account\G
*************************** 1. row ***************************
                View: audit_view_account
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `audit_view_account` AS select `t`.`xAxis` AS `xAxis`,`t`.`total` AS `total`,`t`.`uk_type` AS `uk_type`,`t`.`operated_user_name` AS `operated_user_name`,`t`.`time` AS `time` from (select date_format(from_unixtime((`demo`.`platform_role`.`time` / 1000)),'%k') AS `xAxis`,count(1) AS `total`,'platform_role' AS `uk_type`,`demo`.`platform_role`.`operated_user_name` AS `operated_user_name`,`demo`.`platform_role`.`time` AS `time` from `demo`.`platform_role` group by `xAxis`,`uk_type`,`demo`.`platform_role`.`operated_user_name`,`demo`.`platform_role`.`time` union all select date_format(from_unixtime((`demo`.`dept`.`time` / 1000)),'%k') AS `xAxis`,count(1) AS `total`,'dept' AS `uk_type`,`demo`.`dept`.`operated_user_name` AS `operated_user_name`,`demo`.`dept`.`time` AS `time` from `demo`.`dept` group by `xAxis`,`uk_type`,`demo`.`dept`.`operated_user_name`,`demo`.`dept`.`time` union all select date_format(from_unixtime((`demo`.`audit_post`.`time` / 1000)),'%k') AS `xAxis`,count(1) AS `count(1)`,'post' AS `uk_type`,`demo`.`audit_post`.`operated_user_name` AS `operated_user_name`,`demo`.`audit_post`.`time` AS `time` from `demo`.`audit_post` group by `xAxis`,`uk_type`,`demo`.`audit_post`.`operated_user_name`,`demo`.`audit_post`.`time` union all select date_format(from_unixtime((`demo`.`pwd_change`.`time` / 1000)),'%k') AS `xAxis`,count(1) AS `total`,'pwd_change' AS `uk_type`,`demo`.`pwd_change`.`operated_user_name` AS `operated_user_name`,`demo`.`pwd_change`.`time` AS `time` from `demo`.`pwd_change` group by `xAxis`,`uk_type`,`demo`.`pwd_change`.`operated_user_name`,`demo`.`pwd_change`.`time` union all select date_format(from_unixtime((`demo`.`account_change`.`time` / 1000)),'%k') AS `xAxis`,count(1) AS `total`,'account' AS `uk_type`,`demo`.`account_change`.`operated_user_name` AS `operated_user_name`,`demo`.`account_change`.`time` AS `time` from `demo`.`account_change` group by `xAxis`,`uk_type`,`demo`.`account_change`.`operated_user_name`,`demo`.`account_change`.`time` union all select date_format(from_unixtime((`demo`.`user_info_change`.`time` / 1000)),'%k') AS `xAxis`,count(1) AS `total`,'user_info_change' AS `uk_type`,`demo`.`user_info_change`.`operated_user_name` AS `operated_user_name`,`demo`.`user_info_change`.`time` AS `time` from `demo`.`user_info_change` group by `xAxis`,`uk_type`,`demo`.`user_info_change`.`operated_user_name`,`demo`.`user_info_change`.`time` union all select date_format(from_unixtime((`demo`.`audit_app_change`.`time` / 1000)),'%k') AS `xAxis`,count(1) AS `total`,'app_change' AS `uk_type`,`demo`.`audit_app_change`.`operated_user_name` AS `operated_user_name`,`demo`.`audit_app_change`.`time` AS `time` from `demo`.`audit_app_change` group by `xAxis`,`uk_type`,`demo`.`audit_app_change`.`operated_user_name`,`demo`.`audit_app_change`.`time`) `t`
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci

-- normal view definition
root@localhost[demo]> show create view audit_view_history\G
*************************** 1. row ***************************
                View: audit_view_history
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `audit_view_history` AS select `login_record_history`.`auth_type` AS `auth_type`,`login_record_history`.`login_status` AS `login_status`,`login_record_history`.`device_type` AS `device_type`,`login_record_history`.`login_ip` AS `login_ip`,`login_record_history`.`city` AS `city`,date_format(`login_record_history`.`login_time`,'%e') AS `xAxis`,count(1) AS `yAxis`,`login_record_history`.`login_time` AS `login_time`,`login_record_history`.`username` AS `username` from `login_record_history` group by `xAxis`,`login_record_history`.`auth_type`,`login_record_history`.`login_status`,`login_record_history`.`device_type`,`login_record_history`.`login_ip`,`login_record_history`.`city`,`login_record_history`.`login_time`,`login_record_history`.`username`
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
1 row in set (0.00 sec)

How to repeat:

1. create database demo;
2. use demo
3. source demo.sql
4. mysqlsh -- util checkForServerUpgrade zhenxing@10.186.64.136:5732 --target-version=8.0.34  --output-format=JSON --config-path=/data/mysql/5732/my.cnf.5732

Suggested fix:
Fixed the logic of view detection
[19 Jul 2023 10:38] Shujun Chen
demo.sql

Attachment: demo.sql (application/octet-stream, text), 21.71 KiB.

[19 Jul 2023 10:39] Shujun Chen
checkForServerUpgrade output

Attachment: checkForServerUpgrade.log (application/octet-stream, text), 43.51 KiB.

[24 Jul 2023 10:12] MySQL Verification Team
Hello Shujun Chen,

Thank you for the report and feedback.
Observed no issues found if checked against 5.7.43(after following below steps) but seen on 5.7.32.

regards,
Umesh
[24 Jul 2023 10:12] MySQL Verification Team
test results

Attachment: 111813.results (application/octet-stream, text), 82.37 KiB.

[5 Sep 2023 15:05] Edward Gilmore
Posted by developer:
 
Added the following note to the MySQL Shell 8.0.35 and 8.2.0 release notes:
	
The MySQL Shell upgrade checker utility flagged views as corrupt in MySQL 5.7 versions up to 5.7.39. 
This issue occurred for views whose from clause contained a table.schema prefix with a group by clause.

Thank you for the bug report.