High Performance PLSQL VTS PDF
High Performance PLSQL VTS PDF
Performance
PL/SQL
Steven
Feuerstein
Architect
Oracle
CorporaGon
February
2015
All
referenced
code
is
available
in
my
demo.zip
le
from
the
PL/SQL
Learning
Library:
oracle.com/oll/plsql.
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
Large Pool
Session 1
emp_rec emp%rowtype;
tot_tab pkg.tottabtype;
Session
1
memory
UGA
User
Global
Area
PGA
Process
Global
Area
Library
cache
Shared
SQL
Pre-parsed
calc_totals
Select *
from emp
Update emp
Set sal=...
show_emps
upd_salaries
emp_rec emp%rowtype;
tot_tab pkg.tottabtype;
Session
2
memory
UGA
User
Global
Area
PGA
Process
Global
Area
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
Session 2
DeterminisGc
funcGons
Under
some
circumstances,
can
avoid
execuGon
of
funcGon
with
matching
inputs
sf_timer.*
11g_emplu.pkg
11g_emplu_test.sql
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
11g_frc_vpd.sql
11g_frc_vpd2.sql
show_frc_dependencies.sp
The
funcGon
result
cache
oers
the
most
declaraGve,
widest
impact
caching
technique
available
to
PL/SQL
developers.
Oracle server
SQL Engine
PL/SQL block
Procedural
statement
executor
SQL
statement
executor
Performance penalty
for many context
switches
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
Oracle server
SQL Engine
PL/SQL block
FORALL indx IN
list_of_emps.FIRST..
list_of_emps.LAST
UPDATE employee
SET salary = ...
WHERE employee_id =
list_of_emps(indx);
Update...
Update...
Update...
Update...
Update...
Update...
Procedural
statement
executor
SQL
statement
executor
Update...
Update...
Update...
Update...
Update...
Update...
The
bulk
processing
features
of
PL/SQL
change
the
way
the
PL/SQL
engine
communicates
with
the
SQL
layer.
For
both
FORALL
and
BULK
COLLECT,
the
processing
in
the
SQL
engine
is
almost
completely
unchanged.
Same
transacGon
and
rollback
segment
management
Same
number
of
individual
SQL
statements
will
be
executed.
Retrieve
mulGple
rows
into
a
collecGon
with
a
single
fetch
(context
switch
to
the
SQL
engine).
Deposit
the
mulGple
rows
of
data
into
one
or
more
collec+ons.
NO_DATA_FOUND
is
not
raised
when
no
rows
are
fetched;
instead,
the
collecGon
is
empty.
The
"INTO"
collecGons
are
lled
sequenGally
from
index
value
1.
There
are
no
"gaps"
between
1
and
the
index
value
returned
by
the
COUNT
method.
DECLARE
TYPE employees_aat IS TABLE OF
employees%ROWTYPE;
l_employees employees_aat;
BEGIN
SELECT *
BULK COLLECT INTO l_employees
FROM employees;
FOR indx IN 1 .. l_employees.COUNT
LOOP
process_employee (l_employees(indx));
END LOOP;
END;
bulkcoll.sql
bulkcollect.tst
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
If
you
do
not
know
in
advance
how
many
rows
you
might
retrieve,
you
should:
1.
Declare
an
explicit
cursor.
2.
Fetch
BULK
COLLECT
with
the
LIMIT
clause.
bulklimit.sql
Explicit
BULK
COLLECTs
will
usually
run
a
li6le
faster
than
cursor
for
loops
opGmized
to
BC.
10g_optimize_cfl.sql
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
bulkGming.sql
RelaGonal
Table
Phase
3:
FORALL
from
collecGon
to
table
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
c_to_bulk_0.sql
c_to_bulk_5.sql
nocopy*.*
string_nocopy.*
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
UDF
pragma
declaraGvely
tells
the
compiler
to
"prepare"
the
funcGon
for
execuGon
from
SQL.
Reduces
the
cost
of
the
context
switch
12c_with_funcGon*.sql
12c_udf*.sql
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
Q+A
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
31
educa8on.oracle.com
Copyright
2014
Oracle
and/or
its
aliates.
All
rights
reserved.
|
32
33
34
35