Mysql 当只更改WHERE子句值时,为什么查询运行速度要慢近100倍?
我有以下疑问:Mysql 当只更改WHERE子句值时,为什么查询运行速度要慢近100倍?,mysql,Mysql,我有以下疑问: SELECT count(m.p1_elo_one) FROM belgarath.match_result as m INNER JOIN belgarath.tournament AS tm ON tm.id_ = m.tournament_id INNER JOIN belgarath.tour AS tr ON tr.id_ = tm.tour_id INNER JOIN belgarath.rank AS rk ON rk.id_ = tm.rank_id INNER
SELECT count(m.p1_elo_one)
FROM belgarath.match_result as m
INNER JOIN belgarath.tournament AS tm ON tm.id_ = m.tournament_id
INNER JOIN belgarath.tour AS tr ON tr.id_ = tm.tour_id
INNER JOIN belgarath.rank AS rk ON rk.id_ = tm.rank_id
INNER JOIN belgarath.round AS rd ON rd.id_ = m.round_id
INNER JOIN belgarath.parameters_match AS pm
ON pm.tour_id = tm.tour_id
AND pm.rank_id = tm.rank_id
AND pm.round_id = m.round_id
INNER JOIN belgarath.surf ON belgarath.surf.id_ = tm.surf
INNER JOIN belgarath.player AS p ON p.id_ = m.p1_id
WHERE
belgarath.surf.surf_std_id = 1
AND pm.engineer = 1
AND m.date_time_inferred < "2003-06-01"
AND m.date_time_inferred > "2000-06-01"
AND m.p1_elo_one IS NOT NULL
AND p.name_ NOT LIKE "%/%"
解释
查询:
是否有任何或所有WHERE子句列被索引?请注意,rank现在是一个保留字,这使得它作为表/列标识符的选择很糟糕(令人惊讶的是,ROUND并没有保留)@GilbertLeBlanc-嘿。所有WHERE子句列都被编入索引,除了最后两列:
m.p1\u elo\u one
(Float)和p.name
(VARCHAR)@草莓-我已经停止了SHOW CREATE TABLE
,因为有太多的表和列。我想知道症状是否表明了一些明显的东西?我现在就把EXPLAIN
放上去-那对我来说是一个新的!感谢大家对排名的提醒
——我也注意到了……嗯,我要修改ix\u belgarath\u match\u date\u time\u推断
,包括p1\u elo\u one
——并在(巡演id,排名id,轮号,工程师
)的一些排列上粘贴一个索引。但也许其他人有更好的想法。
'CREATE TABLE `match_result` (
`id_` int NOT NULL AUTO_INCREMENT,
`date_time_op_scheduled` datetime DEFAULT NULL,
`date_time_op_actual` datetime DEFAULT NULL,
`date_time_oc_actual` datetime DEFAULT NULL,
`date_time_inferred` datetime DEFAULT NULL,
`tournament_id` int DEFAULT NULL,
`round_id` tinyint DEFAULT NULL,
`p1_id` int DEFAULT NULL,
`p2_id` int DEFAULT NULL,
`result` varchar(45) DEFAULT NULL,
`uncertainty` float DEFAULT NULL,
`uncertainty_bin` int DEFAULT NULL,
`p1_win_pred` float DEFAULT NULL,
`p1_win_SD` float DEFAULT NULL,
`url` varchar(255) DEFAULT NULL,
`winning_player` int DEFAULT NULL,
`completed_sets` int DEFAULT NULL,
`result_type_id` int DEFAULT NULL,
`p1_pinnacle_closing_odds` float DEFAULT NULL,
`p2_pinnacle_closing_odds` float DEFAULT NULL,
`post_match_data_retrieved` int DEFAULT NULL,
`p1_elo_all` float DEFAULT NULL,
`p1_elo_exc_ret_all` float DEFAULT NULL,
`p1_h2h_win_one_time` float DEFAULT NULL,
`p1_h2h_win_one_none` int DEFAULT NULL,
`p1_h2h_win_all_time_surf` float DEFAULT NULL,
`p1_h2h_win_all_surf` float DEFAULT NULL,
`p1_h2h_win_all_time` float DEFAULT NULL,
`p1_h2h_win_all_none` int DEFAULT NULL,
`p1_h2h_one_time` float DEFAULT NULL,
`p1_h2h_one_none` int DEFAULT NULL,
`p1_h2h_all_time_surf` float DEFAULT NULL,
`p1_h2h_all_surf` float DEFAULT NULL,
`p1_h2h_all_time` float DEFAULT NULL,
`p1_h2h_all_none` int DEFAULT NULL,
`p1_win_one_time` float DEFAULT NULL,
`p1_win_one_none` int DEFAULT NULL,
`p1_win_all_time_surf` float DEFAULT NULL,
`p1_win_all_surf` float DEFAULT NULL,
`p1_win_all_time` float DEFAULT NULL,
`p1_win_all_none` int DEFAULT NULL,
`p1_match_one_time` float DEFAULT NULL,
`p1_match_one_none` int DEFAULT NULL,
`p1_match_all_time_surf` float DEFAULT NULL,
`p1_match_all_surf` float DEFAULT NULL,
`p1_match_all_time` float DEFAULT NULL,
`p1_match_all_none` int DEFAULT NULL,
`p1_elo_one` float DEFAULT NULL,
`p1_elo_exc_ret_one` float DEFAULT NULL,
`p1_jet_lag` float DEFAULT NULL,
`p1_fatigue_short_term` int DEFAULT NULL,
`p1_fatigue_long_term` int DEFAULT NULL,
`p1_retired_last_match` tinyint DEFAULT NULL,
`p2_elo_all` float DEFAULT NULL,
`p2_elo_exc_ret_all` float DEFAULT NULL,
`p2_h2h_win_one_time` float DEFAULT NULL,
`p2_h2h_win_one_none` int DEFAULT NULL,
`p2_h2h_win_all_time_surf` float DEFAULT NULL,
`p2_h2h_win_all_surf` float DEFAULT NULL,
`p2_h2h_win_all_time` float DEFAULT NULL,
`p2_h2h_win_all_none` int DEFAULT NULL,
`p2_h2h_one_time` float DEFAULT NULL,
`p2_h2h_one_none` int DEFAULT NULL,
`p2_h2h_all_time_surf` float DEFAULT NULL,
`p2_h2h_all_surf` float DEFAULT NULL,
`p2_h2h_all_time` float DEFAULT NULL,
`p2_h2h_all_none` int DEFAULT NULL,
`p2_win_one_time` float DEFAULT NULL,
`p2_win_one_none` int DEFAULT NULL,
`p2_win_all_time_surf` float DEFAULT NULL,
`p2_win_all_surf` float DEFAULT NULL,
`p2_win_all_time` float DEFAULT NULL,
`p2_win_all_none` int DEFAULT NULL,
`p2_match_one_time` float DEFAULT NULL,
`p2_match_one_none` int DEFAULT NULL,
`p2_match_all_time_surf` float DEFAULT NULL,
`p2_match_all_surf` float DEFAULT NULL,
`p2_match_all_time` float DEFAULT NULL,
`p2_match_all_none` int DEFAULT NULL,
`p2_elo_one` float DEFAULT NULL,
`p2_elo_exc_ret_one` float DEFAULT NULL,
`p2_jet_lag` float DEFAULT NULL,
`p2_fatigue_short_term` int DEFAULT NULL,
`p2_fatigue_long_term` int DEFAULT NULL,
`p2_retired_last_match` tinyint DEFAULT NULL,
`engineered` tinyint DEFAULT NULL,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id_`),
KEY `ix_belgarath_match__completed_sets` (`completed_sets`),
KEY `ix_belgarath_match__post_match_data_retrieved` (`post_match_data_retrieved`),
KEY `ix_belgarath_match__date_time_oc_actual` (`date_time_oc_actual`),
KEY `ix_belgarath_match__tournament_id` (`tournament_id`),
KEY `ix_belgarath_match__round_id` (`round_id`),
KEY `ix_belgarath_match__player_id_2` (`p2_id`),
KEY `ix_belgarath_match__winning_player` (`winning_player`),
KEY `ix_belgarath_match__result_type_id` (`result_type_id`),
KEY `ix_belgarath_match__uncertainty_bin` (`uncertainty_bin`),
KEY `ix_belgarath_match__date_time_inferred` (`date_time_inferred`),
KEY `ix_belgarath_match__date_time_op_actual` (`date_time_op_actual`),
KEY `ix_belgarath_match__player_id_1` (`p1_id`),
KEY `ix_belgarath_match__date_time_op_scheduled` (`date_time_op_scheduled`) /*!80000 INVISIBLE */,
KEY `ix_belgarath_match__engineered` (`engineered`),
CONSTRAINT `match_result__player_1` FOREIGN KEY (`p1_id`) REFERENCES `player` (`id_`),
CONSTRAINT `match_result__player_2` FOREIGN KEY (`p2_id`) REFERENCES `player` (`id_`),
CONSTRAINT `match_result__round` FOREIGN KEY (`round_id`) REFERENCES `round` (`id_`),
CONSTRAINT `match_result__tournament` FOREIGN KEY (`tournament_id`) REFERENCES `tournament` (`id_`)
) ENGINE=InnoDB AUTO_INCREMENT=1408022 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci'