数据库优化

--创建跟emp表一模一样的表
create table emp2 as select * from emp;
--在新建的表中添加emp中的数据
--insert into emp2 select count(*) from emp2;
--表大小 1TB=1024GB 1GB=1024MB 1MB=1024KB 1KB=1024B (字节) 1B=8字节
select segment_name 名称,bytes/1024/1024 大小 from user_segments where segment_name='EMP2';

1.where和order by 建立索引

2.避免在where子句中进行null值判断

3.避免在where子句中使用!=或<>操作符

4.避免在where子句中使用or 可以采用
select id from t where num = 10 union allselect id from t where Name = 'admin'

5.in 和 not in慎用

6.连续的值使用between就不要用in

7.很多时候exits代替in
select num from a where exists(select 1 from b where num=a.num)

8.模糊建议右左模糊

9.避免在where子句中对字段进行表达式操作

10.避免在where子句中对字段进行函数操作

11.遇到大处理 需要将其数据拆分
使用 LIMIT Oracle(rownum),sqlserver(top)条件是一个好的方法

 

posted @ 2018-11-22 11:17  言西早石头侠  阅读(133)  评论(0编辑  收藏  举报