Direct path inserting
In this recipe we will see how to insert many rows in a table using a particular INSERT
statement to boost performance.
How to do it...
The following steps demonstrates multiple row insertions in the same INSERT
statement:
Connect to the
SH
schema:CONNECT sh@TESTDB/sh
Create an empty table
MY_SALES
with theSALES
table structure:CREATE TABLE MY_SALES AS SELECT * FROM SALES WHERE ROWNUM < 1;
Insert all the rows from
SALES
table in the newly-created table:SET TIMING ON INSERT INTO MY_SALES SELECT * FROM SALES; COMMIT; SET TIMING OFF
Empty the
MY_SALES
table:TRUNCATE TABLE MY_SALES;
Insert all of the rows from the
SALES
table in the newly-created table using direct path inserting:SET TIMING ON INSERT /*+ APPEND */ INTO MY_SALES SELECT * FROM SALES; COMMIT; SET TIMING OFF
Show the execution plan for classical
INSERT
statement:EXPLAIN PLAN FOR INSERT INTO MY_SALES SELECT * FROM SALES; SELECT * FROM TABLE( DBMS_XPLAN.DISPLAY(null,null,'TYPICAL -BYTES'));
Show the...