Mysql查看优化后的SQL语句EXPLAIN EXTENDED
1先执⾏ EXPLAIN EXTENDED
2 show warnings;
EXPLAIN EXTENDED
SELECT
*
FROM
`Test1` d
WHERE d.`ap_id` IN
(SELECT
id
FROM
ap
WHERE ap_code IN (
'Test120190305192721001',
'Test120190309152839001',
'Test120190309152904001'
));
SHOW WARNINGS;
查看优化后最终执⾏的sql
In 并不是⾛的⼦查询⽽是 join ,这个是从上⾯的画红线的地⽅copy 出来的
SELECT
`id` AS `id`,
`ap_id` AS `ap_id`,
`re_id` AS `re_id`,
`update_time` AS `update_time`,
`create_time` AS `create_time`,
`deleted` AS `deleted`
FROM
`ap`
JOIN`Test1` `d`
WHERE (
(
`ap_id` =`ap`.`id`
)
AND (
数据库优化sql语句`ap`.`ap_code` IN (
'Test120190305192721001',
'Test120190309152839001',
'Test120190309152904001'
)
)
)
EXPLAIN EXTENDED
SELECT
d.*
FROM
`Test1` d
INNER JOIN ap a
ON d.`ap_id` = a.id
WHERE a.ap_code IN (
'Test120190305192721001',
'Test120190309152839001',
'Test120190309152904001'
);
查看优化后的sql
SELECT
`id` AS `id`,
`ap_id` AS `ap_id`,
`re_id` AS `re_id`,
`update_time` AS `update_time`,
`create_time` AS `create_time`,
`deleted` AS `deleted`
FROM
`Test1` `d`
JOIN`ap` `a`
WHERE (
(
`ap_id` =`a`.`id`
)
AND (
`a`.`ap_code` IN (
'Test120190305192721001',
'Test120190309152839001',
'Test120190309152904001' )
)
)
;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论