Академический Документы
Профессиональный Документы
Культура Документы
Release 2!
SKILLBUILDERS
6.2
Agenda
Introduce several SQL-tuning related 10g
features
SQL
Tuning Advisor
SQL Profiles
SQL Access Advisor
Optimizer (CBO) enhancements
Hints
Statistics Gathering
PL/SQL Improvements
2005 SkillBuilders, Inc.
6.3
or stale statistics
Better paths
Restructuring
SQL
SQL
Profiles
6.4
STA Interfaces
10g Enterprise Manager
Easy GUI
Launch job with point and click
Implement recommendations with point and
click
Supplied package DBMS_SQLTUNE
R2 adds V$ADVISOR_PROGRESS
Monitor
STA progress
2005 SkillBuilders, Inc.
R2
6.5
Shared pool
Text
Multiple statements bound into SQL Tuning Set
Contains parsing schema and bind values
Contains execution count and average elapsed time
R2 supports export / import into another DB
R2
6.6
Running STA
Create tuning task
Display report
6.7
STA Demo
Create a tuning task
Execute the task
Invokes
cost-based optimizer
Privileges
Privilegesreqd:
reqd:ADVISOR,
ADVISOR,
SELECT_CATALOG_ROLE,
SELECT_CATALOG_ROLE,
EXECUTE
EXECUTEon
on
DBMS_SQLTUNE
DBMS_SQLTUNE
Source
SourceofofSQL
SQLcan
canbe
beADDM
ADDM
SYSTEM>
SYSTEM> declare
declare
22
task_id
task_id varchar2(30);
varchar2(30);
33 begin
begin
44
task_id
task_id :=
:= dbms_sqltune.create_tuning_task(
dbms_sqltune.create_tuning_task(
55
sql_text=>'update
sql_text=>'update dave.t
dave.t set
set c1
c1 == 6000',
6000',
66
task_name=>'test2');
task_name=>'test2');
77
88
dbms_sqltune.execute_tuning_task('test2');
dbms_sqltune.execute_tuning_task('test2');
99 end;
end;
10
/
10 /
PL/SQL
PL/SQL procedure
procedure successfully
successfully completed.
completed.
2005 SkillBuilders, Inc.
6.8
STA Demo
Display the report
SYSTEM>
SYSTEM> set
set long
long 1000
1000
SYSTEM>
set
linesize
SYSTEM> set linesize 120
120
SYSTEM>
select
dbms_sqltune.report_tuning_task('test2')
SYSTEM> select dbms_sqltune.report_tuning_task('test2') from
from dual;
dual;
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST2')
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST2')
----------------------------------------------------------------------------------------------------------------------------------GENERAL
11ststsection
GENERAL INFORMATION
INFORMATION SECTION
SECTION
sectionofofreport
reportgives
gives
-----------------------------------------------------------------general
information
-----------------------------------------------------------------general information
Tuning
Tuning Task
Task Name
Name :: test2
test2
Scope
:: COMPREHENSIVE
Scope
COMPREHENSIVE
Time
Limit(seconds):
1800
Time Limit(seconds): 1800
Completion
Completion Status
Status :: COMPLETED
COMPLETED
Started
at
:
08/02/2004
Started at
: 08/02/2004 17:49:29
17:49:29
Completed
at
:
08/02/2004
17:49:30
Completed at
: 08/02/2004 17:49:30
---------------------------------------------------------------------------------------------------------------------------------- 2005 SkillBuilders, Inc.
6.9
STA Demo
----------------------------------------------------------------------------------------------------------------------------------------------FINDINGS
FINDINGS SECTION
SECTION (1
(1 finding)
finding)
Findings
Findingssection
sectionidentifies
identifies
-----------------------------------------------------------------------------------------------------------------------------------------------
possible
possibleissues
issues
11- Statistics
Statistics Finding
Finding
----------------------------------------Table
Table "DAVE"."T"
"DAVE"."T" was
was not
not analyzed.
analyzed.
Recommendation
Recommendation
Recommendations
Recommendationssection
section
gives
possible
solutions
gives possible solutions
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST2')
DBMS_SQLTUNE.REPORT_TUNING_TASK('TEST2')
--------------------------------------------------------------------------------------------------------------------------------------------Consider
Consider collecting
collecting optimizer
optimizer statistics
statistics for
for this
this table.
table.
execute
dbms_stats.gather_table_stats(ownname
=>
'DAVE',
execute dbms_stats.gather_table_stats(ownname => 'DAVE', tabname
tabname =>
=> 'T',
'T',
estimate_percent
=>
DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt
=>
'FOR
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR
Clean
Cleanup
up
SYSTEM>
SYSTEM> exec
exec dbms_sqltune.drop_tuning_task('test2');
dbms_sqltune.drop_tuning_task('test2');
PL/SQL
PL/SQL procedure
procedure successfully
successfully completed.
completed.
2005 SkillBuilders, Inc.
6.10
SQL Profiles
Additional statistics and information for CBO
Uses
6.11
Mystery:
Mystery:how
how
totosee
the
see the
better
better
execution
execution
plan
planbefore
before
accepting?
accepting?
6.12
Doc
Docsays
saysthis
this
isisaaprocedure
procedure
its
itsactually
actually
aafunction.
function.
6.13
no
no rows
rows selected
selected
Execution
Execution Plan
Plan
------------------------------------------------------------------------------------------------------------------00
SELECT
SELECT STATEMENT
STATEMENT Optimizer=ALL_ROWS
Optimizer=ALL_ROWS (Cost=2
(Cost=2 Card=1
Card=1
11
00 TABLE
ACCESS
(BY
INDEX
ROWID)
OF
'BIG'
(TABLE)
TABLE ACCESS (BY INDEX ROWID) OF 'BIG' (TABLE) (C
(C
22
11
INDEX
INDEX (RANGE
(RANGE SCAN)
SCAN) OF
OF 'BIG_IDX'
'BIG_IDX' (INDEX)
(INDEX) (Cost=1
(Cost=1
DAVE>
DAVE> exec
exec dbms_sqltune.drop_sql_profile('profile_test_profile')
dbms_sqltune.drop_sql_profile('profile_test_profile')
PL/SQL
PL/SQL procedure
procedure successfully
successfully completed.
completed.
2005 SkillBuilders, Inc.
Cleanup
Cleanup
6.14
Recommends
Materialized views, view logs
Indexes
Access via
Enterprise Manager
DBMS_ADVISOR
Supplied package
6.15
Will
Full Workload
Believes
Access
Advisor
DEMO
6.16
changes?
R2
alter
alter session
session set
set "_gby_hash_aggregation_enabled"
"_gby_hash_aggregation_enabled" == FALSE;
FALSE;
6.17
unnesting
View merging
Before 10g
Unconditional
query transformation
10g
Cost
6.18
9i Dynamic Sampling
Compile time sampling of data to determine
selectivity and volume
Useful when statistics old or non-existent
Useful for queries executed many times or
with long execution time
Recursive SQL issued to read random
sample of data blocks
Does not save stats in dictionary
2005 SkillBuilders, Inc.
6.19
9i Dynamic Sampling
Control with optimizer_dynamic_sampling
parameter or dynamic_sampling hint
0 no sampling
1 through 10 Various levels of sampling;
10 most aggressive, does most work
SQL>
SQL> select
select /*+
/*+ dynamic_sampling(t
dynamic_sampling(t 10)
10) */
*/
22 from
from tt
33 where
where lastname
lastname == 'T';
'T';
11 select
select /*+
/*+ dynamic_sampling(1)
dynamic_sampling(1) */
*/
22
t.lastname,
t.lastname, o.order_date
o.order_date
33 from
from t,
t, ord
ord oo
4*
4* where
where t.cust_no
t.cust_no == o.cust_no
o.cust_no
2005 SkillBuilders, Inc.
**
6.20
9i Dynamic Sampling
select
select /*+
/*+ dynamic_sampling(t
dynamic_sampling(t 10)
10) */
*/ **
from
from tt
where
where lastname
lastname == 'T'
'T'
call
count
cpu
elapsed
disk
query
current
rows
call
count
cpu
elapsed
disk
query
current
rows
---------------------------------------------------------------------- ------ -------- ---------- ---------- ---------- ---------- ---------Parse
11
0.04
0.07
118
123
00
00
Parse
0.04
0.07
118
123
Execute
1
0.00
0.00
0
0
0
00
Execute
1
0.00
0.00
0
0
0
Fetch
2
0.00
0.00
0
5
0
22
Fetch
2
0.00
0.00
0
5
0
------------- ----------- --------------- ------------------- ------------------- ------------------- ------------------- ------------------total
4
0.04
0.07
118
128
00
22
total
4
0.04
0.07
118
128
6.21
6.22
10g Hints
Skip Scan
INDEX_SS,
INDEX_SS_ASC | DESC
Join
USE_NL_WITH_INDEX
Subquery
QB_NAME
Transformation
NO_QUERY_TRANSFORMATION
6.23
Part
Partofofnew
newJob
Job
Scheduler
feature.
Scheduler feature.
6.24
DBMS_STATS
Collect data dictionary statistics
SYSDBA>
SYSDBA> exec
exec dbms_stats.gather_dictionary_stats
dbms_stats.gather_dictionary_stats
6.25
Rule-Based Optimization
Still exists, but not supported
OPTIMIZER_MODE considerations
CHOOSE
documentation:
6.26
SQL*Plus AUTOTRACE
DAVE@linux3>
DAVE@linux3> select
select ** from
from big,small
big,small
22 where
big.object_id=small.object_id
where big.object_id=small.object_id
33 and
and big.owner
big.owner like
like 'A%';
'A%';
R2
Execution
Execution Plan
Plan
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|| Id
|| Name
|| Rows
Id || Operation
Operation
Name
Rows || Bytes
Bytes || Cost
Cost (%CPU)
(%CPU)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------|| 00 || SELECT
||
||
11 || 265
SELECT STATEMENT
STATEMENT
265 || 3707
3707 (3)
(3)
|| 11 || NESTED
LOOPS
|
|
1
|
265
|
3707
(3)
NESTED LOOPS
|
|
1 |
265 | 3707
(3)
|*
2
|
TABLE
ACCESS
FULL
|
BIG
|
1
|
186
|
3706
(3)
|* 2 |
TABLE ACCESS FULL
| BIG
|
1 |
186 | 3706
(3)
|| 33 || TABLE
ACCESS
BY
INDEX
ROWID|
SMALL
|
1
|
79
|
1
(0)
TABLE ACCESS BY INDEX ROWID| SMALL
|
1 |
79 |
1
(0)
|*
4
|
INDEX
UNIQUE
SCAN
|
SMALL_OBJECT_ID
|
1
|
|
0
(0)
|* 4 |
INDEX UNIQUE SCAN
| SMALL_OBJECT_ID |
1 |
|
0
(0)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------Predicate
Predicate Information
Information (identified
(identified by
by operation
operation id):
id):
----------------------------------------------------------------------------------------------------22 -- filter("BIG"."OWNER"
filter("BIG"."OWNER" LIKE
LIKE 'A%')
'A%')
44 -- access("BIG"."OBJECT_ID"="SMALL"."OBJECT_ID")
access("BIG"."OBJECT_ID"="SMALL"."OBJECT_ID")
2005 SkillBuilders, Inc.
6.27
PL/SQL Performance
New optimizing compiler
Better
integer
performance
reuse of expression values
simplification of branching code
performance for some library calls
elimination of dead code
6.28
PL/SQL Performance
Initialization parameter controls level of optimization
LINUX>
LINUX> show
show parameter
parameter plsql_opt
plsql_opt
NAME
TYPE
VALUE
NAME
TYPE
VALUE
----------------------------------------------------------------------- --------------------- --------plsql_optimize_level
integer
22
plsql_optimize_level
integer
Automatic
Automaticrecompilations
recompilationsuse
use
level
stored
with
program
level stored with program
2005 SkillBuilders, Inc.
6.29
PL/SQL Performance
Dictionary view reveals compile-time settings
LINUX>
LINUX> exec
exec print_table('select
print_table('select ** from
from
all_plsql_object_settings
all_plsql_object_settings where
where name
name == ''TEST''
''TEST'' ')
')
OWNER
:: DAVE
OWNER
DAVE
NAME
:: TEST
NAME
TEST
TYPE
:: PROCEDURE
TYPE
PROCEDURE
PLSQL_OPTIMIZE_LEVEL
:
2
PLSQL_OPTIMIZE_LEVEL
: 2
PLSQL_CODE_TYPE
:: INTERPRETED
PLSQL_CODE_TYPE
INTERPRETED
6.30
Optimization Comparison
ORACLE9i>
ORACLE9i> begin
begin
22
for
for xx in
in (( select
select ** from
from all_objects
all_objects where
where rownum
rownum << 10000)
10000)
33
loop
loop
44
null;
null;
55
end
end loop;
loop;
9i compiler provides
66 end;
end;
77 //
no conversion
PL/SQL
PL/SQL procedure
procedure successfully
successfully completed.
completed.
select
select **
from
from
all_objects
all_objects where
where rownum
rownum << 10000
10000
10,000 individual
fetches
call
count
cpu
elapsed
disk
query
current
rows
call
count
cpu
elapsed
disk
query
current
rows
---------------------------------------------------------------------- ------ -------- ---------- ---------- ---------- ---------- ---------Parse
11
0.06
0.07
00
00
00
00
Parse
0.06
0.07
Execute
11
0.00
0.00
00
00
00
00
Execute
0.00
0.00
Fetch
10000
3.18
3.11
00
63481
00
9999
Fetch
10000
3.18
3.11
63481
9999
---------------------------------------------------------------------- ------ -------- ---------- ---------- ---------- ---------- ---------total
10002
3.24
3.18
00
63481
00
9999
total
10002
3.24
3.18
63481
9999
2005 SkillBuilders, Inc.
6.31
Optimization Comparison
ORACLE10G>
ORACLE10G> begin
begin
22
for
for xx in
in (( select
select ** from
from all_objects
all_objects where
where rownum
rownum << 10000)
10000)
33
loop
loop
44
null;
null;
55
end
end loop;
loop;
10g compiler converts
66 end;
end;
77 //
this into a bulk collect
PL/SQL
PL/SQL procedure
procedure successfully
successfully completed.
completed.
SELECT
SELECT **
FROM
FROM
ALL_OBJECTS
ALL_OBJECTS WHERE
WHERE ROWNUM
ROWNUM << 10000
10000
Arraysize = 100
Great reduction in
CPU, elapsed time
and logical I/O
call
count
cpu
elapsed
disk
query
current
rows
call
count
cpu
elapsed
disk
query
current
rows
---------------------------------------------------------------------- ------ -------- ---------- ---------- ---------- ---------- ---------Parse
11
0.00
0.00
00
00
00
00
Parse
0.00
0.00
Execute
11
0.00
0.00
00
00
00
00
Execute
0.00
0.00
Fetch
100
0.79
0.74
00
15812
00
9999
Fetch
100
0.79
0.74
15812
9999
---------------------------------------------------------------------- ------ -------- ---------- ---------- ---------- ---------- ---------total
102
0.79
0.75
00
15812
00
9999
total
102
0.79
0.75
15812
9999
2005 SkillBuilders, Inc.
6.32
COMMIT Enhancements
Can COMMIT w/o waiting for log write
Performance increase
BATCH groups redo streams for write
6.33
20 24, NYC
May 1 5, NYC
9 12, Richmond
May 15 18, NYC
9 11, NYC
6.34
The End
Thanks for listening!
Dave
Anderson
dave@skillbuilders.com
www.skillbuilders.com
Visit for tech papers,
download presentations