MySQL社区

标题: 许多oracle的优化规则 在mysql失效--探讨优化 [打印本页]

作者: liyihongcug    时间: 2009-6-12 14:37
标题: 许多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_history  where  not EXISTS  (select id from Event_history where Event_history.id=Outcome_history.eventId)
0.266s (有时会是0.297,这是第1次执行的时间,后来的因为缓存就快了)

再换
select * from Outcome_history  a where  not EXISTS  (select b.id from Event_history b where b.id=a.eventId)
0.281s  (为什么mysql加上别名会慢上很多 ,很奇特的现象 ?? 这2个表都很大,第1表17万,第2条10万条)


如果是这样,exists存在就是为了走索引,没有索引他不会加快速度,在mysql确实跟其他数据库有点不同 。欢迎跟帖讨论。
有兴趣我再贴企业级优化例子
作者: benshan    时间: 2012-8-2 12:18
谢谢




欢迎光临 MySQL社区 (http://www.mysqlpub.com/) Powered by Discuz! X3.2