Академический Документы
Профессиональный Документы
Культура Документы
Turbo-charge
PL/SQL Performance
with Bulk Processing Features
Steven Feuerstein
PL/SQL Evangelist, Quest Software
steven.feuerstein@quest.com
PL/SQL Obsession - www.ToadWorld.com/SF
Performance penalty
for many context
switches
Update... Update...
Update... Update...
Update... Update...
Update... Update...
Update... Update...
Update... Fewer context switches, Update...
same SQL behavior
Copyright 2000-2008 Steven Feuerstein - Page 6
Bulk Processing in PL/SQL
FORALL
Use with inserts, updates, deletes and merges.
Move data from collections to tables.
BULK COLLECT
Use with implicit and explicit queries.
Move data from tables into collections.
In both cases, the "back back" end processing in the
SQL engine is unchanged.
Same transaction and rollback segment management
Same number of individual SQL statements will be
executed.
But BEFORE and AFTER statement-level triggers only
fire once per FORALL INSERT statements.
similar.sql
Copyright 2000-2008 Steven Feuerstein - Page 9
BULK COLLECT for multi-row querying
DECLARE
/* Never can be more than 100 employees! */
Declare a VARRAY TYPE employees_aat IS VARRAY (100) OF
of records to hold employees%ROWTYPE;
the queried data.
l_employees employees_aat;
BEGIN
Fetch all rows into SELECT *
collection BULK COLLECT INTO l_employees bulkcoll.sql
sequentially, FROM employees; bulktiming.sql
starting with 1.
FOR indx IN 1 .. l_employees.COUNT
LOOP
Iterate through the process_employee (l_employees(indx));
END LOOP;
collection
END;
contents with a
loop. But what if I need to fetch and process
millions of rows?
This approach could consume unacceptable
amounts of memory.
Copyright 2000-2008 Steven Feuerstein - Page 11
Limiting retrieval with BULK COLLECT
LOOP
FETCH my_cursor BULK COLLECT INTO l_collection LIMIT 100;
EXIT WHEN my_cursor%NOTFOUND; BAD IDEA
bulkexc.sql
Copyright 2000-2008 Steven Feuerstein - Page 22
Converting old-fashioned code to bulk
forall_incr_commit.sql
Copyright 2000-2008 Steven Feuerstein - Page 24
Bulk Processing Conclusions