MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 2325|回复: 0
打印 上一主题 下一主题

如何对以下多表查询的优化

[复制链接]
跳转到指定楼层
1#
发表于 2013-3-14 13:52:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. select count(*)
  2. from tbl_alarmlog a
  3. where ((a.dev_type=75)
  4. or ((select id from tbl_userdev where a.dev_id=dev_id and a.dev_type=dev_type and user_id=4) is not null)
  5. or (a.dev_type=4 and (select id from tbl_userdev where dev_type=9 and user_id=4 and dev_id in (select a_id from tbl_point where id=a.dev_id)) is not null)
  6. or (a.dev_type=7 and a.serverid=0 and (select id from tbl_patroluser where a.dev_id=ep_id and userid=4 or userid in (select id from tbl_user where creater_id=4)) is not null)
  7. or (a.dev_type=7 and a.serverid<>0)
  8. or ((a.dev_type=1 or a.dev_type=128) and (select id from tbl_userdev where user_id=4 and dev_type=64 and dev_no=a.puid and dev_id=a.channel) is not null))
  9. and a.alarm_time>=FROM_UNIXTIME(1330531200) and a.alarm_time<FROM_UNIXTIME(1363190399) and a.serverid=0
复制代码
请问如何把上述的or语句改成and,貌似说查询子句中or语句会导致全表搜索。
或者说如何优化上述语句,哪些地方要加索引,哪些语句可以优化的?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 分享淘帖 顶 踩
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-6-16 10:57 , Processed in 0.085891 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表