-- 使用普通方式创建默认临时表方法 create temporary table atest(select id ,pid ,sid from tb_parent_student); create temporary table btest(select pid ,sid from tb_child join tb_parent on pid=pid); select *From atest; select *From btest; -- Exists 比较两个结果集的差异信息 select *From atest where not Exists (select *From btest where atest.pid=btest.pid and atest.sid=btest.sid); select *From btest where not Exists (select *from atest where atest.pid=btest.pid and atest.sid=btest.sid); -- left join select *From atest m left join btest as a on m.pid=a.pid and m.sid=a.sid; select *From atest m left join btest as a on m.pid=a.pid and m.sid=a.sid;
其中:atest 和btest 两个临时表格的数据都有近二十万数据。
使用普通方式创建默认临时表执行比较结果集语句耗时(其实还没执行完我受不了了直接断开了,后来实际测试大致执行了38分钟!):

使用内存级别加索引方式穿件临时表执行比较结果耗时:

知道优化后查询会快很多,但是没想到能快这么多。
Mysql 使用临时表比较数据差异以及 临时表的优化
标签:auto mamicode 表格 color 查询 HERE har class and