Reputation: 1
After i upgraded from mysql5.7 to mysql8, the query performance of the following SQL statement decreased significantly.
After explaining, there are a few index keys on mysql5.7 is different from mysql8.Is there any sql_mode to index keys of mysql8 similar to mysql5.7?
This is mysql:
EXPLAIN SELECT * FROM `contract_status`
INNER JOIN `contract_status_subclass` ON `contract_status_subclass`.`id` = `contract_status`.`contract_status_subclass_id` AND contract_status_subclass.disable = 0
INNER JOIN `contract_status_class` ON `contract_status_class`.`id` = `contract_status_subclass`.`contract_status_class_id` AND contract_status_class.disable = 0
WHERE contract_status.disable =0
This is information on mysql 5.7
CREATE TABLE `contract_status` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`contract_status_subclass_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`column_name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(128) NOT NULL DEFAULT '',
`sequence` smallint(5) unsigned NOT NULL DEFAULT '0',
`lastup_account_id` int(10) unsigned NOT NULL DEFAULT '0',
`create_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastup_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`disable` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `column_name` (`column_name`)
) ENGINE=InnoDB AUTO_INCREMENT=145 DEFAULT CHARSET=utf8
CREATE TABLE `contract_status_subclass` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`contract_status_class_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`column_name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(128) NOT NULL DEFAULT '',
`sequence` smallint(5) unsigned NOT NULL DEFAULT '0',
`lastup_account_id` int(10) unsigned NOT NULL DEFAULT '0',
`create_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastup_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`disable` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `column_name` (`column_name`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8
CREATE TABLE `contract_status_class` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`column_name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(128) NOT NULL DEFAULT '',
`sequence` smallint(5) unsigned NOT NULL DEFAULT '0',
`lastup_account_id` int(10) unsigned NOT NULL DEFAULT '0',
`create_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastup_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`disable` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `column_name` (`column_name`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
---|---|---|---|---|---|---|---|---|---|
1 | SIMPLE | contract_status | ALL | NULL | NULL | NULL | NULL | 126 | Using where |
1 | SIMPLE | contract_status_subclass | eq_ref | PRIMARY | PRIMARY | 2 | contract_status.contract_status_subclass_id | 1 | Using where |
1 | SIMPLE | contract_status_class | ALL | PRIMARY | NULL | NULL | NULL | 3 | Using where; Using join buffer (Block Nested Loop) |
This is information on mysql8.0.34
CREATE TABLE `contract_status` (
`id` smallint unsigned NOT NULL AUTO_INCREMENT,
`contract_status_subclass_id` smallint unsigned NOT NULL DEFAULT '0',
`column_name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(128) NOT NULL DEFAULT '',
`sequence` smallint unsigned NOT NULL DEFAULT '0',
`lastup_account_id` int unsigned NOT NULL DEFAULT '0',
`create_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastup_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`disable` tinyint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `column_name` (`column_name`)
) ENGINE=InnoDB AUTO_INCREMENT=152 DEFAULT CHARSET=utf8mb3
CREATE TABLE `contract_status_subclass` (
`id` smallint unsigned NOT NULL AUTO_INCREMENT,
`contract_status_class_id` smallint unsigned NOT NULL DEFAULT '0',
`column_name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(128) NOT NULL DEFAULT '',
`sequence` smallint unsigned NOT NULL DEFAULT '0',
`lastup_account_id` int unsigned NOT NULL DEFAULT '0',
`create_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastup_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`disable` tinyint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `column_name` (`column_name`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb3
CREATE TABLE `contract_status_class` (
`id` smallint unsigned NOT NULL AUTO_INCREMENT,
`column_name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(128) NOT NULL DEFAULT '',
`sequence` smallint unsigned NOT NULL DEFAULT '0',
`lastup_account_id` int unsigned NOT NULL DEFAULT '0',
`create_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastup_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`disable` tinyint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `column_name` (`column_name`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3
id | select_type | table | partitions | key | possible_keys | key | key_len | ref | rows | filtered | Extra |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | SIMPLE | contract_status_class | NULL | ALL | PRIMARY | NULL | NULL | NULL | 3 | 33.33 | Using where |
1 | SIMPLE | contract_status_subclass | NULL | ALL | PRIMARY | NULL | NULL | NULL | 21 | 4.76 | Using where; Using join buffer (hash join) |
1 | SIMPLE | contract_status | NULL | ALL | NULL | NULL | NULL | NULL | 141 | 1.00 | Using where; Using join buffer (hash join) |
Upvotes: 0
Views: 83