insert语句优化
来源:互联网 发布:播放器软件下载 编辑:程序博客网 时间:2024/05/29 09:16
author:skate
time:2010/10/19
insert优化
要想提高insert的速度,首先要知道什么影响insert慢,在执行insert的过程中产生redo和undo,要想提高insert的速度,在充分利用系统资源的条件下就要尽量减少insert产生的redo和undo,undo的大小没办法改变,但是我们可以改变redo的量。下面是提高insert方法。
1. 增加hint /*+ append */ --不用在高水位下查找可insert的空间,直接在高水位之上insert
2. 增加hint /*+ parallel(tab,4) */
或者alter session enable/disable parallel dml; ---充分利用系统硬件资源
3. alter table tablename nologging/logging ----关闭表的log服务,减少redo产生
4. 如果业务允许的话,可以先删除索引,insert之后再重建. ---减少在insert时维护索引的开销
5. 可以增加临时中间表 ----减少此事务对undo的使用
6. 增大sort_area_size或PGA ----增加排序空间,避免磁盘操作
7. 优化sql语句本身
8. pl/sql批处理 ---化整为零,把大事务变成零散的小事务
说明:tb_order_detail_his :7000W记录
tb_order_detail :2000W记录
优化前:
INSERT INTO /*+ append */ tablename_his
SELECT * FROM tablename PARTITION (TB_ORDER_DE_WAREID40) WHERE ID NOT IN (
SELECT tcc.id FROM tablename PARTITION (TB_ORDER_DE_WAREID40) tcc , tablename_his tcch WHERE tcc.id=tcch.id
)
在做数据归档时,需要做大数据量的insert,对于insert内容少还是可以胜任的,可当要把200多万的数据归档,2个小时都没有成功,
于是对其优化改造,利用append,parallel,分批处理,nologging方法,使这个200W的数据归档在15分钟就完成
优化后:
通过 mod(tcc.id,10)把内容分10部分提交归档
INSERT INTO /*+ append */ tablename_his
SELECT * FROM tablename PARTITION (TB_ORDER_DE_WAREID40) tcc WHERE NOT EXISTS (
SELECT /*+ parallel(tcch,7) parallel(tcc,7) */ tcch.id FROM tablename_his tcch WHERE tcc.id=tcch.id
) AND mod(tcc.id,10)=9
-----end-----
- insert语句优化
- Mysql insert语句的优化
- Mysql insert语句的优化
- Mysql insert语句的优化
- MySQL插入语句insert性能优化
- insert语句太长,有StringBuilder优化一下
- MySQL插入语句insert性能优化
- Mysql 中insert语句的性能优化
- MySQL插入语句insert性能优化
- MySQL插入语句insert性能优化
- MySQL插入语句insert性能优化
- MySQL插入语句insert性能优化
- MySQL插入语句insert性能优化
- MySQL插入语句insert性能优化
- MySQL插入语句insert性能优化
- insert语句
- insert语句
- insert语句
- 超级函数指针
- 那些排序算法
- [飞鸽传书]珍藏:OO五大原则
- 给激活了WS_HSCROLL,WS_VSCROLL的RichEdit增加自动换行的控制
- 常用的一些javascript小技巧
- insert语句优化
- 从程序员到asp.net架构师转变
- 测试用例基本格式
- 边沿检测(转)
- 用XmlDocument创建XML文档
- 如何读技术类书籍
- AHK 快餐店[11] 之 虚拟桌面 AutoHotkey 版
- DM9000A 的数据速率问题,强制为10M全双工操作,10Mbps,
- 如果.net2.0网站发布在net1.0下出现的问题解决办法