许多oracle的优化规则 在mysql失效--探讨优化
许多oracle的优化规则 在mysql失效--探讨优化比如
select * from Outcome_history where eventId not in (select id from Event_history)
我执行得到结果时间为 0.267s
如果按照常规数据库优化 必须将not in换成not exist
select * from Outcome_historywherenot EXISTS(select id from Event_history where Event_history.id=Outcome_history.eventId)
0.266s (有时会是0.297,这是第1次执行的时间,后来的因为缓存就快了)
再换
select * from Outcome_historya wherenot EXISTS(select b.id from Event_history b where b.id=a.eventId)
0.281s(为什么mysql加上别名会慢上很多 ,很奇特的现象 ?? 这2个表都很大,第1表17万,第2条10万条)
如果是这样,exists存在就是为了走索引,没有索引他不会加快速度,在mysql确实跟其他数据库有点不同 。欢迎跟帖讨论。
有兴趣我再贴企业级优化例子 谢谢
页:
[1]