Author: skate
Time: 2010/10/19
Insert Optimization
To increase the insert speed, you must first know what affects the slow insert and generate redo and undo during insert execution. To increase the insert speed, when fully utilizing system resources, we should minimize the redo and undo generated by insert. The size of Undo cannot be changed, but we can change the redo volume. The following describes how to improve the insert method.
1. Add hint/* + append */-- you do not need to search for the insert-able space under the high water level, and insert directly above the high water level
2. Add hint/* + parallel (tab, 4 )*/
Or alter session enable/disable parallel DML;
--- Make full use of system hardware resources
3. alter table tablename nologging/Logging
---- Disable the table Log service to reduce redo generation.
4. If the business permits, you can delete the index first and then re-create the index after insert. --- reduce the indexing overhead during insert.
5. You can add a temporary intermediate table.
---- Reduce the use of Undo for this transaction
6. Increase sort_area_size or PGA
---- Increase the sorting space to avoid disk operations
7. Optimize the SQL statement itself
8. PL/SQL batch processing --- convert large transactions into scattered small transactions
Tb: tb_order_detail_his: records
Tb_order_detail: 2000w record
Before optimization:
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
)
During data archiving, the insert statement requires a large amount of data. If the insert statement contains less content, the insert statement can still be used. However, if you want to archive more than 2 million of the data, it will fail for two hours,
Therefore, we optimized the transformation and used the append, parallel, batch processing, and nologging methods to archive the million data in 15 minutes.
After optimization:
Use Mod (TCC. ID, 10) to archive the content in 10 parts
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 -----