我是靠谱客的博主 现代水杯,这篇文章主要介绍inner join的时候加上force,从26秒提升到3秒,why ?,现在分享给大家,希望可以做个参考。

cdp.listed_cpny_fin_rpt_prd表总记录数:1467246
test.qa_cpny表总记录数:103


explain SELECT dat.*
FROM test.qa_cpny es force index(PRIMARY)
inner join cdp.listed_cpny_fin_rpt_prd dat
on (es.excel_id = dat.excel_id)
;

explainSELECT dat.*
FROM test.qa_cpny es
inner join cdp.listed_cpny_fin_rpt_prd dat
on (es.excel_id = dat.excel_id)
;
explain结果都是一样的如下:
'1', 'SIMPLE', 'listed_cpny_fin_rpt_prd', 'ALL', 'PRIMARY', NULL, NULL, NULL, '1056426', ''
'1', 'SIMPLE', 'es', 'eq_ref', 'PRIMARY', 'PRIMARY', '4', 'func', '1', 'Using where; Using index'

看explain结果,走的都是primary主键索引,可是接下来执行建表语句:
drop table if exists test_cpny.listed_cpny_fin_rpt_prd;
create table test_cpny.listed_cpny_fin_rpt_prd
SELECT dat.*
FROM test.qa_cpny es
inner join cdp.listed_cpny_fin_rpt_prd dat
on (es.excel_id = dat.excel_id)
;
60960 row(s) affected
Records: 60960Duplicates: 0Warnings: 0
25.797sec
不加force动作,是25.797sec

drop table if exists test_cpny.listed_cpny_fin_rpt_prd;
create table test_cpny.listed_cpny_fin_rpt_prd
SELECT dat.*
FROM test.qa_cpny es force index(PRIMARY)
inner join cdp.listed_cpny_fin_rpt_prd dat
on (es.excel_id = dat.excel_id)
;
60960 row(s) affected
Records: 60960Duplicates: 0Warnings: 0
2.765sec
加了force动作,是2.765sec

看来有的时候mysql的explain也不是尽善尽美的啊,大家讨论下这个现象的深层次原因吧!

最后

以上就是现代水杯最近收集整理的关于inner join的时候加上force,从26秒提升到3秒,why ?的全部内容,更多相关inner内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部