黑马程序员技术交流社区

标题: 在千万级的数据库查询中,如何提高效率之SQL 语句方面 [打印本页]

作者: 小白进阶之路    时间: 2018-4-18 13:25
标题: 在千万级的数据库查询中,如何提高效率之SQL 语句方面
a. 应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描。
b. 应尽量避免在 where 子句中使用 or 来连接条件,否则将导致引擎放弃使用索引而进行全表扫描,如:
select id from t where num=10 or num=20 可以这样查询: select id from t where num=10 union all
select id from t where num=20
c. in 和 not in 也要慎用,否则会导致全表扫描,如: select id from t where num in(1,2,3) 对于连续的
数值,能用 between 就不要用 in 了: select id from t where num between 1 and 3
作者: 小白进阶之路    时间: 2018-4-19 10:08
占座00000000000000
作者: 小白进阶之路    时间: 2019-5-5 09:56
1111111111111111111111111
作者: 小白进阶之路    时间: 2019-5-7 11:33
22222222222222222222




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2