D52163GC10 sg2
D52163GC10 sg2
D52163GC10 sg2
n s e
i ce
b l el
fer a
a n s
o n -tr
Oracle Database n 11g: SQL Tuning
a
s eฺ
Workshop h a
e s ) u id
ฺ
ir ent G
ฺ m
d gp SVolume
tud
II • Student Guide
b i a@ this
i a (ja use
Ab to
o n io
n t
e A
J o s
D52163GC10
Edition 1.0
June 2008
D54948
Author Copyright © 2008, Oracle. All rights reserved.
license, post, transmit, or distribute this document in whole or in part without the
Joel Goodman express authorization of Oracle.
Harald van Breederode
The information contained in this document is subject to change without notice. If you
Jörn Bartels find any problems in the document, please report them in writing to: Oracle University,
500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
Pekka Siltala warranted to be error-free.
Bernard Soleillant
Restricted Rights Notice
James Spiller If this documentation is delivered to the United States Government or anyone using
the documentation on behalf of the United States Government, the following notice is
n s e
Clay Fuller applicable:
ice
Ira Singer
b l el
Christopher Andrews
U.S. GOVERNMENT RIGHTS
fe r a
The U.S. Government’s rights to use, modify, reproduce, release, perform, display, or
Magnus Isaksson n s
disclose these training materials are restricted by the terms of the applicable Oracle
a
Sean Kim n - tr
license agreement and/or the applicable U.S. Government contract.
o
an
Trademark Notice
Trevor Bauwen
Yash Jain
s
a deฺ
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other
h
)
s Gui
names may be trademarks of their respective owners.
e
r ฺ
Editors
p ฺ mi dent
Amitha Narayan d g Stu
Raj Kumar
b i a@ this
i a (ja use
b
Graphic Designer
A to
ni o
Priya Saxena
t o
e An
Jos
Publishers
Jothi Lakshmi
Veena Narasimhan
Contents
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
iii
Common Mistakes on Customer Systems 2-14
Proactive Tuning Methodology 2-16
Simplicity in Application Design 2-17
Data Modeling 2-18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
iv
Summary 3-35
Practice 3: Overview 3-36
4 Optimizer Operators
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Objectives 4-2
Row Source Operations 4-3
Main Structures and Access Paths 4-4
Full Table Scan 4-5
Full Table Scans: Use Cases 4-6
ROWID Scan 4-7
Sample Table Scans 4-8
n s e
Indexes: Overview 4-10
i ce
Normal B*-tree Indexes 4-12
b l el
Index Scans 4-13
fer a
Index Unique Scan 4-14
a n s
Index Range Scan 4-15 n -tr
o
Index Range Scan: Descending 4-16
s an
Descending Index Range Scan 4-17
) h a deฺ
ฺ e s Gui
Index Range Scan: Function-Based 4-18
r
Index Full Scan 4-19
p ฺ mi dent
d g Stu
Index Fast Full Scan 4-20
i a@ this
Index Skip Scan 4-21
b
i a (ja use
Index Skip Scan: Example 4-23
Ab to
Index Join Scan 4-24
o n io
The AND-EQUAL Operation 4-25
nt
e A B*-tree Indexes and Nulls 4-26
J o s Using Indexes: Considering Nullable Columns 4-27
Index-Organized Tables 4-28
Index-Organized Table Scans 4-29
Bitmap Indexes 4-30
Bitmap Index Access: Examples 4-31
Combining Bitmap Indexes: Examples 4-32
Combining Bitmap Index Access Paths 4-33
Bitmap Operations 4-34
Bitmap Join Index 4-35
Composite Indexes 4-36
Invisible Index: Overview 4-37
Invisible Indexes: Examples 4-38
Guidelines for Managing Indexes 4-39
Investigating Index Usage 4-41
Practice 4: Overview 4-43
v
Clusters 4-44
When Are Clusters Useful? 4-45
Cluster Access Path: Examples 4-47
Sorting Operators 4-48
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
vi
AUTOTRACE 5-15
The AUTOTRACE Syntax 5-16
AUTOTRACE: Examples 5-17
AUTOTRACE: Statistics 5-18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
p ฺ mi dent
Execution Plan Interpretation: Example 2 5-45
Execution Plan Interpretation: Example 3 5-47
d g Stu
b i a@ this
Reading More Complex Execution Plans 5-48
i a (ja use
Reviewing the Execution Plan 5-49
Ab to
Looking Beyond Execution Plans 5-50
o n io
Summary 5-51
nt Practice 5: Overview 5-52
e A
J o s
6 Case Study: Star Transformation
Objectives 6-2
The Star Schema Model 6-3
The Snowflake Schema Model 6-4
Star Query: Example 6-5
Execution Plan Without Star Transformation 6-6
Star Transformation 6-7
Star Transformation: Considerations 6-8
Star Transformation: Rewrite Example 6-9
Retrieving Fact Rows from One Dimension 6-10
Retrieving Fact Rows from All Dimensions 6-11
Joining the Intermediate Result Set with Dimensions 6-12
Star Transformation Plan: Example 1 6-13
Star Transformation: Further Optimization 6-14
vii
Using Bitmap Join Indexes 6-15
Star Transformation Plan: Example 2 6-16
Star Transformation Hints 6-17
Bitmap Join Indexes: Join Model 1 6-18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
7 Optimizer Statistics
n s e
Objectives 7-2
i ce
Optimizer Statistics 7-3
b l el
Types of Optimizer Statistics 7-4
fer a
Table Statistics (DBA_TAB_STATISTICS) 7-5
a n s
Index Statistics (DBA_IND_STATISTICS) 7-6 n -tr
o
Index Clustering Factor 7-8
s an
h
Column Statistics (DBA_TAB_COL_STATISTICS) 7-10
) a deฺ
Histograms 7-11 r ฺ e s Gui
Frequency Histograms 7-12 p ฺ mi dent
d g Stu
Viewing Frequency Histograms 7-13
b i a@ this
Height-Balanced Histograms 7-14
a (ja use
Viewing Height-Balanced Histograms 7-15
i
Ab to
Histogram Considerations 7-16
o n io
t
Multicolumn Statistics: Overview 7-17
n
e A Expression Statistics: Overview 7-19
J o s Gathering System Statistics 7-20
Gathering System Statistics: Example 7-22
Mechanisms for Gathering Statistics 7-24
Statistic Preferences: Overview 7-25
When to Gather Statistics Manually 7-27
Manual Statistics Gathering 7-28
Manual Statistics Collection: Factors 7-29
Managing Statistics Collection: Example 7-30
Optimizer Dynamic Sampling: Overview 7-31
Optimizer Dynamic Sampling at Work 7-32
OPTIMIZER_DYNAMIC_SAMPLING 7-33
Locking Statistics 7-34
Summary 7-35
Practice 7: Overview 7-36
viii
8 Using Bind Variables
Objectives 8-2
Cursor Sharing and Different Literal Values 8-3
Cursor Sharing and Bind Variables 8-4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
ix
10 Application Tracing
Objectives 10-2
End-to-End Application Tracing Challenge 10-3
End-to-End Application Tracing 10-4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
x
Implementing Recommendations 11-15
SQL Access Advisor: Overview 11-16
SQL Access Advisor: Usage Model 11-17
Possible Recommendations 11-18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Jos
xi
J
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
o s e
n A
t o n
Aio
b i a
b i
to
(ja use
d p ฺ
a@ this
xii
r ฺ
g Stu
e ) h
mi dent
s
s Gui
an
o
a deฺ
tr n -
a n s fe
r
a b l el
i
ce n s e
Appendix A
Practices and Solutions
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
n s e
i ce
b l el
fer a
a n s
n -tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
Table of Contents
Practices for Lesson 1 ......................................................................................................... 3
Practice 1-1: Exploring the Database Architecture......................................................... 4
Practices for Lesson 2 ....................................................................................................... 12
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
r ฺ e s Gui
Practice 8-2: Understanding CURSOR_SHARING................................................... 260
p ฺ mi dent
Practices for Lesson 9 ..................................................................................................... 273
Practice 9-1: Using Hints ............................................................................................ 274
d g Stu
Practices for Lesson 10 ................................................................................................... 318
i a@ this
Practice 10-1: Tracing Applications ........................................................................... 319
b
i a (ja use
Practices for Lesson 11 ................................................................................................... 363
b to
Practice 11-1: Proactively Tuning High-Load SQL Statements................................. 364
A
o n io
Practice 11-2: Using SQL Access Advisor................................................................. 385
ntPractice 11-3: Using Automatic SQL Tuning............................................................. 415
e A
J o s
n s e
i ce
b l el
fer a
a n s
n -tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
i a (ja use
• ____________________________
A b to
o
ni some background processes:
5)toList
An
e •
Jos
___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
• ___________________________
6) The _______________________ process writes the dirty buffers to the data files.
7) The _______________________ process writes the redo logs to the log files.
• ___________________________
• ___________________________
• ____________________________
onfig/OCMTrustedCerts.txt-
r ฺ s Gui
Djavax.net.ssl.KeyStore=/u01/app/oracle/product/11.1.0/db_1/sysman/c
e
ฺ mi dent
Djava.security.properties=/u01/app/oracle/product/11.1.0/db_1/oc4j/j
p
g Stu
2ee/home/config/jazn.security.props -
d
a@ this
DEMDROOT=/u01/app/oracle/product/11.1.0/db_1/edrsr33p1.us.oracle.com
b i
_orcl -Dsysman.md5password=true -
i a (ja use
Drepapi.oracle.home=/u01/app/oracle/product/11.1.0/db_1 -
b to
Ddisable.checkForUpdate=true -
A
io
Doracle.sysman.ccr.ocmSDK.websvc.keystore=/u01/app/oracle/product/11
t o n
.1.0/db_1/jlib/emocmclnt.ks -
A n Dice.pilots.html4.ignoreNonGenericFonts=true -
o s e Djava.awt.headless=true -jar
J /u01/app/oracle/product/11.1.0/db_1/oc4j/j2ee/home/oc4j.jar -config
/u01/app/oracle/product/11.1.0/db_1/oc4j/j2ee/OC4J_DBConsole_edrsr33
p1.us.oracle.com_orcl/config/server.xml
oracle 12225 1 0 Mar26 ? 00:00:00 ora_pmon_orcl
oracle 12227 1 0 Mar26 ? 00:00:00 ora_vktm_orcl
oracle 12231 1 0 Mar26 ? 00:00:00 ora_diag_orcl
oracle 12233 1 0 Mar26 ? 00:00:00 ora_dbrm_orcl
oracle 12235 1 0 Mar26 ? 00:00:00 ora_psp0_orcl
oracle 12239 1 0 Mar26 ? 00:00:00 ora_dia0_orcl
oracle 12241 1 0 Mar26 ? 00:00:00 ora_mman_orcl
oracle 12243 1 0 Mar26 ? 00:00:21 ora_dbw0_orcl
oracle 12245 1 0 Mar26 ? 00:00:48 ora_lgwr_orcl
oracle 12247 1 0 Mar26 ? 00:00:01 ora_ckpt_orcl
oracle 12249 1 0 Mar26 ? 00:00:04 ora_smon_orcl
oracle 12251 1 0 Mar26 ? 00:00:00 ora_reco_orcl
oracle 12253 1 0 Mar26 ? 00:00:05 ora_mmon_orcl
oracle 12255 1 0 Mar26 ? 00:00:01 ora_mmnl_orcl
oracle 12257 1 0 Mar26 ? 00:00:00 ora_d000_orcl
oracle 12259 1 0 Mar26 ? 00:00:00 ora_s000_orcl
oracle 12282 1 0 Mar26 ? 00:00:00 ora_fbda_orcl
(LOCAL=NO)
oracle 12331 1 0 Mar26 ? 00:00:12 oracleorcl
(LOCAL=NO)
oracle 12333 1 0 Mar26 ? 00:00:05 oracleorcl
(LOCAL=NO)
oracle 12335 1 0 Mar26 ? 00:00:37 oracleorcl
(LOCAL=NO)
oracle 12340 1 0 Mar26 ? 00:01:51 oracleorcl
(LOCAL=NO)
oracle 12346 1 0 Mar26 ? 00:00:01 oracleorcl
n s e
(LOCAL=NO)
i ce
oracle 12362 1 0 Mar26 ? 00:00:00 ora_q001_orcl
b l el
oracle
oracle
12570
20119
1 0 Mar26 ?
1 0 14:50 ?
00:00:01 ora_cjq0_orcl
00:00:00 oracleorcl
fe r a
(LOCAL=NO)
a n s
oracle 20482 20480 0 14:56 pts/2 -tr
00:00:00 grep orcl
o n
an
oracle 22002 1 0 Mar26 pts/4 00:00:08
/u01/app/oracle/product/11.1.0/db_1/perl/bin/perl
h s
a deฺ
/u01/app/oracle/product/11.1.0/db_1/bin/emwd.pl dbconsole
)
s Gui
/u01/app/oracle/product/11.1.0/db_1/edrsr33p1.us.oracle.com_orcl/sys
e
r ฺ
mi dent
man/log/emdb.nohup
p ฺ
[oracle@edrsr33p1-orcl Database_Architecture]$
g Stu
d
b i a@ this
--------------------------------------------------------------
#!/bin/bash (ja se
b i a to u
i o
ps -efA| grep orcl
nton
e A 15) From a terminal session connected as the oracle user, execute the files.sh
J o s script located in your $HOME/solutions/Database_Architecture
directory. What does this script show you?
a) This script shows you the location and names of all database files, the
initialization file, the password file, and trace files.
[oracle@edrsr33p1-orcl Database_Architecture]$ ./files.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
NAME
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
---------------------------------------------
/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/oradata/orcl/control02.ctl
/u01/app/oracle/oradata/orcl/control03.ctl
SQL>
SQL>
SQL> col member format a45
SQL>
SQL> select group#,member from v$logfile;
n s e
i ce
GROUP# MEMBER
b l el
----------
3
---------------------------------------------
/u01/app/oracle/oradata/orcl/redo03.log
fer a
2 /u01/app/oracle/oradata/orcl/redo02.log
a n s
1 /u01/app/oracle/oradata/orcl/redo01.log
o n -tr
SQL>
s an
SQL> col tablespace_name format a20 ) h
SQL> a deฺ
SQL> col file_name format a45 rฺe
s Gui
SQL> ฺ m i ent
d p tud from dba_data_files;
g file_name
SQL> select tablespace_name,
@ his S
TABLESPACE_NAME bia FILE_NAME
t
( j a
-------------------- s e
---------------------------------------------
USERS bia
t o u /u01/app/oracle/oradata/orcl/users01.dbf
i oA
UNDOTBS1
n
/u01/app/oracle/oradata/orcl/undotbs01.dbf
ntoSYSTEM
SYSAUX /u01/app/oracle/oradata/orcl/sysaux01.dbf
e A /u01/app/oracle/oradata/orcl/system01.dbf
J o s EXAMPLE /u01/app/oracle/oradata/orcl/example01.dbf
SQL>
SQL> select tablespace_name, file_name from dba_temp_files;
TABLESPACE_NAME FILE_NAME
-------------------- ---------------------------------------------
TEMP /u01/app/oracle/oradata/orcl/temp01.dbf
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
-rw-rw---- 1 oracle oinstall 1544 Aug 22 2007
/u01/app/oracle/product/11.1.0/db_1/dbs/hc_orcl.dat
-rw-r----- 1 oracle oinstall 1536 Mar 26 22:03
/u01/app/oracle/product/11.1.0/db_1/dbs/orapworcl
-rw-r----- 1 oracle oinstall 2560 Mar 27 03:13
/u01/app/oracle/product/11.1.0/db_1/dbs/spfileorcl.ora
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Database_Architecture
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
n s e
export
i ce
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
b l el
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
fe r a
a n s
sqlplus / as sysdba @files.sql
o n -tr
ls -l $ORACLE_HOME/dbs/*orcl*
s an
) h a deฺ
ls /u01/app/oracle/diag/rdbms/orcl/orcl
r ฺ e s Gui
ฺ mi dent
ls -l /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert*
p
d g Stu
b i a@ this
--------------------------------------------------------------
ntoselect
e A
J o s
col member format a45
exit;
16) From a terminal session connected as the oracle user, execute the sga.sh script
located in your $HOME/solutions/Database_Architecture directory.
What does this script show you?
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
n s e
SQL>
i ce
SQL> select * from v$sgainfo;
b l el
NAME BYTES RES
fer a
-------------------------------- ---------- ---
a n s
Fixed SGA Size 1303188 No
n - tr
Redo Buffers 5181440 No o
Buffer Cache Size 335544320 Yes
s an
Shared Pool Size a deฺ
276824064 Yes
) h
Large Pool Size
r ฺ e s Gui
4194304 Yes
mi dent
Java Pool Size 12582912 Yes
Streams Pool Size
p ฺ
g Stu
0 Yes
Shared IO Pool Size
d 0 Yes
a@ this
Granule Size 4194304 No
Maximum SGA Size
b i 845348864 No
i a (ja use
Startup overhead in Shared Pool 46137344 No
Ab to
o n io
NAME BYTES RES
-------------------------------- ---------- ---
nt
e A Free SGA Memory Available 209715200
J o s 12 rows selected.
SQL>
SQL> col component format a30
SQL>
SQL> select component,current_size,min_size,max_size from
v$sga_dynamic_components;
14 rows selected.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
n s e
[oracle@edrsr33p1-orcl Database_Architecture]$
i ce
b l el
--------------------------------------------------------------
fer a
a n s
#!/bin/bash
o n -tr
cd /home/oracle/solutions/Database_Architecture
s an
) h a deฺ
export ORACLE_SID=orcl
r ฺ e s Gui
ฺ mi dent
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
p
d g Stu
export
b i a@ this
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
i a (ja use
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
A b to
ni o
ntosqlplus / as sysdba @sga.sql
e A
J o s --------------------------------------------------------------
set echo on
exit;
n s e
i ce
b l el
fer a
a n s
n -tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
example. Make sure you run the script from a terminal session connected as the
oracle user. You can find the scripts for all the following cases in your
$HOME/solutions/Common_Mistakes directory.
[oracle@edrsr33p1-orcl Common_Mistakes]$ ./correlation_setup.sh
a b l
fe r
Connected to:
a n s
Production
o n -tr
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
an
With the Partitioning, Oracle Label Security, OLAP, Data Mining
s
and Real Application Testing options
) h a deฺ
SQL> SQL>
r ฺ e s Gui
User altered.
p ฺ mi dent
SQL> SQL> d g Stu
Grant succeeded. ia@ is
b t h
SQL> SQL>ia (ja usefrom Oracle Database 11g Enterprise Edition
Disconnected
A
Release to - Production
b11.1.0.6.0
o
ni Real
With the Partitioning, Oracle Label Security, OLAP, Data Mining
ntoand Application Testing options
e A [oracle@edrsr33p1-orcl Common_Mistakes]$
J o s
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Common_Mistakes
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
execute. The flush.sql script flushes both the shared pool and the buffer cache to
avoid most caching effects so that you can have good comparisons between two
executions. Note: You should not use commands found in this script on a production
system.
[oracle@edrsr33p1-orcl Common_Mistakes]$ sqlplus sh/sh
A b to
ni o
System altered.
ntoElapsed: 00:00:00.49
e A SQL>
J o s
--------------------------------------------------------------
3) From the same SQL*Plus session, execute the following statement and note the time
it takes to execute (You can use the correlation.sql script.):
SELECT COUNT(*)
FROM products p
WHERE prod_list_price < 1.15 * (SELECT avg(unit_cost)
FROM costs c
WHERE c.prod_id = p.prod_id);
SQL> @correlation
SQL>
SQL> SELECT COUNT(*)
2 FROM products p
3 WHERE prod_list_price < 1.15 * (SELECT avg(unit_cost)
COUNT(*)
----------
46
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Elapsed: 00:00:01.21
SQL>
--------------------------------------------------------------
set timing on
set echo on
SELECT COUNT(*)
n s e
FROM products p
i ce
WHERE prod_list_price < 1.15 * (SELECT avg(unit_cost)
b l el
FROM costs c
WHERE c.prod_id = p.prod_id);
fe r a
a n s
n - tr
o
4) Before trying to fix the previous statement, flush your environment again using the
flush.sql script from the SQL*Plus session.
s an
) h a deฺ
SQL> @flush
r ฺ e s Gui
ฺ m i ent
SQL> alter system flush shared_pool;
System altered.
d p
g Stud
b i
Elapsed: 00:00:00.10 a@ this
(ja flush
SQL> alter system
i a u se buffer_cache;
A b to
i o
System altered.
nton
e A Elapsed: 00:00:00.17
J o s SQL>
5) How do you rewrite this statement to enhance performance? Test your solution. You
should discuss this with your instructor.
SQL> @nocorrelation
SQL>
SQL> set timing on
SQL> set echo on
SQL>
SQL> SELECT COUNT(*)
2 FROM products p, (SELECT prod_id, AVG(unit_cost) ac FROM
costs GROUP BY prod_id) c
3 WHERE p.prod_id = c.prod_id AND
4 p.prod_list_price < 1.15 * c.ac;
COUNT(*)
----------
46
Elapsed: 00:00:00.16
--------------------------------------------------------------
set timing on
set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SELECT COUNT(*)
FROM products p, (SELECT prod_id, AVG(unit_cost) ac FROM costs
GROUP BY prod_id) c
WHERE p.prod_id = c.prod_id AND
p.prod_list_price < 1.15 * c.ac;
ia@
2008
b t h is
Copyright (c)ja e
( 1982,
u s
2007, Oracle. All rights reserved.
A bia to
o n io
Connected to:
t
An Production
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
e
Jos With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> SQL>
Revoke succeeded.
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Common_Mistakes
export ORACLE_SID=orcl
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
EOF
i a (ja use
and Real Application Testing options
A
SQL> SQL> to drop user jfv cascade
b SQL> SQL>
o
ni at line *
ntoERROR 1:
e A ORA-01918: user 'JFV' does not exist
J o s
SQL> SQL>
User created.
SQL> SQL>
Grant succeeded.
SQL> SQL>
Table created.
SQL> SQL> 2 3 4 5 6 7
PL/SQL procedure successfully completed.
ERROR at line 1:
ORA-00942: table or view does not exist
n s e
SQL> SQL>
i ce
Table created.
b l el
SQL> SQL> 2 3 4 5 6 7
fer a
PL/SQL procedure successfully completed.
a n s
n -tr
o
an
SQL> SQL>
Table created.
s
a deฺ
)7h
SQL> SQL> 2 3 4 5
r
6
ฺ e s Gui
ฺ m i ent
PL/SQL procedure successfully completed.
SQL> SQL>
d g p t u d
Index created.
a@ this S
b i
SQL> SQL> SQL>
i a (jadroputable
se old purge
b
at line 1:t
ERROR A
* o
ni o
ntoORA-00942: table or view does not exist
e A
J o s SQL> drop table new purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> SQL>
Table created.
SQL>
Table created.
SQL> SQL> 2 3 4 5 6 7
PL/SQL procedure successfully completed.
SQL> SQL> 2 3 4 5 6 7
PL/SQL procedure successfully completed.
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
#!/bin/bash
cd /home/oracle/solutions/Common_Mistakes
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
n s e
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
i ce
b l el
sqlplus / as sysdba <<EOF
fer a
set echo on
a n s
o n -tr
a n users temporary
drop user jfv cascade;
e A
J o s begin
for i in 1..500000 loop
insert into orders
values(i,100,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaa');
end loop;
commit;
end;
/
begin
for i in 1..500000 loop
insert into orders
values(500000+i,100,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
end loop;
commit;
begin
for i in 1..500000 loop
insert into employees
values(i,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa');
n s e
end loop;
i ce
commit;
b l el
end;
/
fer a
a n s
o n -tr
create table job_history (employee_id number, job varchar2(500));
begin
s an
for i in 1..500000 loop
) h a deฺ
insert into job_history
r ฺ e s Gui
ฺ m i ent
values(mod(i,1000),'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
d g p t u d
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
a@ this
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa');S
end loop; b i
commit;
i a (ja use
end;
A b to
o
ni index job_history_empid_indx on job_history(employee_id);
/
ntocreate
e A
J o s
drop table old purge;
drop table new purge;
begin
for i in 1..500000 loop
insert into old
values(i,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa');
end loop;
commit;
end;
/
begin
end loop;
commit;
end;
/
EOF
9) Connect as the JFV user from a SQL*Plus session and stay connected in that session
n s e
until further notice. In the session, set SQL*Plus timings on and flush your
ice
environment again before starting the second case. You can use the set timing
b l el
on command and the flush.sql script for this.
f er a
an s
[oracle@edrsr33p1-orcl Common_Mistakes]$ sqlplus jfv/jfv
- t r
n 26 21:06:33
n oMar
SQL*Plus: Release 11.1.0.6.0 - Production on Wed
s a
a eฺ
2008
) h i d
Copyright (c) 1982, 2007, Oracle. es
i r t Gu reserved.
ฺ Allnrights
g p ฺm ude
Connected to: d S t
i a @ h i s
Oracle Database 11g
b t
Enterprise Edition Release 11.1.0.6.0 -
Production
a (ja useOracle Label Security, OLAP, Data Mining
With the iPartitioning,
A
and Real to Testing options
b Application
o
ni set timing on
ntoSQL>
e A SQL> @flush
J o s
System altered.
Elapsed: 00:00:00.33
System altered.
Elapsed: 00:00:07.12
SQL>
--------------------------------------------------------------
SQL> @join
SQL>
SQL> SELECT count(*)
2 FROM job_history jh, employees e
3 WHERE substr(to_char(e.employee_id),1) =
substr(to_char(jh.employee_id),1);
COUNT(*)
----------
n s e
499500
i ce
b l el
Elapsed: 00:00:03.03
SQL> fe r a
a n s
n
--------------------------------------------------------------
o -tr
set timing on a n
set echo on
h s
a deฺ
e )
s Gui
r ฺ
mi e dent
SELECT count(*)
FROM
p
job_history jh, employees ฺ
g Stu
d
WHERE substr(to_char(e.employee_id),1) =
b i a@ this
substr(to_char(jh.employee_id),1);
i a (ja use
b to fixtthe
11) Before trying
A o previous statement, flush your environment again using the
i o
flush.sql
n script from your SQL*Plus session.
t o
e An SQL> @flush
Jos
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.12
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:00.72
SQL>
--------------------------------------------------------------
12) How would you rewrite the previous query for better performance? Test your
solution. You should discuss this with your instructor.
COUNT(*)
----------
499500
Elapsed: 00:00:00.70
SQL>
n s e
--------------------------------------------------------------
ice
b l el
set timing on
fe r a
set echo on
a n s
SELECT count(*)
o n -tr
an
FROM job_history jh, employees e
WHERE e.employee_id = jh.employee_id;
h s
a deฺ
e )
s Guagain i
r
13) Before analyzing the third case, flush yourฺ
i ent environment using the flush.sql
ฺ m
gp Stud
script from your SQL*Plus session.
d
SQL> @flush
i @ shared_pool;
aflush h is
b t
(ja use
SQL> alter system
b i a to
A
System altered.
o
t o ni
Elapsed: 00:00:00.11
A n SQL> alter system flush buffer_cache;
e
Jos System altered.
Elapsed: 00:00:00.23
SQL>
--------------------------------------------------------------
14) The third case you analyze is a simple predicate case. Still connected as the JFV user
from your SQL*Plus session, execute the following query and note the time it takes
to complete:
SELECT * FROM orders WHERE order_id_char = 1205;
SQL> @simple_predicate
SQL>
SQL> set timing on
SQL> set echo on
ORDER_ID_CHAR ORDER_TOTAL
-------------------------------------------------- -----------
CUSTOMER_NAME
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
------------
1205 100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
n s e
Elapsed: 00:00:07.62
i ce
SQL>
b l el
--------------------------------------------------------------
fe r a
a n s
set timing on
o n -tr
an
set echo on
System altered.
Elapsed: 00:00:00.20
SQL>
16) How would you rewrite the previous statement for better performance? Test your
solution. You should discuss this with your instructor.
SQL> @better_predicate
SQL>
SQL> set timing on
SQL> set echo on
SQL>
SQL> SELECT * FROM orders WHERE order_id_char = '1205';
ORDER_ID_CHAR ORDER_TOTAL
-------------------------------------------------- -----------
CUSTOMER_NAME
aaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Elapsed: 00:00:00.04
SQL>
--------------------------------------------------------------
set timing on
n s e
set echo on
i ce
b l el
SELECT * FROM orders WHERE order_id_char = '1205';
fe ra
a n s
n - tr
17) Before proceeding with the next analysis, flush your environment again using the
flush.sql script. o
s an
SQL> alter system flush shared_pool; ) h
SQL> @flush a deฺ
r ฺ e s Gui
System altered.
p ฺ mi dent
Elapsed: 00:00:00.11@d
g Stu
b
SQL> alter system i t h is
aflush buffer_cache;
i a (ja use
b
System altered.
A to
ni o
ntoElapsed: 00:00:00.11
e A SQL>
J o s --------------------------------------------------------------
18) The fourth case is a UNION case. Execute the following query and note the time it
takes to complete:
select count(*)
from (select name from old union select name from new);
SQL> @union
SQL>
SQL> set timing on
SQL> set echo on
SQL>
SQL> select count(*)
2 from (select name from old union select name from new);
COUNT(*)
Elapsed: 00:00:06.39
SQL>
19) Before investigating a better solution, flush your environment again using the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
flush.sql script.
SQL> @flush
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.10
SQL> alter system flush buffer_cache;
n s e
i ce
System altered.
b l el
Elapsed: 00:00:00.09
fe r a
SQL>
a n s
n -tr
20) How would you rewrite the previous statement for better performance? Test your
o
an
solution. You should discuss this with your instructor.
s
) h a deฺ
SQL> @better_union
SQL>
r ฺ e s Gui
SQL> set timing on
p ฺ mi dent
SQL> set echo on
d g Stu
a@ this
SQL>
b i
SQL> select count(*)
i a (ja name
2 from (select
u sefrom old union all select name from new);
A b
COUNT(*) to
i o
ton 1000000
----------
A n
o s e
J Elapsed: 00:00:00.42
SQL>
21) Execute the multiple_setup.sql script to set up the environment for this case.
SQL> @multiple_setup
SQL> create table myemp as select * from hr.employees;
Table created.
SQL>
214 rows created.
SQL>
428 rows created.
SQL>
n s e
856 rows created.
i ce
b l el
SQL>
1712 rows created.
fer a
a n s
SQL>
n -tr
o
an
3424 rows created.
SQL>
h s
a deฺ
6848 rows created.
e )
s Gui
r ฺ
i ent
SQL>
p ฺ m
13696 rows created.
d g Stud
SQL> b i a@ this
i a (ja use
27392 rows created.
SQL> A
b to
o
ni rows created.
nto54784
e A
J o s SQL>
109568 rows created.
SQL>
219136 rows created.
SQL>
438272 rows created.
SQL>
876544 rows created.
SQL>
1753088 rows created.
SQL>
SQL>
Commit complete.
SQL>
Commit complete.
SQL>
22) Execute the multiple1.sql script and note the total time it takes to execute.
SQL> @multiple1
SQL> set timing on
n s e
i ce
el
SQL>
SQL>
a b l
SQL> SELECT COUNT (*)
fe r
FROM myemp
a n s
WHERE salary < 2000;
n - tr
2 3
o
s an
) h a deฺ
COUNT(*)
r ฺ e s Gui
----------
p ฺ mi dent
0
d g Stu
b
Elapsed: 00:00:15.49 i a@ this
( j
SQL> SELECT COUNT a (*)se
FROM myemp
WHERE A salary to u 2000 AND 4000;
bia BETWEEN
o n i2o 3
nt COUNT(*)
e A ----------
J o s 5636096
Elapsed: 00:00:17.14
SQL> SELECT COUNT (*)
FROM myemp
WHERE salary>4000;
2 3
COUNT(*)
----------
8388608
Elapsed: 00:00:18.12
SQL>
23) How would you rewrite the statements found in multiple1.sql script for better
performance?
SQL> @multiple2
SQL> SELECT COUNT (CASE WHEN salary < 2000
2 THEN 1 ELSE null END) count1,
Elapsed: 00:00:18.19
SQL>
a@ this
Common_Mistakes]$
b i
i a (ja use
--------------------------------------------------------------
A b
#!/bin/bash to
o
ni /home/oracle/solutions/Common_Mistakes
ntocd
e A
J o s export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
STREAM_NUM=0
MAX_STREAM=500
date
# one more
let STREAM_NUM="STREAM_NUM+1"
done
date
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
26) Analyze the bad_connect.sh script and try to find a better solution to enhance
the performance of that application. Test your solution. You should discuss this with
your instructor. n s e
i ce
b l el
[oracle@edrsr33p1-orcl Common_Mistakes]$ ./better_connect.sh
fe r a
Wed Mar 26 22:00:48 GMT-7 2008
a n s
-tr
Wed Mar 26 22:00:50 GMT-7 2008
[oracle@edrsr33p1-orcl Common_Mistakes]$
o n
s an
--------------------------------------------------------------
) h a deฺ
#!/bin/bash
r ฺ e s Gui
p ฺ mi dent
cd /home/oracle/solutions/Common_Mistakes
d g Stu
i a@ this
export ORACLE_SID=orcl
b
i a (ja use
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
A b to
ni o
export
ntoPATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
e A l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
J o s
date
date
--------------------------------------------------------------
declare
c number;
begin
for i in 1..500 loop
select count(*) into c from dba_users;
end loop;
end;
/
exit;
2008
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
n s e
i ce
SQL> SQL> SQL> SQL>
b l el
User dropped.
f er a
SQL> SQL> Disconnected from Oracle Database 11g Enterprise s
an Edition
- t r
on Data Mining
Release 11.1.0.6.0 - Production
n
With the Partitioning, Oracle Label Security, OLAP,
a
[oracle@edrsr33p1-orcl Common_Mistakes]$as
and Real Application Testing options
) h i d eฺ
i r ฺes nt Gu
--------------------------------------------------------------
g p ฺm ude
#!/bin/bash d S t
@ s
a b ia
e thi
cd /home/oracle/solutions/Common_Mistakes
j
b ia ( to us
o AORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export ORACLE_SID=orcl
n i
ntoexport
e A
J o s export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
set echo on
EOF
n s e
i ce
b l el
fer a
a n s
n -tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
J o s SQL>
SQL> alter user sh identified by sh account unlock;
User altered.
SQL>
SQL> connect sh/sh
Connected.
SQL>
SQL> ALTER SESSION SET TRACEFILE_IDENTIFIER = 'MYOPTIMIZER';
Session altered.
SQL>
SQL> alter session set events '10053 trace name context forever,
level 1';
Session altered.
SQL>
no rows selected
SQL>
SQL> exit
n s e
Disconnected from Oracle Database 11g Enterprise Edition Release
ice
11.1.0.6.0 - Production
b l el
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
fe ra
orcl_ora_1801_MYOPTIMIZER.trc
a n s
orcl_ora_1801_MYOPTIMIZER.trm
o n -tr
aandn interpret the important
[oracle@edrsr33p1-orcl Trace_Event]$
2) With the help of your instructor, see the generatedatraces eฺ purposes. Do not use it
hdemonstration
)
parts of the trace file. Note: This lab is onlysfor u i d
i
on your production system unless explicitly r ฺe askedt G
by Oracle Support Services.
a) The 10053 trace output is g p ฺmdownudinto
broken
ena number of sections that broadly
t through in evaluating a plan. These
doptimizerSgoes
@
reflect the stages that the i s
ia query,thparameters
( a b
stages are asjfollows: e used by the optimizer, base statistical
ia to
information, base u s
table access cost, join order and method computations,
b
A for special features, such as query transformations.
n i orecosting
to[oracle@edrsr33p1-orcl Trace_Event]$ cat myoptimizer.trc
e An
Jos Trace file
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_32643_MYOPTIMIZE
R.trc
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.1.0/db_1
System name: Linux
Node name: edrsr33p1.us.oracle.com
Release: 2.6.9-55.0.0.0.2.ELsmp
Version: #1 SMP Wed May 2 14:59:56 PDT 2007
Machine: i686
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 18
Unix process pid: 32643, image: [email protected] (TNS
V1-V3)
A b
s.cust_id AND
nt
e A ch.channel_desc IN ('Internet','Catalog') AND
J o s t.calendar_quarter_desc IN ('1999-Q1','1999-Q2')
GROUP BY ch.channel_class, c.cust_city, t.calendar_quarter_desc
*******************************************
Legend
The following abbreviations are used by optimizer trace.
CBQT - cost-based query transformation
JPPD - join predicate push-down
OJPPD - old-style (non-cost-based) JPPD
FPD - filter push-down
PM - predicate move-around
CVM - complex view merging
SPJ - select-project-join
SJC - set join conversion
SU - subquery unnesting
OBYE - order by elimination
ST - star transformation
CNT - count(col) to count(*) transformation
JE - Join Elimination
qb - query block
LB - leaf blocks
DK - distinct keys
J o s ******************************
Compilation Environment Dump
_smm_min_size = 204 KB
_smm_max_size = 40960 KB
_smm_px_max_size = 102400 KB
Bug Fix Control Environment
*************************************
PARAMETERS WITH DEFAULT VALUES
******************************
Compilation Environment Dump
optimizer_mode_hinted = false
optimizer_features_hinted = 0.0.0
parallel_execution_enabled = true
parallel_query_forced_dop = 0
parallel_dml_forced_dop = 0
parallel_ddl_forced_degree = 0
parallel_ddl_forced_instances = 0
_query_rewrite_fudge = 90
optimizer_features_enable = 11.1.0.6
optimizer_use_invisible_indexes = false
flashback_data_archive_internal_cursor = 0
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
_optimizer_extended_stats_usage_control = 240
Bug Fix Control Environment
fix 3834770 = 1
fix 3746511 = enabled
fix 4519016 = enabled
fix 3118776 = enabled
fix 4488689 = enabled
fix 2194204 = disabled
…
fix 6133948 = enabled
n s e
fix 6239909 = enabled
i ce
b l el
***************************************
fer a
PARAMETERS IN OPT_PARAM HINT
a n s
****************************
o n -tr
an
***************************************
Column Usage Monitoring is ON: tracking level = 1
***************************************
h s
a deฺ
e )
s Gui
r ฺ
i on equery
nt block SEL$1 (#0)
ฺ
Considering Query Transformations
p m d
**************************
d g Stu
Query transformations
b i a@ this
**************************
(QT)
CBQT: Validity
i a (jachecks
u sepassed for 70fqjd9u1zk7c.
SEL$1 A
b
CSE: Considering
tocommon sub-expression elimination in query block
o n io (#0)
*************************
nt Common Subexpression elimination (CSE)
e A
J o s *************************
CSE: CSE not performed on query block SEL$1 (#0).
OBYE: Considering Order-by Elimination from view SEL$1 (#0)
***************************
Order-by elimination (OBYE)
***************************
OBYE: OBYE bypassed: no order by to eliminate.
JE: Considering Join Elimination on query block SEL$1 (#0)
*************************
Join Elimination (JE)
*************************
SQL:******* UNPARSED QUERY IS *******
SELECT "CH"."CHANNEL_CLASS" "CHANNEL_CLASS","C"."CUST_CITY"
"CUST_CITY","T"."CALENDAR_QUARTER_DESC"
"CALENDAR_QUARTER_DESC",SUM("S"."AMOUNT_SOLD") "SALES_AMOUNT" FROM
"SH"."SALES" "S","SH"."TIMES" "T","SH"."CUSTOMERS"
"C","SH"."CHANNELS" "CH" WHERE "S"."TIME_ID"="T"."TIME_ID" AND
"S"."CUST_ID"="C"."CUST_ID" AND "S"."CHANNEL_ID"="CH"."CHANNEL_ID"
AND "C"."CUST_STATE_PROVINCE"='CA' AND
("CH"."CHANNEL_DESC"='Internet' OR "CH"."CHANNEL_DESC"='Catalog')
AND ("T"."CALENDAR_QUARTER_DESC"='1999-Q1' OR
*************************
CNT: COUNT() to COUNT(*) not done.
JE: Considering Join Elimination on query block SEL$1 (#0)
*************************
Join Elimination (JE)
*************************
SQL:******* UNPARSED QUERY IS *******
SELECT "CH"."CHANNEL_CLASS" "CHANNEL_CLASS","C"."CUST_CITY"
"CUST_CITY","T"."CALENDAR_QUARTER_DESC"
"CALENDAR_QUARTER_DESC",SUM("S"."AMOUNT_SOLD") "SALES_AMOUNT" FROM
n s e
"SH"."SALES" "S","SH"."TIMES" "T","SH"."CUSTOMERS"
i ce
"C","SH"."CHANNELS" "CH" WHERE "S"."TIME_ID"="T"."TIME_ID" AND
b l el
"S"."CUST_ID"="C"."CUST_ID" AND "S"."CHANNEL_ID"="CH"."CHANNEL_ID"
AND "C"."CUST_STATE_PROVINCE"='CA' AND
fer a
n s
("CH"."CHANNEL_DESC"='Internet' OR "CH"."CHANNEL_DESC"='Catalog')
a
AND ("T"."CALENDAR_QUARTER_DESC"='1999-Q1' OR
n -tr
o
an
"T"."CALENDAR_QUARTER_DESC"='1999-Q2') GROUP BY
"CH"."CHANNEL_CLASS","C"."CUST_CITY","T"."CALENDAR_QUARTER_DESC"
Query block SEL$1 (#0) unchanged
h s
a deฺ
query block SEL$1 (#0) unchanged
e )
s Gui
r ฺ
mi dent
Considering Query Transformations on query block SEL$1 (#0)
**************************
p ฺ
g Stu
d
Query transformations (QT)
b i a@ this
**************************
CSE: Considering common sub-expression elimination in query block
SEL$1 (#0)
i a (ja use
b to
*************************
A
o n io
Common Subexpression elimination (CSE)
*************************
nt
e A CSE: CSE not performed on query block SEL$1 (#0).
*******************************************
Peeked values of the binds in SQL statement
*******************************************
***************************
OBYE: OBYE bypassed: no order by to eliminate.
Considering Query Transformations on query block SEL$1 (#0)
**************************
Query transformations (QT)
**************************
CSE: Considering common sub-expression elimination in query block
SEL$1 (#0)
*************************
Common Subexpression elimination (CSE)
n s e
*************************
i ce
CSE: CSE not performed on query block SEL$1 (#0).
b l el
kkqctdrvTD-start on query block SEL$1 (#0)
kkqctdrvTD-start: :
fer a
n
call(in-use=62016, alloc=81864), compile(in-use=105980,
a s
alloc=109196), execution(in-use=3376, alloc=4060)
o n -tr
kkqctdrvTD-cleanup: transform(in-use=0, alloc=0)
s an:
h a deฺ
call(in-use=62016, alloc=81864), compile(in-use=106488,
alloc=109196), execution(in-use=3376,) alloc=4060)
r ฺ e s Gui
kkqctdrvTD-end: ฺ m i ent
d g p
call(in-use=62016, alloc=81864),
t u d compile(in-use=106808,
a@ this S
alloc=109196), execution(in-use=3376, alloc=4060)
b i
i a (ja set-join
SJC: Considering
u se conversion in query block SEL$1 (#1)
to (SJC)
b Conversion
*************************
A
i o
Set-Join
n
nto*************************
e A SJC: not performed
n s e
kkqctdrvTD-end:
i ce
call(in-use=81660, alloc=98240), compile(in-use=110304,
b l el
alloc=113320), execution(in-use=3376, alloc=4060)
fer a
kkqctdrvTD-start on query block SEL$1 (#1)
a n s
kkqctdrvTD-start: :
o n -tr
an
call(in-use=81660, alloc=98240), compile(in-use=110304,
alloc=113320), execution(in-use=3376, alloc=4060)
h s
a deฺ
Registered qb: SEL$1 0xb7e01c6c (COPY) SEL$1)
r ฺ e s Gui
---------------------
QUERY BLOCK SIGNATURE ฺ m i ent
---------------------
d g p t u d
signature(): NULL @
a is S
b i t h
***********************************
(ja ByuPlacement
Cost-Based Group
i a se
b to
***********************************
A
n i o
GBP: Checking validity of GBP for query block SEL$1 (#1)
nto(#1)
GBP: Checking validity of group-by placement for query block SEL$1
e A
J o s GBP: Bypassed: QB has disjunction.
kkqctdrvTD-cleanup: transform(in-use=9008, alloc=9460) :
call(in-use=81684, alloc=98240), compile(in-use=129100,
alloc=132448), execution(in-use=3376, alloc=4060)
kkqctdrvTD-end:
call(in-use=81684, alloc=98240), compile(in-use=119884,
alloc=132448), execution(in-use=3376, alloc=4060)
kkqctdrvTD-end:
call(in-use=81708, alloc=98240), compile(in-use=123428,
alloc=132448), execution(in-use=3376, alloc=4060)
an
AND "S"."CHANNEL_ID"="CH"."CHANNEL_ID" AND
"C"."CUST_STATE_PROVINCE"='CA' AND ("CH"."CHANNEL_DESC"='Internet'
OR "CH"."CHANNEL_DESC"='Catalog') AND
h s
a deฺ
)
s Gui
("T"."CALENDAR_QUARTER_DESC"='1999-Q1' OR "T"."C
e
r ฺ
kkoqbc: optimizing query block
p ฺ miSEL$1de(#1)
nt
d g Stu
:
b i
call(in-use=81716, a@ alloc=98240),
t h is compile(in-use=124640,
alloc=132448),( j a s e
execution(in-use=3376, alloc=4060)
b i a to u
i o A
kkoqbc-subheap (create addr=0xb7d47960)
n
toQUERY BLOCK TEXT
****************
A n
o s e ****************
J SELECT ch.channel_class, c.cust_city, t.calendar_quarter_desc,
SUM(s.amount_sold) sales_amount
FROM sh.sales s,sh.times t,sh.customers c,sh.channels ch
WHERE s.time_id = t.time_id AND
s.cust_id = c.cust_id AND
s.channel_id = ch.channel_id
---------------------
QUERY BLOCK SIGNATURE
---------------------
signature (optimizer): qb_name=SEL$1 nbfros=4 flg=0
fro(0): flg=0 objn=72254 hint_alias="C"@"SEL$1"
fro(1): flg=0 objn=72252 hint_alias="CH"@"SEL$1"
fro(2): flg=0 objn=72192 hint_alias="S"@"SEL$1"
fro(3): flg=0 objn=72250 hint_alias="T"@"SEL$1"
-----------------------------
SYSTEM STATISTICS INFORMATION
-----------------------------
Using NOWORKLOAD Stats
CPUSPEED: 1263 millions instructions/sec
***************************************
BASE STATISTICAL INFORMATION
***********************
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Table Stats::
Table: CHANNELS Alias: CH
#Rows: 5 #Blks: 4 AvgRowLen: 40.00
Index Stats::
Index: CHANNELS_PK Col#: 1
LVLS: 0 #LB: 1 #DK: 5 LB/K: 1.00 DB/K: 1.00 CLUF: 1.00
***********************
Table Stats::
Table: CUSTOMERS Alias: C
#Rows: 55500 #Blks: 1486 AvgRowLen: 180.00
n s e
Index Stats::
i ce
Index: CUSTOMERS_GENDER_BIX Col#: 4
b l el
LVLS: 1 #LB: 3 #DK: 2 LB/K: 1.00 DB/K: 2.00 CLUF: 5.00
Index: CUSTOMERS_MARITAL_BIX Col#: 6
fer a
LVLS: 1 #LB: 5 #DK: 11 LB/K: 1.00 DB/K: 1.00 CLUF: 18.00
a n s
Index: CUSTOMERS_PK Col#: 1
n -tr
o
an
LVLS: 1 #LB: 115 #DK: 55500 LB/K: 1.00 DB/K: 1.00 CLUF:
54405.00
Index: CUSTOMERS_YOB_BIX Col#: 5
h s
a deฺ
)
s Gui
LVLS: 1 #LB: 19 #DK: 75 LB/K: 1.00 DB/K: 1.00 CLUF: 75.00
e
r ฺ
mi dent
***********************
Table Stats::
p ฺ
g Stu
Table: TIMES Alias: T
d
Index Stats:: b i a@ this
#Rows: 1826 #Blks: 59 AvgRowLen: 197.00
i a (ja use
Index: TIMES_PK Col#: 1
b to
LVLS: 1 #LB: 5 #DK: 1826 LB/K: 1.00 DB/K: 1.00 CLUF: 53.00
A
o n io
***********************
Table Stats::
nt
e A Table: SALES Alias: S (Using composite stats)
b i a@ this
ix_sel: 1.000000 ix_sel_with_filters: 1.000000
Cost: 58.03 Resp: 58.03 Degree: 0
i a (ja use
Access Path: index (FullScan)
b to
Index: SALES_TIME_BIX
A
o n io
resc_io: 60.00 resc_cpu: 719286
ix_sel: 1.000000 ix_sel_with_filters: 1.000000
nt
e A Cost: 60.05 Resp: 60.05 Degree: 0
n s e
Access path analysis for CUSTOMERS
i ce
***************************************
b l el
SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for CUSTOMERS[C]
fer a
Table: CUSTOMERS Alias: C
a n s
-tr
Card: Original: 55500.000000 Rounded: 383 Computed: 382.76
n
o
an
Non Adjusted: 382.76
Access Path: TableScan
Cost: 406.16 Resp: 406.16 Degree: 0
h s
a deฺ
Cost_io: 404.00 Cost_cpu: 32782460
e )
s Gui
r ฺ
mi dent
Resp_io: 404.00 Resp_cpu: 32782460
p ฺ
****** trying bitmap/domain indexes ******
g Stu
d
Access Path: index (FullScan)
b i a@ this
Index: CUSTOMERS_GENDER_BIX
resc_io: 4.00 resc_cpu: 29486
i a (ja use
ix_sel: 1.000000 ix_sel_with_filters: 1.000000
b to
Cost: 4.00 Resp: 4.00 Degree: 0
A
o n io
Access Path: index (FullScan)
Index: CUSTOMERS_MARITAL_BIX
nt
e A resc_io: 6.00 resc_cpu: 46329
***************************************
SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for CHANNELS[CH]
Table: CHANNELS Alias: CH
Card: Original: 5.000000 Rounded: 2 Computed: 2.00 Non
Adjusted: 2.00
Access Path: TableScan
Cost: 3.00 Resp: 3.00 Degree: 0
Cost_io: 3.00 Cost_cpu: 29826
Resp_io: 3.00 Resp_cpu: 29826
n s e
****** trying bitmap/domain indexes ******
i ce
Access Path: index (FullScan)
b l el
Index: CHANNELS_PK
resc_io: 1.00 resc_cpu: 8121
fe r a
ix_sel: 1.000000 ix_sel_with_filters: 1.000000
a n s
Cost: 1.00 Resp: 1.00 Degree: 0
n - tr
o
an
****** finished trying bitmap/domain indexes ******
Best:: AccessPath: TableScan
h s
a deฺ
Cost: 3.00 Degree: 1 Resp: 3.00 Card: 2.00 Bytes: 0
e )
s Gu2 i
r ฺ
i ent 286
Grouping column cardinality [CHANNEL_CL]
Grouping column cardinality ฺ[mCUST_CITY]
d g
Grouping column cardinalityp t u d
[CALENDAR_Q] 2
a@ this S
***************************************
b i
i a (ja usANDe
A b
OPTIMIZER
to
STATISTICS COMPUTATIONS
o n io PLANS
***************************************
GENERAL
nt ***************************************
e A
J o s Considering cardinality-based initial join order.
Permutations for Starting Table :0
Join order[1]: CHANNELS[CH]#0 TIMES[T]#1 CUSTOMERS[C]#2
SALES[S]#3
***************
Now joining: TIMES[T]#1
***************
NL Join
Outer table: Card: 2.00 Cost: 3.00 Resp: 3.00 Degree: 1 Bytes:
21
Access path analysis for TIMES
Inner table: TIMES Alias: T
Access Path: TableScan
NL Join: Cost: 37.31 Resp: 37.31 Degree: 1
Cost_io: 37.00 Cost_cpu: 4659106
Resp_io: 37.00 Resp_cpu: 4659106
****** trying bitmap/domain indexes ******
Access Path: index (FullScan)
Index: TIMES_PK
resc_io: 6.00 resc_cpu: 407929
n s e
***************
i ce
Now joining: CUSTOMERS[C]#2
b l el
***************
NL Join
fer a
n
Outer table: Card: 365.20 Cost: 37.31 Resp: 37.31 Degree: 1
a s
Bytes: 37
n -tr
o
an
Access path analysis for CUSTOMERS
Inner table: CUSTOMERS Alias: C
Access Path: TableScan
h s
a deฺ
)
s Gui
NL Join: Cost: 147725.92 Resp: 147725.92 Degree: 1
e
r ฺ
mi dent
Cost_io: 146936.00 Cost_cpu: 11970256947
p ฺ
Resp_io: 146936.00 Resp_cpu: 11970256947
g Stu
d
****** trying bitmap/domain indexes ******
b i a@ this
Access Path: index (FullScan)
Index: CUSTOMERS_GENDER_BIX
i a (ja use
resc_io: 4.00 resc_cpu: 29486
b to
ix_sel: 1.000000 ix_sel_with_filters: 1.000000
A
o n io
Cost: 4.00 Resp: 4.00 Degree: 0
Access Path: index (FullScan)
nt
e A Index: CUSTOMERS_MARITAL_BIX
p ฺ
NL Join: Cost: 2625413.78 Resp: 2625413.78 Degree: 1
g Stu
d
Cost_io: 2538743.82 Cost_cpu: 1313377131608
b i a@ this
Resp_io: 2538743.82 Resp_cpu: 1313377131608
****** trying bitmap/domain indexes ******
i a (ja use
Access Path: index (AllEqJoinGuess)
b to
Index: SALES_CHANNEL_BIX
A
o n io
resc_io: 11.00 resc_cpu: 83786
ix_sel: 0.250000 ix_sel_with_filters: 0.250000
nt
e A NL Join : Cost: 1686111.78 Resp: 1686111.78 Degree: 1
918843 b i a@ this
Blocks to Sort: 3825 Row size: 34 Total Rows:
i a (ja use
Initial runs: 2 Merge passes: 1 IO Cost / pass: 2074
b to
Total IO sort cost: 5899
A
Total CPU sort cost: 929421655
J o s SM cost: 156308.78
resc: 156308.78 resc_io: 155430.00 resc_cpu: 13316903726
resp: 156308.78 resp_io: 155430.00 resp_cpu: 13316903726
Outer table: CUSTOMERS Alias: C
resc: 147725.92 card 139783.45 bytes: 63 deg: 1 resp:
147725.92
Inner table: SALES Alias: S
resc: 498.20 card: 918843.00 bytes: 21 deg: 1 resp: 498.20
using dmeth: 2 #groups: 1
Cost per ptn: 1944.36 #ptns: 1
hash_area: 124 (max=10240) buildfrag: 1280 probefrag: 3702
ppasses: 1
Hash join: Resc: 150168.48 Resp: 150168.48 [multiMatchCost=0.00]
HA Join
HA cost: 150168.48
resc: 150168.48 resc_io: 149346.00 resc_cpu: 12463693737
resp: 150168.48 resp_io: 149346.00 resp_cpu: 12463693737
GROUP BY sort
GROUP BY adjustment factor: 0.500000
GROUP BY cardinality: 572.000000, TABLE cardinality: 3116.000000
SORT ressource Sort statistics
b i a@ this
Inner table: SALES Alias: S
Access Path: TableScan
i a (ja use
NL Join: Cost: 6507.09 Resp: 6507.09 Degree: 1
b to
n
…
i oA
nto***********************
e A
J o s Join order[22]:
CHANNELS[CH]#0
SALES[S]#3 CUSTOMERS[C]#2 TIMES[T]#1
***************
Now joining: TIMES[T]#1
***************
NL Join
Outer table: Card: 49822.22 Cost: 910.93 Resp: 910.93 Degree: 1
Bytes: 47
Access path analysis for TIMES
Inner table: TIMES Alias: T
Access Path: TableScan
NL Join: Cost: 804636.92 Resp: 804636.92 Degree: 1
Cost_io: 797001.00 Cost_cpu: 115712978623
Resp_io: 797001.00 Resp_cpu: 115712978623
Access Path: index (UniqueScan)
Index: TIMES_PK
resc_io: 1.00 resc_cpu: 10059
ix_sel: 0.000548 ix_sel_with_filters: 0.000548
NL Join : Cost: 50766.00 Resp: 50766.00 Degree: 1
Cost_io: 50707.00 Cost_cpu: 894143044
49822 b i a@ this
Blocks to Sort: 379 Row size: 62 Total Rows:
i a (ja use
Initial runs: 2 Merge passes: 1 IO Cost / pass: 206
b to
Total IO sort cost: 585
A
Total CPU sort cost: 59514576
J o s 41943040
Degree: 1
Blocks to Sort: 1 Row size: 28 Total Rows: 183
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 15215743
Total Temp space used: 0
SM join: Resc: 1519.02 Resp: 1519.02 [multiMatchCost=0.00]
SM Join
SM cost: 1519.02
resc: 1519.02 resc_io: 1488.00 resc_cpu: 470031494
resp: 1519.02 resp_io: 1488.00 resp_cpu: 470031494
Outer table: CUSTOMERS Alias: C
resc: 910.93 card 49822.22 bytes: 47 deg: 1 resp: 910.93
Inner table: TIMES Alias: T
resc: 18.15 card: 182.60 bytes: 16 deg: 1 resp: 18.15
using dmeth: 2 #groups: 1
Cost per ptn: 141.09 #ptns: 1
hash_area: 124 (max=10240) buildfrag: 359 probefrag: 1
ppasses: 1
Hash join: Resc: 1070.22 Resp: 1070.22 [multiMatchCost=0.04]
Outer table: TIMES Alias: T
ppasses: 1
Hash join: Resc: 929.92 Resp: 929.92 [multiMatchCost=0.00]
HA Join
HA cost: 929.92 swapped
resc: 929.92 resc_io: 903.00 resc_cpu: 407887714
resp: 929.92 resp_io: 903.00 resp_cpu: 407887714
Best:: JoinMethod: Hash
Cost: 929.92 Degree: 1 Resp: 929.92 Card: 6231.19 Bytes:
63
n s e
***************
i ce
Now joining: CHANNELS[CH]#0
b l el
***************
NL Join
f a
er 1
Outer table: Card: 6231.19 Cost: 929.92 Resp: 929.92
an s
Degree:
Bytes: 63
n -tr
o
an
Access path analysis for CHANNELS
Inner table: CHANNELS Alias: CH
Access Path: TableScan
h s
a deฺ
)
s Gui
NL Join: Cost: 7694.18 Resp: 7694.18 Degree: 1
e
r ฺ
mi dent
Cost_io: 7655.00 Cost_cpu: 593732024
p ฺ
Resp_io: 7655.00 Resp_cpu: 593732024
g Stu
d
Access Path: index (UniqueScan)
Index: CHANNELS_PK
b i a@ this
resc_io: 1.00 resc_cpu: 8451
i a (ja use
ix_sel: 0.200000 ix_sel_with_filters: 0.200000
b to
NL Join : Cost: 7164.39 Resp: 7164.39 Degree: 1
A
o n io Cost_io: 7134.00 Cost_cpu: 460548636
Resp_io: 7134.00 Resp_cpu: 460548636
nt
e A Access Path: index (AllEqUnique)
J o s Index: CHANNELS_PK
resc_io: 1.00 resc_cpu: 8451
ix_sel: 0.200000 ix_sel_with_filters: 0.200000
NL Join : Cost: 7164.39 Resp: 7164.39 Degree: 1
Cost_io: 7134.00 Cost_cpu: 460548636
Resp_io: 7134.00 Resp_cpu: 460548636
****** trying bitmap/domain indexes ******
****** finished trying bitmap/domain indexes ******
1 b i a@ this
hash_area: 124 (max=10240) buildfrag: 58 probefrag: 1 ppasses:
i a (ja use
Hash join: Resc: 933.50 Resp: 933.50 [multiMatchCost=0.02]
b to
Outer table: CHANNELS Alias: CH
A
o n io
resc: 3.00 card 2.00 bytes: 21 deg: 1 resp: 3.00
Inner table: TIMES Alias: T
nt
e A resc: 929.92 card: 6231.19 bytes: 63 deg: 1 resp: 929.92
*********************************
Number of join permutations tried: 22
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
*********************************
(newjo-save) [1 3 2 0 ]
GROUP BY adjustment factor: 0.500000
GROUP BY cardinality: 572.000000, TABLE cardinality: 3116.000000
SORT ressource Sort statistics
Sort width: 238 Area size: 208896 Max Area size:
41943040
Degree: 1
Blocks to Sort: 40 Row size: 103 Total Rows:
3116
n s e
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
i ce
Total IO sort cost: 0 Total CPU sort cost: 16783070
b l el
Total Temp space used: 0
Trying or-Expansion on query block SEL$1 (#1)
fer a
Transfer Optimizer annotations for query block SEL$1 (#1)
a n s
id=0 frofand predicate="C"."CUST_STATE_PROVINCE"='CA'
n -tr
o
an
id=0 frofkksm[i] (sort-merge/hash)
predicate="S"."CUST_ID"="C"."CUST_ID"
h s
a deฺ
id=0 frosand (sort-merge/hash) predicate="S"."CUST_ID"="C"."CUST_ID"
id=0 frofkksm[i] (sort-merge/hash)
e )
s Gui
r ฺ
mi dent
predicate="S"."TIME_ID"="T"."TIME_ID"
p ฺ
id=0 frosand (sort-merge/hash) predicate="S"."TIME_ID"="T"."TIME_ID"
g Stu
d
id=0 frofand predicate="T"."CALENDAR_QUARTER_DESC"='1999-Q1' OR
b i a@ this
"T"."CALENDAR_QUARTER_DESC"='1999-Q2'
id=0 frofkksm[i] (sort-merge/hash)
i a (ja use
predicate="S"."CHANNEL_ID"="CH"."CHANNEL_ID"
b to
id=0 frosand (sort-merge/hash)
A
o n io
predicate="S"."CHANNEL_ID"="CH"."CHANNEL_ID"
id=0 frofand predicate="CH"."CHANNEL_DESC"='Catalog' OR
nt
e A "CH"."CHANNEL_DESC"='Internet'
J o s ----------------------------------------------------+---------------
--------------------+---------------+
| 0 | SELECT STATEMENT | | |
| 935 | | | |
| 1 | HASH GROUP BY | | 572 | 47K
| 935 | 00:00:12 | | |
| 2 | HASH JOIN | | 3116 | 256K
| 933 | 00:00:12 | | |
| 3 | TABLE ACCESS FULL | CHANNELS | 2 | 42
| 3 | 00:00:01 | | |
| 4 | HASH JOIN | | 6231 | 383K
| 930 | 00:00:12 | | |
| 5 | PART JOIN FILTER CREATE | :BF0000 | 183 | 2928
| 18 | 00:00:01 | | |
| 6 | TABLE ACCESS FULL | TIMES | 183 | 2928
| 18 | 00:00:01 | | |
| 7 | HASH JOIN | | 49K | 2287K
| 911 | 00:00:11 | | |
| 8 | TABLE ACCESS FULL | CUSTOMERS| 383 | 9958
| 406 | 00:00:05 | | |
Predicate Information:
----------------------
2 - access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
3 - filter(("CH"."CHANNEL_DESC"='Catalog' OR
"CH"."CHANNEL_DESC"='Internet'))
4 - access("S"."TIME_ID"="T"."TIME_ID")
6 - filter(("T"."CALENDAR_QUARTER_DESC"='1999-Q1' OR
"T"."CALENDAR_QUARTER_DESC"='1999-Q2'))
7 - access("S"."CUST_ID"="C"."CUST_ID")
8 - filter("C"."CUST_STATE_PROVINCE"='CA')
n s e
i ce
Content of other_xml column
b l el
===========================
db_version : 11.1.0.6
fer a
parse_schema : SH
a n s
plan_hash : 1647000731
n -tr
o
an
plan_hash_2 : 94088042
Outline Data:
/*+
h s
a deฺ
BEGIN_OUTLINE_DATA
e )
s Gui
r ฺ
mi dent
IGNORE_OPTIM_EMBEDDED_HINTS
p ฺ
OPTIMIZER_FEATURES_ENABLE('11.1.0.6')
g Stu
d
DB_VERSION('11.1.0.6')
ALL_ROWS
b i a@ this
OUTLINE_LEAF(@"SEL$1")
i a (ja use
FULL(@"SEL$1" "C"@"SEL$1")
b to
FULL(@"SEL$1" "S"@"SEL$1")
A
o n io FULL(@"SEL$1" "T"@"SEL$1")
FULL(@"SEL$1" "CH"@"SEL$1")
nt
e A LEADING(@"SEL$1" "C"@"SEL$1" "S"@"SEL$1" "T"@"SEL$1"
J o s "CH"@"SEL$1")
USE_HASH(@"SEL$1" "S"@"SEL$1")
USE_HASH(@"SEL$1" "T"@"SEL$1")
USE_HASH(@"SEL$1" "CH"@"SEL$1")
SWAP_JOIN_INPUTS(@"SEL$1" "T"@"SEL$1")
SWAP_JOIN_INPUTS(@"SEL$1" "CH"@"SEL$1")
USE_HASH_AGGREGATION(@"SEL$1")
END_OUTLINE_DATA
*/
n s e
Query Block Registry:
i ce
SEL$1 0xb7e0905c (PARSER) [FINAL]
b l el
:
fe r a
call(in-use=143844, alloc=246544), compile(in-use=166732,
a n s
alloc=224788), execution(in-use=13796, alloc=16288)
o n -tr
End of Optimizer State Dump n
a ======================
====================== END SQL StatementaDump s eฺ
[oracle@edrsr33p1-orcl Trace_Event]$ ) h i d
i r ฺes nt Gu
3) Execute the te_cleanup.sh g p ฺm clean
script totu deup your environment for this lab.
d S ./te_cleanup.sh
@ Trace_Event]$
i a i s
ab se th
[oracle@edrsr33p1-orcl
SQL*Plus:ia
( j u
A b t o
Release 11.1.0.6.0 - Production on Wed Apr 9 22:18:01 2008
o n io
Copyright (c) 1982, 2007, Oracle. All rights reserved.
t
e An
Jos Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Trace_Event]$
n s e
i ce
b l el
fer a
a n s
n -tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
1) Case 1: Connected as the oracle user from a terminal session, execute the
ap_setup.sh script.
[oracle@edrsr33p1-orcl Access_Paths]$ ./ap_setup.sh
2) In the same terminal session, connect as the SH user in the SQL*Plus session.
[oracle@edrsr33p1-orcl Access_Paths]$ sqlplus sh/sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
SQL>
SQL> create table mysales as select * from sh.sales;
Table created.
n s e
i ce
SQL>
b l el
SQL> insert into mysales select * from mysales;
fe r a
a n s
918843 rows created.
n - tr
o
an
SQL> commit;
Commit complete. h s
a deฺ
e )
s Gui
r ฺ
SQL>
SQL>
p ฺ mi dent
d
SQL> insert into mysales gselectS*tufrom mysales;
b i a@ this
(ja use
1837686 rows created.
b i a to
A
SQL> commit;
o
ni complete.
toCommit
A n
o s e SQL>
J SQL> insert into mysales select * from mysales;
SQL> commit;
Commit complete.
SQL>
SQL> insert into mysales select * from mysales;
SQL> commit;
Commit complete.
SQL>
SQL> insert into mysales select * from mysales;
SQL> commit;
Commit complete.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> insert into mysales values (0,0,sysdate,0,0,0,0);
1 row created.
SQL> commit;
Commit complete.
SQL>
n s e
SQL> exec dbms_stats.gather_schema_stats('SH');
ice
b l el
PL/SQL procedure successfully completed.
fe ra
SQL>
a n s
o n
4) Set up your session with the following commands: set timing on, set
-tr
an
autotrace trace only, and set linesize 200. After this, execute the
s
h a deฺ
select * from mysales where prod_id=0; query. What do you observe?
)
r ฺ e s Gtable. ui
p ฺ mi dent
a) Basically, there are no indexes on the MYSALES
b) .The only possibility ford goptimizer
the
S tuis to use the full table scan to retrieve only
one row. You can a see@ s takes a long time.
that the iscan
b i t h
i a (jaon use
SQL> @with_and_without_index
SQL> set
SQL> A
b echo
to
o
ni set timing on
ntoSQL>
e A SQL> set autotrace traceonly
System altered.
Elapsed: 00:00:00.61
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:15.04
SQL>
SQL> select * from mysales where prod_id=0;
Elapsed: 00:00:28.85
Execution Plan
----------------------------------------------------------
Plan hash value: 3597614299
n s e
1 - filter("PROD_ID"=0)
i ce
b l el
Statistics
fe r a
----------------------------------------------------------
a n s
421 recursive calls
n - tr
o
an
0 db block gets
141606 consistent gets
141529 physical reads
h s
a deฺ
0 redo size
e )
s Gui
r ฺ
mi dent
790 bytes sent via SQL*Net to client
p ฺ
420 bytes received via SQL*Net from client
g Stu
d
2 SQL*Net roundtrips to/from client
b i a@ this
5 sorts (memory)
0 sorts (disk)
i a (ja use
1 rows processed
Ab to
o n io
SQL>
SQL> set timing off
nt
e A SQL> set autotrace off
J o s SQL>
5) How do you enhance the performance of the query in step 4? Implement your
solution.
SQL> @create_mysales_index
SQL> set echo on
SQL>
SQL> create index mysales_prodid_idx on mysales(prod_id) nologging
compute statistics;
Index created.
SQL>
6) Execute the same query again and verify that performance is enhanced now.
a) After implementing the index, the optimizer can use it to speed up the query
execution time. You can see a dramatic improvement in performance.
SQL> @with_and_without_index
SQL> set echo on
System altered.
Elapsed: 00:00:00.29
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:01.71
SQL>
n s e
SQL> select * from mysales where prod_id=0;
i ce
b l el
Elapsed: 00:00:00.88
fer a
Execution Plan
a n s
o n -tr
----------------------------------------------------------
an
Plan hash value: 3009203711
h s
a deฺ
--------------------------------------------------------------------
------------------------------
e )
s| NameGui
Bytes | Cost (%CPU)| Time ฺm|i
| Id | Operation r ฺ n t | Rows |
d g p tude
--------------------------------------------------------------------
i a @ his S |
------------------------------
|
11M| 6079 (j(1)|ab 00:01:13
0 | SELECT STATEMENT
e t | | 402K|
a ACCESS
1 | biTABLE u sBY INDEX ROWID| MYSALES
|
11M| A
o
t 00:01:13 | | 402K|
o n
|* io2 | INDEX RANGE SCAN
6079 (1)|
| MYSALES_PRODID_IDX | 402K|
nt | 822 (1)| 00:00:10 |
e A
J o s --------------------------------------------------------------------
------------------------------
2 - access("PROD_ID"=0)
Statistics
----------------------------------------------------------
496 recursive calls
0 db block gets
104 consistent gets
21 physical reads
0 redo size
794 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
SQL>
SQL> set timing off
SQL> set autotrace off
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Table dropped.
n s e
ce
SQL>
SQL>
eli
b l
8) Case 2: Drop all indexes currently created on the CUSTOMERS table except its
f e ra
primary key index.
t r a ns
SQL> @drop_customers_indexes
o n -
SQL> set termout off
s an
SQL>
) h a deฺ
ฺ e s Gui
--------------------------------------------------------------
r
p ฺ mi dent
set termout off
store set sqlplus_settings d g replace
S tu
buffer.sqlia @ his
save
timingja b replace
e t off verify off autotrace off feedback off
set
( off
s
heading
bia to u
spool Adait.sql
o n io
t SELECT 'drop index '||i.index_name||';'
e An FROM user_indexes i
Jos WHERE
AND
i.table_name = 'CUSTOMERS'
NOT EXISTS
(SELECT 'x'
FROM user_constraints c
WHERE c.index_name = i.index_name
AND c.table_name = i.table_name
AND c.status = 'ENABLED');
spool off
@dait
A b to
--------------------------------------------------------------------
i o
to|n Id | Operation
-----------
| Name | Rows | Bytes | Cost (%CPU)|
A n Time |
o s e --------------------------------------------------------------------
J -----------
| 0 | SELECT STATEMENT | | 6 | 1080 | 407 (1)|
00:00:05 |
|* 1 | TABLE ACCESS FULL| CUSTOMERS | 6 | 1080 | 407 (1)|
00:00:05 |
--------------------------------------------------------------------
-----------
1 - filter(TO_NUMBER("CUST_POSTAL_CODE")=40804 AND
"CUST_CREDIT_LIMIT"=10000 AND "CUST_GENDER"='M')
Statistics
----------------------------------------------------------
1067 recursive calls
0 db block gets
1722 consistent gets
0 sorts (disk)
6 rows processed
SQL>
SQL> set timing off
SQL> set autotrace off
SQL>
10) Create three B*-tree indexes on the following CUSTOMERS table columns:
cust_gender
n s e
cust_postal_code i ce
cust_credit_limit
b l el
fe ra
SQL> @create_cust_gender_index
a n s
SQL>
SQL>
set echo on
n - tr
o
an
SQL> CREATE INDEX cust_cust_gender_idx
2
3
ON customers(cust_gender)
NOLOGGING COMPUTE STATISTICS; h s
a deฺ
e )
s Gui
r ฺ
Index created.
p ฺ mi dent
SQL> d g Stu
SQL> set echo onbi
a@ this
SQL> @create_cust_postal_code_index
SQL>
i a (ja use
A b INDEXtocust_cust_postal_code_idx
SQL> CREATE
n o
i3 NOLOGGING
2 ON customers(cust_postal_code)
nt o COMPUTE STATISTICS;
e A
J o s Index created.
SQL>
SQL> @create_cust_credit_limit_index
SQL> set echo on
SQL>
SQL> CREATE INDEX cust_cust_credit_limit_idx
2 ON customers(cust_credit_limit)
3 NOLOGGING COMPUTE STATISTICS;
Index created.
SQL>
SQL> @list_customers_indexes
SQL> set echo on
SQL> set linesize 200 pagesize 1000
SQL>
SQL> SELECT ui.table_name
2 , decode(ui.index_type
3 ,'NORMAL', ui.uniqueness
4 ,ui.index_type) AS index_type
TABLE_NAME INDEX_TYPE
INDEX_NAME
------------------------------ --------------------------- ---------
---------------------
CUSTOMERS UNIQUE
CUSTOMERS_PK
CUSTOMERS NONUNIQUE
CUST_CUST_GENDER_IDX
CUSTOMERS NONUNIQUE
CUST_CUST_CREDIT_LIMIT_IDX
n s e
CUSTOMERS NONUNIQUE
i ce
CUST_CUST_POSTAL_CODE_IDX
b l el
SQL>
fe ra
a n s
11) Start monitoring all the CUSTOMERS indexes.
o n -tr
SQL> @start_monitoring_indexes
s an
SQL> set echo on
) h a deฺ
ui
SQL>
r ฺ
SQL> ALTER INDEX CUSTOMERS_PK MONITORINGe s USAGE;
G
p ฺ mi dent
Index altered.
d g Stu
SQL>
b i a@ this
( j
SQL> ALTER INDEXa s e
CUST_CUST_POSTAL_CODE_IDX MONITORING USAGE;
bia to u
Index A
altered.
o n io
nt SQL>
e A SQL> ALTER INDEX CUST_CUST_GENDER_IDX MONITORING USAGE;
J o s
Index altered.
SQL>
SQL> ALTER INDEX CUST_CUST_CREDIT_LIMIT_IDX MONITORING USAGE;
Index altered.
SQL>
SQL> @show_index_usage
SQL> set echo on
SQL>
SQL> set linesize 200
SQL>
SQL> select * from v$object_usage;
SQL>
Execution Plan
----------------------------------------------------------
Plan hash value: 1928091631
--------------------------------------------------------------------
-------------------------------------
| Id | Operation | Name |
Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
-------------------------------------
| 0 | SELECT STATEMENT | |
6 | 1080 | 218 (1)| 00:00:03 |
|* 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS |
6 | 1080 | 218 (1)| 00:00:03 |
|* 2 | INDEX FULL SCAN | CUST_CUST_POSTAL_CODE_IDX |
89 | | 134 (1)| 00:00:02 |
Statistics
----------------------------------------------------------
395 recursive calls
3 db block gets
384 consistent gets
132 physical reads
n s e
604 redo size
i ce
2570 bytes sent via SQL*Net to client
b l el
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
fe r a
6 sorts (memory)
a n s
0 sorts (disk)
n - tr
o
an
6 rows processed
SQL>
h s
a deฺ
SQL> set timing off
e )
s Gui
r ฺ
mi dent
SQL> set autotrace off
SQL>
p ฺ
g Stu
d
13) Execute the following query:
b i a@ this*/ c.*
SELECT /*+ INDEX_COMBINE(c)
FROM (ja c us=e'M'
customers
i a
b
WHERE cust_gender
to
AND Acust_postal_code
n i o = 40804
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 4093665856
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
-------------------------------------------
| Id | Operation | Name
| Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
-------------------------------------------
| 0 | SELECT STATEMENT |
| 6 | 1080 | 466 (1)| 00:00:06 |
|* 1 | TABLE ACCESS BY INDEX ROWID | CUSTOMERS
| 6 | 1080 | 466 (1)| 00:00:06 |
n s e
| 2 | BITMAP CONVERSION TO ROWIDS |
i ce
| | | | |
b l el
|
|
3 |
|
BITMAP AND
| | |
|
fer a
| 4 | BITMAP CONVERSION FROM ROWIDS|
a n s
| | | | |
n -tr
o
an
|* 5 | INDEX RANGE SCAN |
CUST_CUST_CREDIT_LIMIT_IDX | | | 14 (0)| 00:00:01 |
| 6 |
h
BITMAP CONVERSION FROM ROWIDS| s
a deฺ
| | | |
e )
s Gui
|
r ฺ
mi dent
|* 7 | INDEX RANGE SCAN | CUST_CUST_GENDER_IDX
| | | 51 ฺ
(0)| 00:00:01 |
p
g Stu
d
--------------------------------------------------------------------
b i a@ this
-------------------------------------------
J o s 7 - access("CUST_GENDER"='M')
Statistics
----------------------------------------------------------
3 recursive calls
7 db block gets
894 consistent gets
81 physical reads
1020 redo size
2570 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
SQL>
SQL> select * from v$object_usage;
i A termout off
SQL> @drop_customers_indexes
o set
to n
SQL>
e An SQL>
SQL> @create_gender_limit_code_index
Jos SQL>
SQL>
set echo on
Index created.
SQL>
SQL>
SQL> SELECT /*+ INDEX(c) */ c.*
2 FROM customers c
3 WHERE cust_gender = 'M'
4 AND cust_postal_code = 40804
5 AND cust_credit_limit = 10000
6 /
6 rows selected.
n s e
Elapsed: 00:00:00.01
i ce
b l el
Execution Plan
fer a
----------------------------------------------------------
Plan hash value: 2871279522
a n s
n -tr
o
an
--------------------------------------------------------------------
--------------------------------------
| Id | Operation | Name
h s
a deฺ |
Rows | Bytes | Cost (%CPU)| Time |
e )
s Gui
r ฺ
mi dent
--------------------------------------------------------------------
p ฺ
--------------------------------------
g Stu
| 0 | SELECT STATEMENT
d | |
7 | 1260 | 18
b a@ this
(0)| 00:00:01 |
i
(ja use
| 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS |
7 | 1260 |
|* 2 | b i a18 (0)| 00:00:01 |
to
INDEX RANGE SCAN | CUST_GENDER_LIMIT_CODE_IDX |
6 |
io A | 12 (0)| 00:00:01 |
t o n
--------------------------------------------------------------------
A n --------------------------------------
o s e
J Predicate Information (identified by operation id):
---------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
22 consistent gets
14 physical reads
0 redo size
2981 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
b i a@ this
i a (ja use
4101 rows selected.
A
Elapsed: to
b 00:00:00.08
ni o
ntoExecution Plan
e A ----------------------------------------------------------
--------------------------------------------------------------------
--------------------------------------
| Id | Operation | Name |
Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
--------------------------------------
| 0 | SELECT STATEMENT | |
3469 | 609K| 3454 (1)| 00:00:42 |
| 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS |
3469 | 609K| 3454 (1)| 00:00:42 |
|* 2 | INDEX RANGE SCAN | CUST_GENDER_LIMIT_CODE_IDX |
3469 | | 12 (0)| 00:00:01 |
--------------------------------------------------------------------
--------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
0 db block gets
4391 consistent gets
0 physical reads
0 redo size
795172 bytes sent via SQL*Net to client
3423 bytes received via SQL*Net from client
275 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
4101 rows processed
n s e
i ce
SQL>
b l el
SQL>
SQL> set autotrace off
fer a
SQL> set timing off
a n s
SQL>
o n -tr
18) Execute the following query:
s an
SELECT /*+ INDEX(c) */ c.*
) h a deฺ
FROM customers c
r ฺ e s Gui
mi dent
WHERE cust_gender = 'M'
AND cust_postal_code = 40804;
p ฺ
g Stu
What do you observe? d
a) You replacedja b ia@ this
( u s e is used and with
cust_credit_limit cust_postal_code, which has
b ia to
better selectivity. The index the resulting cost is better.
i A
o @query04
n
SQL>
toSQL> set echo on
e An SQL>
Jos
SQL> set timing on
SQL> set autotrace traceonly
SQL> set linesize 200 pagesize 1000
SQL>
SQL> SELECT /*+ INDEX(c) */ c.*
2 FROM customers c
3 WHERE cust_gender = 'M'
4 AND cust_postal_code = 40804
5 /
75 rows selected.
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 2871279522
--------------------------------------------------------------------
--------------------------------------
n s e
2 - access("CUST_GENDER"='M')
i ce
filter(TO_NUMBER("CUST_POSTAL_CODE")=40804)
b l el
fe ra
Statistics
a n s
-
----------------------------------------------------------
n tr
o
an
1 recursive calls
0 db block gets
196 consistent gets
h s
a deฺ
101 physical reads
e )
s Gui
r ฺ
mi dent
0 redo size
p ฺ
16237 bytes sent via SQL*Net to client
g Stu
d
464 bytes received via SQL*Net from client
b i a@ this
6 SQL*Net roundtrips to/from client
0 sorts (memory)
i a (ja use
0 sorts (disk)
A b to
75 rows processed
o n io
SQL>
nt
e A SQL> set timing off
15 rows selected.
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 2438361736
--------------------------------------------------------------------
--------------------------------------
n s e
| Id | Operation | Name |
i ce
Rows | Bytes | Cost (%CPU)| Time |
b l el
--------------------------------------------------------------------
--------------------------------------
fer a
| 0 | SELECT STATEMENT |
a n s |
11 | 1980 | 185 (1)| 00:00:03 |
o n -tr
an
| 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS |
11 | 1980 | 185 (1)| 00:00:03 |
|* 2 | INDEX FULL SCAN
h s
a deฺ
| CUST_GENDER_LIMIT_CODE_IDX |
11 | | 173 (1)| 00:00:03 |
e )
s Gui
r ฺ
mi dent
--------------------------------------------------------------------
p ฺ
--------------------------------------
g Stuby operation id):
d
Predicate Information
b i a@ this
(identified
---------------------------------------------------
i a (ja use
b to
2 - access("CUST_CREDIT_LIMIT"=10000)
A
n i o filter(TO_NUMBER("CUST_POSTAL_CODE")=40804 AND
nto"CUST_CREDIT_LIMIT"=10000)
e A
J o s Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
189 consistent gets
56 physical reads
0 redo size
4617 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
15 rows processed
SQL>
SQL> set timing off
SQL> set autotrace off
SQL>
SQL>
cust_credit_limit
SQL> @drop_customers_indexes
SQL> set termout off
SQL>
SQL> @create_cust_gender_bindex
SQL> set echo on
SQL>
SQL> CREATE BITMAP INDEX cust_cust_gender_bidx ON
customers(cust_gender)
n s e
2 NOLOGGING COMPUTE STATISTICS;
i ce
b l el
Index created.
fe r a
SQL>
a n s
SQL> @create_cust_postal_code_bindex
o n -tr
an
SQL> set echo on
SQL>
h s
a deฺ
SQL> CREATE BITMAP INDEX cust_cust_postal_code_bidx ON
customers(cust_postal_code)
e )
s Gui
r ฺ
mi dent
2 NOLOGGING COMPUTE STATISTICS;
p ฺ
g Stu
Index created.
d
b i a@ this
(ja use
SQL>
SQL> setb a
SQL> @create_cust_credit_limit_bindex
i
echo onto
A
io CREATE BITMAP INDEX cust_cust_credit_limit_bidx ON
SQL>
t o n
SQL>
A n customers(cust_credit_limit)
SQL>
SQL> @list_customers_indexes
SQL> set echo on
SQL> set linesize 200 pagesize 1000
SQL>
SQL> SELECT ui.table_name
2 , decode(ui.index_type
3 ,'NORMAL', ui.uniqueness
4 ,ui.index_type) AS index_type
5 , ui.index_name
6 FROM user_indexes ui
7 WHERE ui.table_name = 'CUSTOMERS'
8 ORDER BY ui.table_name
9 , ui.uniqueness desc;
TABLE_NAME INDEX_TYPE
INDEX_NAME
CUSTOMERS BITMAP
CUST_CUST_CREDIT_LIMIT_BIDX
CUSTOMERS BITMAP
CUST_CUST_POSTAL_CODE_BIDX
SQL>
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 3047829365
--------------------------------------------------------------------
----------------------------------------
| Id | Operation | Name |
Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
----------------------------------------
| 0 | SELECT STATEMENT | |
6 | 1080 | 402 (1)| 00:00:05 |
|* 1 | TABLE ACCESS BY INDEX ROWID | CUSTOMERS |
6 | 1080 | 402 (1)| 00:00:05 |
1 - filter(TO_NUMBER("CUST_POSTAL_CODE")=40804)
4 - access("CUST_CREDIT_LIMIT"=10000)
n s e
5 - access("CUST_GENDER"='M')
i ce
b l el
Statistics
fe r a
----------------------------------------------------------
a n s
1 recursive calls
n - tr
o
an
0 db block gets
813 consistent gets
5 physical reads
h s
a deฺ
0 redo size
e )
s Gui
r ฺ
mi dent
2570 bytes sent via SQL*Net to client
p ฺ
420 bytes received via SQL*Net from client
g Stu
d
2 SQL*Net roundtrips to/from client
b i a@ this
0 sorts (memory)
0 sorts (disk)
i a (ja use
6 rows processed
A b to
o n io
SQL>
SQL> set autotrace off
nt
e A SQL> set timing off
J o s SQL>
SQL>
22) Case 5: Drop all the CUSTOMERS indexes except its primary key index. After this,
create two bitmap indexes on the following columns of the CUSTOMERS table:
cust_year_of_birth
cust_credit_limit
SQL> @drop_customers_indexes
SQL> set termout off
SQL>
SQL> @create_cust_year_of_birth_bindex
SQL> set echo on
SQL>
SQL> CREATE BITMAP INDEX cust_cust_year_of_birth_bidx
2 ON customers(cust_year_of_birth)
3 NOLOGGING COMPUTE STATISTICS;
Index created.
SQL>
Index created.
SQL>
5 / bi
c.cust_credit_limit = 10000
A to
o
ni rows selected.
nt o7158
eA
Jos
Elapsed: 00:00:00.12
Execution Plan
----------------------------------------------------------
Plan hash value: 1912490408
--------------------------------------------------------------------
-----------------------------------------
| Id | Operation | Name
| Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
-----------------------------------------
| 0 | SELECT STATEMENT |
| 7585 | 1333K| 581 (1)| 00:00:07 |
| 1 | TABLE ACCESS BY INDEX ROWID | CUSTOMERS
| 7585 | 1333K| 581 (1)| 00:00:07 |
| 2 | BITMAP CONVERSION TO ROWIDS|
| | | | |
| 3 | BITMAP OR |
| | | | |
4 - access("C"."CUST_CREDIT_LIMIT"=10000)
5 - access("C"."CUST_YEAR_OF_BIRTH"=1953)
Statistics
----------------------------------------------------------
n s e
1 recursive calls
i ce
0 db block gets
b l el
1683 consistent gets
3 physical reads
fe r a
0 redo size
a n s
1391886 bytes sent via SQL*Net to client
o n -tr
an
5667 bytes received via SQL*Net from client
479 SQL*Net roundtrips to/from client
0 sorts (memory)
h s
a deฺ
0 sorts (disk)
e )
s Gui
7158 rows processed r ฺ
i ent
p ฺ m d
SQL>
SQL> set timing off @ d g S t u
SQL> set autotraceb i aoff this
SQL>
i a (ja use
SQL>
A b to
o
ni 6: Drop all the CUSTOMERS indexes except its primary key index. After this,
24) Case
t o
e An create three different bitmap indexes on the following columns of the CUSTOMERS
Jos
table:
cust_year_of_birth
cust_credit_limit
cust_postal_code
SQL> @drop_customers_indexes
SQL> set termout off
SQL>
SQL> @create_cust_year_of_birth_bindex
SQL> set echo on
SQL>
SQL> CREATE BITMAP INDEX cust_cust_year_of_birth_bidx
2 ON customers(cust_year_of_birth)
3 NOLOGGING COMPUTE STATISTICS;
Index created.
SQL>
SQL> @create_cust_credit_limit_bindex
SQL> set echo on
Index created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> @create_cust_postal_code_bindex
SQL> set echo on
SQL>
SQL> CREATE BITMAP INDEX cust_cust_postal_code_bidx ON
customers(cust_postal_code)
2 NOLOGGING COMPUTE STATISTICS;
Index created.
n s e
ice
SQL>
b l el
25) Execute the following query:
fe r a
SELECT c.*
a n s
FROM customers c
WHERE (c.cust_year_of_birth = '1970' And c.cust_postal_code o n -tr =
40804 ) a n
AND NOT cust_credit_limit = 15000;
h a s eฺ
) i d
What do you observe?
i r ฺes nt Gu
a) The query has a complex WHERE
g p ฺmclauseu e is well suited for using bitmap
dthat
d t
than the full tablei @cost.his S indexes and the resulting cost is better
indexes. The optimizer uses two bitmap
a
scan
( j a b et
i a u s
SQL> @query07
b
A echo ont
SQL> set o
i o
n set timing on
SQL>
ntoSQL>
e A SQL> set autotrace traceonly
J o s SQL>
SQL> SELECT c.*
2 FROM customers c
3 WHERE (c.cust_year_of_birth = '1970' And c.cust_postal_code =
40804 )
4 AND NOT cust_credit_limit = 15000
5 /
Elapsed: 00:00:00.03
Execution Plan
----------------------------------------------------------
Plan hash value: 576122600
--------------------------------------------------------------------
------------------------------------------
| Id | Operation | Name
| Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
------------------------------------------
| 3 | BITMAP MINUS |
| | | | |
| 4 | BITMAP MINUS |
| | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| CUST_CUST_YEAR_OF_BIRTH_BIDX
| | | | |
|* 6 | BITMAP INDEX SINGLE VALUE| CUST_CUST_CREDIT_LIMIT_BIDX
| | | | |
|* 7 | BITMAP INDEX SINGLE VALUE | CUST_CUST_CREDIT_LIMIT_BIDX
| | | | |
n s e
--------------------------------------------------------------------
i ce
------------------------------------------
b l el
Predicate Information (identified by operation id):
fe r a
---------------------------------------------------
a n s
o n -tr
an
1 - filter(TO_NUMBER("C"."CUST_POSTAL_CODE")=40804)
5 - access("C"."CUST_YEAR_OF_BIRTH"=1970)
6 - access("CUST_CREDIT_LIMIT"=15000)
h s
a deฺ
7 - )
s Gui
access("CUST_CREDIT_LIMIT" IS NULL)
e
r ฺ
i ent
p ฺ m d
Statistics
d g S t u
b
1 recursivea@ calls
t h is
----------------------------------------------------------
i
a blocksegets
0 (jdb
b i
773a t o u gets
consistent
n i o A 30 physical reads
J o s 420
2
bytes received via SQL*Net from client
SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> set timing off
SQL> set autotrace off
SQL>
26) Make sure the optimizer can no longer use the bitmap index you created on the
cust_year_of_birth column.
a) The best solution is to render it invisible.
SQL> show parameter optimizer_use_invisible_indexes
Index altered.
INDEX_NAME VISIBILIT
------------------------------ ---------
CUST_CUST_CREDIT_LIMIT_BIDX VISIBLE
CUST_CUST_YEAR_OF_BIRTH_BIDX INVISIBLE
CUST_CUST_POSTAL_CODE_BIDX VISIBLE
CUSTOMERS_PK VISIBLE
4 rows selected.
n s e
i ce
SQL>
b l el
27) Execute the following query:
fe r a
SELECT c.*
a n s
FROM customers c
WHERE (c.cust_year_of_birth = '1970' And c.cust_postal_code o n -tr =
40804 ) a n
AND NOT cust_credit_limit = 15000;
h a s eฺ
) i d
What do you observe?
i r ฺes nt Gu
a) This is the same query as in the
g p ฺm
previous
u d e However, the optimizer can no
step.
d t
i a @ his S indexes.
longer find a good plan that uses bitmap
SQL> @query07 b
( j aon se t
ia to u
SQL> set echo
b
SQL>
i
SQL>o A timing on
set
n
toSQL> set autotrace traceonly
A n SQL>
o s e SQL> SELECT c.*
J 2 FROM customers c
3 WHERE (c.cust_year_of_birth = '1970' And c.cust_postal_code =
40804 )
4 AND NOT cust_credit_limit = 15000
5 /
Elapsed: 00:00:00.03
Execution Plan
----------------------------------------------------------
Plan hash value: 2008213504
--------------------------------------------------------------------
-----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
-----------
| 0 | SELECT STATEMENT | | 1 | 180 | 407 (1)|
00:00:05 |
---------------------------------------------------
1 - filter(TO_NUMBER("C"."CUST_POSTAL_CODE")=40804 AND
"C"."CUST_YEAR_OF_BIRTH"=1970 AND
"CUST_CREDIT_LIMIT"<>15000)
Statistics
----------------------------------------------------------
393 recursive calls
n s e
0 db block gets
i ce
1590 consistent gets
b l el
0 physical reads
0 redo size
fer a
2024 bytes sent via SQL*Net to client
a n s
420 bytes received via SQL*Net from client
n -tr
o
an
2 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
h s
a deฺ
1 rows processed
e )
s Gui
r ฺ
i ent
SQL>
p ฺ m d
SQL> set timing off
d g S t u
SQL> set autotrace off
SQL> b i a@ this
a
(jthe se query:
i a
28) Case 7: Execute
b u
following
to
o
SELECTA c.*
t o ni customers
FROM c
Elapsed: 00:00:00.07
Execution Plan
----------------------------------------------------------
--------------------------------------------------------------------
-------------------------
| Id | Operation | Name | Rows | Bytes
| Cost (%CPU)| Time |
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
-------------------------
| 0 | SELECT STATEMENT | | 3 | 540
| 7 (0)| 00:00:01 |
| 1 | INLIST ITERATOR | | |
| | |
| 2 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS | 3 | 540
| 7 (0)| 00:00:01 |
|* 3 | INDEX UNIQUE SCAN | CUSTOMERS_PK | 3 |
| 4 (0)| 00:00:01 |
n s e
--------------------------------------------------------------------
i ce
-------------------------
b l el
Predicate Information (identified by operation id):
fe r a
---------------------------------------------------
a n s
o n -tr
an
3 - access("CUST_ID"=44910 OR "CUST_ID"=88340 OR
"CUST_ID"=104590)
h s
a deฺ
e )
s Gui
Statistics r ฺ
i ent
ฺ m
----------------------------------------------------------
p d
d
2 recursive calls g S t u
3 db block
b i a@gets
9 consistent t h
getsis
a
4 (jphysical sereads
b i
560a redo u
to sent via SQL*Net to client
size
i o A2022 bytes
J o s 0
0
sorts (memory)
sorts (disk)
1 rows processed
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
29) Case 8: Drop all the indexes on the CUSTOMERS table except its primary key index.
After this, create a concatenated B*-tree index on the following columns of the
CUSTOMERS table, and in the order here:
cust_last_name
cust_first_name
SQL> @drop_customers_indexes
SQL> set termout off
SQL>
SQL> @create_last_first_name_index
SQL> set echo on
Index created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
A
Elapsed: to
b 00:00:00.19
ni o
ntoExecution Plan
e A ----------------------------------------------------------
--------------------------------------------------------------------
-----------------------------
| Id | Operation | Name | Rows |
Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
-----------------------------
| 0 | SELECT STATEMENT | | 55500 |
812K| 55 (2)| 00:00:01 |
| 1 | INDEX FAST FULL SCAN| CUST_LAST_FIRST_NAME_IDX | 55500 |
812K| 55 (2)| 00:00:01 |
--------------------------------------------------------------------
-----------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3886 consistent gets
0 sorts (disk)
55500 rows processed
SQL>
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
SQL>
31) Case 9: Drop all the indexes on the CUSTOMERS table except its primary key index. n s e
i ce
After this, create two B*-tree indexes on the following columns of the CUSTOMERS
b l el
table:
fe ra
cust_last_name
a n s
cust_first_name
n - tr
o
SQL> @drop_customers_indexes
s an
SQL> set termout off
) h a deฺ
s Gui
SQL>
SQL> @create_last_name_index
r ฺ e
SQL> set echo on
p ฺ mi dent
SQL>
d g Stu
SQL> CREATE INDEX cust_cust_last_name_idx
i a@ STATISTICS;
t h is
2 ON customers(cust_last_name)
b
3 NOLOGGING
i a (ja use
COMPUTE
Index A b
created. to
ni o
ntoSQL>
e A SQL> @create_first_name_index
Index created.
SQL>
SQL>
SQL> SELECT /*+ INDEX_JOIN(c cust_cust_first_name_idx
cust_cust_last_name_idx) */ c.cust_last_name
2 , c.cust_first_name
3 FROM customers c
4 /
Elapsed: 00:00:00.27
n s e
i ce
Execution Plan
b l el
----------------------------------------------------------
fer a
Plan hash value: 3557918892
a n s
n -tr
--------------------------------------------------------------------
o
an
-------------------------------
| Id | Operation
Bytes | Cost (%CPU)| Time |
| Name
h s
a deฺ
| Rows |
)
s Gui
--------------------------------------------------------------------
e
r ฺ
mi dent
-------------------------------
| 0 | SELECT STATEMENT
p ฺ
g Stu
| | 55500 |
812K| 511
d
(1)| 00:00:07 |
| 1 | VIEW
b i a@ this | index$_join$_001 | 55500 |
(ja use
812K| 511 (1)| 00:00:07 |
|* 2 |
| b i a
HASH JOIN
| to |
| | |
|
io
3 | A INDEX FAST FULL SCAN| CUST_CUST_FIRST_NAME_IDX | 55500 |
t o n
812K| 175 (1)| 00:00:03 |
A n | 4 | INDEX FAST FULL SCAN| CUST_CUST_LAST_NAME_IDX | 55500 |
2 - access(ROWID=ROWID)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3985 consistent gets
279 physical reads
0 redo size
811440 bytes sent via SQL*Net to client
41109 bytes received via SQL*Net from client
3701 SQL*Net roundtrips to/from client
0 sorts (memory)
SQL>
SQL>
SQL> set autotrace off
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
33) CASE 10: Drop all the indexes on the CUSTOMERS table except its primary key
index. Then, create one bitmap index on the following column of the CUSTOMERS
table:
cust_credit_limit
SQL> @drop_customers_indexes
n s e
i ce
el
SQL> set termout off
SQL>
a b l
SQL> @create_cust_credit_limit_bindex
fer
SQL> set echo on
a n s
-tr
SQL>
SQL> CREATE BITMAP INDEX cust_cust_credit_limit_bidx ON
o n
customers(cust_credit_limit)
2 NOLOGGING COMPUTE STATISTICS; s an
) h a deฺ
Index created.
r ฺ e s Gui
SQL> p ฺ mi dent
d g Stu
34) Execute the followinga
i @ his
query:
SELECT count(*)
j a b e t
credit_limit
FROM (
ia to u = 10000;
customers s
A b
WHERE cust_credit_limit
n i
What
o do you observe?
n to
e A a) Although cust_credit_limit is not a selective column, the COUNT
Jos operation on its bitmap index is very efficient.
SQL> @query11
SQL> set echo on
SQL>
SQL> set linesize 200
SQL> set timing on
SQL> set autotrace traceonly
SQL>
SQL> SELECT count(*) credit_limit
2 FROM customers
3 WHERE cust_credit_limit = 10000
4 /
Elapsed: 00:00:00.00
Execution Plan
----------------------------------------------------------
Plan hash value: 37937133
| 0 | SELECT STATEMENT | |
1 | 4 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | |
1 | 4 | | |
| 2 | BITMAP CONVERSION COUNT | |
6938 | 27752 | 1 (0)| 00:00:01 |
|* 3 | BITMAP INDEX SINGLE VALUE| CUST_CUST_CREDIT_LIMIT_BIDX |
| | | |
--------------------------------------------------------------------
---------------------------------------
n s e
i ce
Predicate Information (identified by operation id):
b l el
---------------------------------------------------
fe r a
3 - access("CUST_CREDIT_LIMIT"=10000)
a n s
o n -tr
Statistics
s an
h a deฺ
----------------------------------------------------------
)
1 recursive calls
r ฺ e s Gui
3 consistent getsฺmi nt
0 db block gets
p
g Stu d e
d
2 physical reads
@ via
0 redo size
b
423 bytes i asent t h isSQL*Net to client
a received
420 (jbytes e via SQL*Net from client
sroundtrips
i a
b 0 sorts
2 u
to (memory) to/from client
SQL*Net
io A
t o n 0 sorts (disk)
A n 1 rows processed
o s e
J SQL>
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
SQL>
35) Case 11: Drop all the CUSTOMERS indexes except its primary key index. After this,
create one B*-tree index on the following column of the CUSTOMERS table:
cust_credit_limit
SQL> @drop_customers_indexes
SQL> set termout off
SQL>
SQL> @create_cust_credit_limit_index
SQL> set echo on
SQL>
SQL> CREATE INDEX cust_cust_credit_limit_idx
2 ON customers(cust_credit_limit)
3 NOLOGGING COMPUTE STATISTICS;
SQL>
i a (ja use
A b to
--------------------------------------------------------------------
i o
----------------------------
J o s --------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 1 |
4 | 14 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 |
4 | | |
|* 2 | INDEX RANGE SCAN| CUST_CUST_CREDIT_LIMIT_IDX | 6938 |
27752 | 14 (0)| 00:00:01 |
--------------------------------------------------------------------
----------------------------
2 - access("CUST_CREDIT_LIMIT"=10000)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
SQL>
n s e
i ce
37) Case 12: Drop all the indexes on the CUSTOMERS table except its primary key index.
After this, create one B*-tree index on the following column of the CUSTOMERS b l el
fe r a
table: s
cust_last_name tra n
o n -
SQL> @drop_customers_indexes
SQL> set termout off s an
SQL>
) h a deฺ
SQL> @create_last_name_index
r ฺ e s Gui
SQL> set echo on
SQL> p ฺ mi dent
d g Stu
SQL> CREATE INDEX cust_cust_last_name_idx
ia@ STATISTICS;
h is
2 ON customers(cust_last_name)
b
3 NOLOGGINGaCOMPUTE t
i a (j u se
A b
Index created. to
ni o
ntoSQL>
e A
J o s 38) Execute the following query:
SELECT cust_id, country_id
FROM customers
WHERE LOWER( cust_last_name) LIKE 'gentle';
What do you observe?
a) Although there is an index, it cannot be used because its column is modified by a
function.
SQL> @query12
SQL> set echo on
SQL>
SQL> set linesize 200
SQL> set timing on
SQL> set autotrace traceonly
SQL>
SQL> SELECT cust_id, country_id
2 FROM customers
3 WHERE LOWER( cust_last_name) LIKE 'gentle'
4 /
Elapsed: 00:00:00.01
Execution Plan
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
----------------------------------------------------------
Plan hash value: 2008213504
--------------------------------------------------------------------
-----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
-----------
| 0 | SELECT STATEMENT | | 555 | 9990 | 406 (1)|
n s e
00:00:05 |
i ce
|* 1 | TABLE ACCESS FULL| CUSTOMERS | 555 | 9990 | 406 (1)|
b l el
00:00:05 |
--------------------------------------------------------------------
fe r a
-----------
a n s
o n -tr
an
Predicate Information (identified by operation id):
---------------------------------------------------
h s
a deฺ
)
s Gui
1 - filter(LOWER("CUST_LAST_NAME")='gentle')
e
r ฺ
i ent
p ฺ m d
Statistics
d g S t u
b
1 recursivea@ calls
t h is
----------------------------------------------------------
i
a blocksegets
0 (jdb
b i
1464a t o u gets
consistent
n i o A 00 physical reads
J o s 475
7
bytes received via SQL*Net from client
SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
80 rows processed
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
39) How can you enhance the performance of the previous query without modifying the
statement itself? Implement your solution.
a) You can create a function-based index.
SQL> @create_lower_cust_last_name_index
SQL> set echo on
SQL>
SQL> CREATE INDEX lower_cust_last_name_idx ON
2 customers(LOWER(cust_last_name))
3 /
SQL>
40) Check if your solution executes faster than in the case of the query in step 38.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL> @query12
SQL> set echo on
SQL>
SQL> set linesize 200
SQL> set timing on
SQL> set autotrace traceonly
SQL>
SQL> SELECT cust_id, country_id
2 FROM customers
n s e
ce
3 WHERE LOWER( cust_last_name) LIKE 'gentle'
4 /
eli
a b l
80 rows selected.
fe r
a n s
Elapsed: 00:00:00.00
o n -tr
Execution Plan
s an
) h a deฺ
----------------------------------------------------------
s Gui
Plan hash value: 967065894
r ฺ e
p ฺ mi dent
--------------------------------------------------------------------
i a ( u s
--------------------------------------------------------------------
------------------------------------
| 0A b t o
| SELECT STATEMENT | |
i o
to|n 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS
555 | 17760 | 41 (0)| 00:00:01 |
A n |
o s e 555 | 17760 |
|* 2 |
41 (0)| 00:00:01 |
INDEX RANGE SCAN | LOWER_CUST_LAST_NAME_IDX |
J 222 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------
------------------------------------
2 - access(LOWER("CUST_LAST_NAME")='gentle')
Statistics
----------------------------------------------------------
24 recursive calls
0 db block gets
23 consistent gets
1 physical reads
0 redo size
2077 bytes sent via SQL*Net to client
475 bytes received via SQL*Net from client
7 SQL*Net roundtrips to/from client
SQL>
SQL> set autotrace off
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
41) Case 13: Execute the iot_setup.sql script to set up the environment for this
case.
SQL> @iot_setup
SQL> set echo on
SQL>
n s e
SQL> CREATE table promotions_iot
i ce
2 (promo_id number primary key
b l el
3
4
, promo_name VARCHAR2(40)
, promo_subcategory VARCHAR2 (30)
fe ra
5 , promo_category VARCHAR2 (30)
a n s
6
7
, promo_cost NUMBER
, promo_begin_date DATE o n -tr
8 , promo_end_date DATE)
s an
9 ORGANIZATION INDEX
) h a deฺ
10 /
r ฺ e s Gui
Table created.
p ฺ mi dent
d g Stu
SQL>
a@ this
SQL> INSERT INTO ipromotions_iot
b
2 SELECT (
a ja usepromo_name, promo_subcategory, promo_category,
promo_id,
i
promo_cost,
to
b promotions
promo_begin_date, promo_end_date
A
i4o /
3 FROM
t o n
A n
o s e 503 rows created.
J SQL>
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 4106015420
n s e
i ce
--------------------------------------------------------------------
b l el
------------
| Id | Operation | Name | Rows | Bytes | Cost
fer a
(%CPU)| Time |
a n s
-tr
--------------------------------------------------------------------
n
o
an
------------
| 0 | SELECT STATEMENT | | 364 | 35308 | 17
(0)| 00:00:01 |
h s
a deฺ
|* 1 | TABLE ACCESS FULL| PROMOTIONS |
e )
s Gui
364 | 35308 | 17
r ฺ
mi dent
(0)| 00:00:01 |
p
g Stuฺ
--------------------------------------------------------------------
------------
d
b i
Predicate Informationa@(identified
t h is by operation id):
i a (ja use
---------------------------------------------------
A b to
i o
1 - filter("PROMO_ID">300)
nton
e A
J o s Statistics
----------------------------------------------------------
123 recursive calls
0 db block gets
88 consistent gets
3 physical reads
0 redo size
21829 bytes sent via SQL*Net to client
585 bytes received via SQL*Net from client
17 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
235 rows processed
SQL>
SQL> SELECT /*+ INDEX(promotions) */ *
2 FROM promotions
3 WHERE promo_id > 300
4 /
Execution Plan
----------------------------------------------------------
Plan hash value: 4044283270
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
----------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time |
--------------------------------------------------------------------
----------------------
| 0 | SELECT STATEMENT | | 364 | 35308 |
353 (0)| 00:00:05 |
| 1 | TABLE ACCESS BY INDEX ROWID| PROMOTIONS | 364 | 35308 |
n s e
353 (0)| 00:00:05 |
i ce
|* 2 | INDEX RANGE SCAN | PROMO_PK | 364 | |
b l el
1 (0)| 00:00:01 |
--------------------------------------------------------------------
fe r a
----------------------
a n s
o n -tr
an
Predicate Information (identified by operation id):
---------------------------------------------------
h s
a deฺ
2 - access("PROMO_ID">300)
e )
s Gui
r ฺ
i ent
p ฺ m d
Statistics
d g S t u
b
1 recursivea@ calls
t h is
----------------------------------------------------------
i
a blocksegets
0 (jdb
b i
243a t o u gets
consistent
n i o A 10 physical reads
J o s 585
17
bytes received via SQL*Net from client
SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
235 rows processed
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
SQL> SELECT *
2 FROM promotions_iot
3 WHERE promo_id > 300
4 /
Elapsed: 00:00:00.00
Execution Plan
n s e
----------------------------------------------------------
i ce
Plan hash value: 1463021396
b l el
fer
-------------------------------------------------------------------- a
------------------
a n s
| Id | Operation | Name -tr
| Rows | Bytes | Cost
n
o
an
(%CPU)| Time |
--------------------------------------------------------------------
------------------
h s
a deฺ
| 0 | SELECT STATEMENT |
e )
s Gui | 235 | 23500 | 2
r ฺ
mi dent
(0)| 00:00:01 |
p ฺ
|* 1 | INDEX RANGE SCAN| SYS_IOT_TOP_72170 |
g Stu
235 | 23500 | 2
(0)| 00:00:01 |
d
b
------------------ i a@ this
--------------------------------------------------------------------
n t o
e A
Jos Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
5 recursive calls
0 db block gets
42 consistent gets
0 physical reads
116 redo size
19922 bytes sent via SQL*Net to client
585 bytes received via SQL*Net from client
17 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
235 rows processed
SQL>
Table dropped.
SQL>
SQL>
45) Case 14: Execute shc_setup.sql to set up your environment for this lab. n s e
i ce
SQL> @shc_setup
b l el
SQL> set echo on
fer a
SQL>
a n s
SQL> set linesize 200
SQL>
n - tr
o
an
SQL> drop cluster bigemp_cluster including tables;
drop cluster bigemp_cluster including tables
* h s
a deฺ
ERROR at line 1:
e )
s Gui
r ฺ
ORA-00943: cluster does not exist
p ฺ mi dent
d g Stu
SQL>
b i a@ t h is
a
2 (deptno(jnumber,
SQL> CREATE CLUSTER
e number sort)
bigemp_cluster
ssal
b i a u
toHASH IS deptno SIZE 50
o A
3 HASHKEYS 10000
An
e
Jos
Cluster created.
SQL>
SQL> create table bigemp_fact (
2 empno number primary key, sal number sort, job varchar2(12) not
null,
3 deptno number not null, hiredate date not null)
4 CLUSTER bigemp_cluster (deptno, sal);
Table created.
SQL>
SQL>
SQL> begin
2 for i in 1..1400000 loop
3 insert into bigemp_fact values(i,i,'J1',10,sysdate);
4 end loop;
5 commit;
6 end;
7 /
SQL>
SQL> begin
2 for i in 1..1400000 loop
3 insert into bigemp_fact values(1400000+i,i,'J1',20,sysdate);
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
4 end loop;
5 commit;
6 end;
7 /
SQL>
SQL>
SQL> exec dbms_stats.gather_schema_stats('SH');
n s e
ice
PL/SQL procedure successfully completed.
b l el
SQL>
fe r a
a n s
46) Execute the query15.sql script. What do you observe?
o n -tr
a) Because you may have a lot of memory on your system, n the script first reduces
a optimizer
the amount of memory available to your session.
h a sThe
e ฺ decides to use the
s) costG
cluster access path to retrieve the data. The ui d
is minimal.
r ฺ e
SQL> @query15
p ฺ mi dent
SQL> set echo on
d g Stu
SQL>
SQL> set linesizeia
@ his
a on se t
b 200
SQL> set timing( j
a to utraceonly
SQL> set iautotrace
SQL> A
b
o n io alter session set workarea_size_policy=manual;
SQL>
nt
e A Session altered.
J o s
Elapsed: 00:00:00.02
SQL> alter session set sort_area_size=50000;
Session altered.
Elapsed: 00:00:00.01
SQL>
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.16
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:06.69
SQL>
SQL>
Elapsed: 00:00:07.21
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Execution Plan
----------------------------------------------------------
Plan hash value: 865757019
--------------------------------------------------------------------
-------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------
n s e
| 0 | SELECT STATEMENT | | 1400K| 32M| 1
ice
(0)| 00:00:01 |
b l el
|* 1 | TABLE ACCESS HASH| BIGEMP_FACT | 1400K|
(0)| 00:00:01 |
32M| 1
fe ra
--------------------------------------------------------------------
a n s
-------------
o n -tr
Predicate Information (identified by operation
s a nid):
h a deฺ
---------------------------------------------------
)
r ฺ e s Gui
mi dent
1 - access("DEPTNO"=10)
p ฺ
g Stu
d
Statistics
b i a@ this
----------------------------------------------------------
a
689 (jrecursive segets
calls
b i a
0 db
to u
block
i o A99451 consistent gets
to n 5999 physical reads
A n 116 redo size
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
Session altered.
Elapsed: 00:00:00.00
SQL> alter session set sort_area_size=50000;
Session altered.
Elapsed: 00:00:00.00
SQL>
n s e
SQL> alter system flush shared_pool;
i ce
b l el
System altered.
fe r a
Elapsed: 00:00:00.10
a n s
SQL> alter system flush buffer_cache;
o n -tr
System altered.
s an
) h a deฺ
Elapsed: 00:00:00.04
r ฺ e s Gui
miwherededeptno=10
nt
SQL>
SQL> select * from bigemp_fact
g p ฺ u
order by sal;
d S t
@ s
thi
1400000 rows selected.
a b ia
j e
ia ( to us
Elapsed: 00:00:07.41
b
i o A Plan
Execution
n
ntoPlan hash value: 865757019
----------------------------------------------------------
e A
J o s --------------------------------------------------------------------
-------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------
| 0 | SELECT STATEMENT | | 1400K| 32M| 1
(0)| 00:00:01 |
|* 1 | TABLE ACCESS HASH| BIGEMP_FACT | 1400K| 32M| 1
(0)| 00:00:01 |
--------------------------------------------------------------------
-------------
1 - access("DEPTNO"=10)
Statistics
SQL>
SQL> set autotrace off
SQL> set timing off
n s e
SQL>
ice
48) Execute the query17.sql script. What do you observe? b l el
fe ra
a n s
a) Again, the script first ensures that the amount of memory available to your session
n - tr
is reduced. Then the script executes the same query, but asks to order the result
o
based on the sorted sal column in the descending order. The optimizer can still
an
use the cluster access path without sorting the data. The cost is still minimal.
s
) h a deฺ
SQL> @query17
r ฺ e s Gui
mi dent
SQL> set echo on
SQL>
SQL> set linesize 200 dg p ฺ
SQL> set timing on @ S tu
b i atraceonly
t h is
(ja use
SQL> set autotrace
SQL>
i a
b sessionto set workarea_size_policy=manual;
A
SQL> alter
o
ni
toSession altered.
A n
o s e Elapsed: 00:00:00.00
J SQL> alter session set sort_area_size=50000;
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.09
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:00.12
SQL>
SQL> select * from bigemp_fact where deptno=10 order by sal desc;
Execution Plan
----------------------------------------------------------
Plan hash value: 865757019
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
-------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------
| 0 | SELECT STATEMENT | | 1400K| 32M| 1
(0)| 00:00:01 |
|* 1 | TABLE ACCESS HASH| BIGEMP_FACT | 1400K| 32M| 1
n s e
(0)| 00:00:01 |
ice
--------------------------------------------------------------------
b l el
-------------
fe r a
Predicate Information (identified by operation id):
a n s
---------------------------------------------------
o n -tr
1 - access("DEPTNO"=10)
s an
) h a deฺ
r ฺ e s Gui
Statistics
ฺ m i ent
----------------------------------------------------------
d
1090 recursive calls g p t u d
10 db block
a@gets is S
a b i
99509 consistent t h
gets
6005 (jphysical
i a u sereads
A b bytes
0
to sent via SQL*Net to client
redo size
i o
33605911
J o s 12
0
sorts (memory)
sorts (disk)
1400000 rows processed
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
Session altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Elapsed: 00:00:00.00
SQL> alter session set sort_area_size=50000;
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> alter system flush shared_pool;
System altered.
n s e
i ce
Elapsed: 00:00:00.10
b l el
SQL> alter system flush buffer_cache;
fer a
System altered.
a n s
o n -tr
an
Elapsed: 00:00:00.04
SQL>
h s
a deฺ
SQL> select * from bigemp_fact where deptno=10 order by empno;
e )
s Gui
1400000 rows selected. r ฺ
i ent
p ฺ m
Elapsed: 00:00:10.01
d g Stud
Execution Plan bia
@ his
j a e t
( s
----------------------------------------------------------
u
iavalue:to1775608660
b
Plan hash
n i oA
nto----------------------
--------------------------------------------------------------------
e A
J o s | Id | Operation
Cost (%CPU)| Time |
| Name | Rows | Bytes |TempSpc|
--------------------------------------------------------------------
----------------------
| 0 | SELECT STATEMENT | | 1400K| 32M| |
47728 (1)| 00:09:33 |
| 1 | SORT ORDER BY | | 1400K| 32M| 107M|
47728 (1)| 00:09:33 |
|* 2 | TABLE ACCESS HASH| BIGEMP_FACT | 1400K| 32M| |
1 (0)| 00:00:01 |
--------------------------------------------------------------------
----------------------
2 - access("DEPTNO"=10)
Statistics
----------------------------------------------------------
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
n s e
ice
50) Execute the query19.sql script. What do you observe?
b l el
r a
a) Again, the script first ensures that the amount of memory available to your session
fe
n s
is reduced. Then the script executes the same query, but this time asks to order the
a
- tr
result based on the sal, deptno key. The optimizer can still make use of the
n
o
an
cluster access path, but must sort the data making the cost of the query higher.
s
SQL> @query19
) h a deฺ
SQL> set echo on
r ฺ e s Gui
mi dent
SQL>
SQL> set linesize 200
p ฺ
g Stu
SQL> set timing on d
b i a@ this
SQL> set autotrace traceonly
(ja usetseworkarea_size_policy=manual;
SQL>
i a
SQL> alter session
baltered.to
i o A
Session
nton
e A Elapsed: 00:00:00.00
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.10
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:00.09
SQL>
SQL> select * from bigemp_fact where deptno=10 order by sal,empno;
Execution Plan
----------------------------------------------------------
Plan hash value: 1775608660
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
----------------------
| Id | Operation | Name | Rows | Bytes |TempSpc|
Cost (%CPU)| Time |
--------------------------------------------------------------------
----------------------
| 0 | SELECT STATEMENT | | 1400K| 32M| |
47728 (1)| 00:09:33 |
| 1 | SORT ORDER BY | | 1400K| 32M| 107M|
47728 (1)| 00:09:33 |
n s e
|* 2 | TABLE ACCESS HASH| BIGEMP_FACT | 1400K| 32M| |
i ce
1 (0)| 00:00:01 |
b l el
--------------------------------------------------------------------
----------------------
fer a
a n s
Predicate Information (identified by operation id):
o n -tr
an
---------------------------------------------------
2 - access("DEPTNO"=10)
h s
a deฺ
e )
s Gui
r ฺ
i ent
Statistics
p ฺ m d
d g t u
----------------------------------------------------------
S
12 db b i a@gets
1139 recursive
block
calls
t h is
a sereads
6178 (jconsistent gets
i a
b 0 redotosize
12238 u
physical
i o A
nton 33605911 bytes sent via SQL*Net to client
J o s 93335
12
SQL*Net roundtrips to/from client
sorts (memory)
1 sorts (disk)
1400000 rows processed
SQL>
SQL> set autotrace off
SQL> set timing off
SQL>
Cluster dropped.
SQL>
SQL>
SQL>
SQL> drop table emp purge;
drop table emp purge
n s e
*
i ce
ERROR at line 1:
b l el
ORA-00942: table or view does not exist
fer a
a n s
SQL> drop table dept purge;
n - tr
o
an
drop table dept purge
*
ERROR at line 1:
h s
a deฺ
e
ORA-00942: table or view does not exist )
s Gui
r ฺ
p ฺ mi dent
SQL> d g Stu
SQL>
i @( his
aemp
SQL> CREATE TABLE
j b
a NUMBER(7)e t
2 ( u s
ia toVARCHAR2(15)
empno ,
3 b
4o A job
ename NOT NULL,
o n i VARCHAR2(9) ,
nt 6 hiredate DATE
5 mgr NUMBER(7) ,
e A ,
Jos
7 sal NUMBER(7) ,
8 comm NUMBER(7) ,
9 deptno NUMBER(3)
10 );
Table created.
SQL>
SQL> CREATE TABLE dept (
2 deptno NUMBER(3) ,
3 dname VARCHAR2(14),
4 loc VARCHAR2(14),
5 c VARCHAR2(500)
6 );
Table created.
SQL>
SQL> CREATE INDEX emp_index
2 ON emp(deptno)
3 TABLESPACE users
Index created.
SQL>
SQL> CREATE INDEX dept_index
2 ON dept(deptno)
3 TABLESPACE users
4 STORAGE (INITIAL 50K
5 NEXT 50K
6 MINEXTENTS 2
7 MAXEXTENTS 10
n s e
8 PCTINCREASE 33);
i ce
b l el
Index created.
fer a
SQL>
a n s
SQL>
n - tr
o
an
SQL> begin
2 for i in 1..999 loop
3 insert into dept values
h s
a deฺ
)
s Gui
(i,'D'||i,'L'||i,dbms_random.string('u',500));
e
r ฺ
mi dent
4 end loop;
5 commit;
p ฺ
g Stu
6 end;
d
7 /
b i a@ this
i a (ja successfully
PL/SQL procedure
u se completed.
SQL> A
b to
n i o
t oSQL>
n SQL> begin
e A
Jos
2 for i in 1..500000 loop
3 insert into emp values
(i,dbms_random.string('u',15),dbms_random.string('u',9),i,sysdate,i,
i,mod(i,999));
4 end loop;
5 commit;
6 end;
7 /
SQL>
SQL> exec dbms_stats.gather_schema_stats('SH');
SQL>
SQL>
SQL> set timing on
SQL> set autotrace traceonly
SQL> set linesize 200
SQL>
SQL> alter session set workarea_size_policy=manual;
Session altered.
Elapsed: 00:00:00.00
n s e
i ce
el
SQL> alter session set sort_area_size=50000;
a b l
Session altered.
fe r
a n s
-tr
Elapsed: 00:00:00.00
SQL> alter session set hash_area_size=5000;
o n
Session altered. s an
) h a deฺ
Elapsed: 00:00:00.00
r ฺ e s Gui
SQL>
SQL> p ฺ mi dent
d g where
SQL> select * from emp,dept
S tuemp.deptno=dept.deptno and
emp.deptno > 800; a@ is
b i t h
(ja use
99000 rowsaselected.
i
A b to
i o
ton
Elapsed: 00:00:02.88
A n Execution Plan
o s e ----------------------------------------------------------
J Plan hash value: 128236434
--------------------------------------------------------------------
-------------------------------
| Id | Operation | Name | Rows | Bytes
|TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------
-------------------------------
| 0 | SELECT STATEMENT | | 19780 | 10M|
| 3449 (1)| 00:00:42 |
|* 1 | HASH JOIN | | 19780 | 10M|
104K| 3449 (1)| 00:00:42 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 199 | 99K|
| 18 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | DEPT_INDEX | 199 | |
| 2 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | EMP | 99198 | 5521K|
| 1207 (2)| 00:00:15 |
--------------------------------------------------------------------
-------------------------------
1 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")
3 - access("DEPT"."DEPTNO">800)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
4 - filter("EMP"."DEPTNO">800)
Statistics
----------------------------------------------------------
9 recursive calls
0 db block gets
4365 consistent gets
10146 physical reads
0 redo size
n s e
57968984 bytes sent via SQL*Net to client
i ce
73009 bytes received via SQL*Net from client
b l el
6601 SQL*Net roundtrips to/from client
0 sorts (memory)
fer a
0 sorts (disk)
a n s
99000 rows processed
o n -tr
SQL>
s an
SQL> set autotrace off
) h a deฺ
SQL> set timing off;
r ฺ e s Gui
mi ofdthe nt
SQL>
p ฺ e
g Stu previous query? Implement your
54) How would you enhance the performance
d
solution.
b i a@ this
i a (ja to store
a) Create a cluster
u sethe two tables.
A b
SQL> @ic_setup to
o
ni set echo on
SQL>
t o
An SQL> drop table emp purge;
SQL>
e
Jos Table dropped.
Table dropped.
SQL>
SQL> drop cluster emp_dept including tables;
drop cluster emp_dept including tables
*
ERROR at line 1:
ORA-00943: cluster does not exist
SQL>
SQL> CREATE CLUSTER emp_dept (deptno NUMBER(3))
2 SIZE 600
3 TABLESPACE users
4 STORAGE (INITIAL 200K
5 NEXT 300K
Cluster created.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
e A MINEXTENTS 2
Jos
7 MAXEXTENTS 10
8 PCTINCREASE 33);
Index created.
SQL>
SQL> begin
2 for i in 1..999 loop
3 insert into dept values
(i,'D'||i,'L'||i,dbms_random.string('u',500));
4 end loop;
5 commit;
6 end;
7 /
SQL>
SQL>
SQL> begin
2 for i in 1..500000 loop
7 /
SQL>
SQL> exec dbms_stats.gather_schema_stats('SH');
SQL>
n s e
i ce
55) Execute the following query to confirm the performance enhancement of the previous
query: b l el
select * fe r a
from emp,dept
a n s
where emp.deptno=dept.deptno and emp.deptno > 800;
o n -tr
What do you observe?
s an
h
a) The optimizer is able to use the cluster access
) i eฺ the query execute
apath thatdmakes
faster.
i r ฺes nt Gu
SQL> @ic_query
g p ฺm ude
SQL> set echo on d S t
@ s
SQL>
j a b ia
e thi
SQL> set timing
i a (
SQL> set autotrace
on
u s
traceonly
b
A linesizet 200
SQL> set o
i o
n select * from emp,dept where emp.deptno=dept.deptno and
SQL>
ntoSQL>
e A emp.deptno > 800;
J o s
99000 rows selected.
Elapsed: 00:00:01.20
Execution Plan
----------------------------------------------------------
Plan hash value: 593050162
--------------------------------------------------------------------
--------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time |
--------------------------------------------------------------------
--------------------
| 0 | SELECT STATEMENT | | 19780 | 10M|
11515 (1)| 00:02:19 |
| 1 | NESTED LOOPS | | 19780 | 10M|
11515 (1)| 00:02:19 |
| 2 | TABLE ACCESS CLUSTER| DEPT | 199 | 99K|
167 (0)| 00:00:03 |
3 - access("DEPT"."DEPTNO">800)
4 - filter("EMP"."DEPTNO">800 AND "EMP"."DEPTNO"="DEPT"."DEPTNO")
Statistics
----------------------------------------------------------
n s e
1 recursive calls
i ce
0 db block gets
b l el
30131 consistent gets
0 physical reads
fer a
0 redo size
a n s
6259293 bytes sent via SQL*Net to client
o n -tr
an
73009 bytes received via SQL*Net from client
6601 SQL*Net roundtrips to/from client
0 sorts (memory)
h s
a deฺ
0 sorts (disk)
e )
s Gui
99000 rows processed r ฺ
i ent
p ฺ m d
SQL>
d g S t u
SQL> set timing b i
offa@ this
SQL> set autotrace off
SQL>
i a (ja use
A
56) Execute
b to
the ic_cleanup.sql script to clean up your environment for this case.
n i o
toSQL> @ic_cleanup
e An SQL> set echo on
Jos SQL>
SQL> drop cluster emp_dept including tables;
Cluster dropped.
SQL>
SQL> drop table emp purge;
drop table emp purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL>
Table created.
SQL>
SQL> begin
2 for i in 1..10000 loop
3 insert into t values(1,i);
4 end loop;
5 end;
n s e
6 /
i ce
b l el
PL/SQL procedure successfully completed.
fer a
SQL>
a n s
SQL> create index it on t(c,d);
o n -tr
Index created.
s an
) h a deฺ
SQL>
r ฺ e s Gui
58) Execute the following query:
p ฺ mi dent
select count(*) from t where
d g d=1;S tu
What do you observe?
b i a@ this
a (jais notuusing
a) The optimizer
i se the index and does a full table scan.
A b to
o
ni set echo on
SQL> @query20
t oSQL>
e An SQL>
Jos
SQL> set linesize 200
SQL>
SQL> set timing on
SQL> set autotrace on
SQL>
SQL> select count(*) from t where d=1;
COUNT(*)
----------
1
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 2966233522
--------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
2 - filter("D"=1)
n s e
Note
i ce
-----
b l el
- dynamic sampling used for this statement
fe ra
a n s
Statistics
n - tr
o
an
----------------------------------------------------------
5 recursive calls
0 db block gets
h s
a deฺ
48 consistent gets
e )
s Gui
r ฺ
mi dent
0 physical reads
0 redo size
p ฺ
g Stu
d
418 bytes sent via SQL*Net to client
b i a@ this
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
i a (ja use
0 sorts (memory)
A b to
0 sorts (disk)
o n io 1 rows processed
nt SQL>
e A
J o s SQL> set timing off
SQL> set autotrace off
SQL>
59) How would you improve the performance of a query, such as the one in the previous
step? Implement your solution.
a) Make sure you gather correctly the statistics for your table so that the index skip
scan can be used.
SQL> @iss_gather_stats
SQL> set echo on
SQL>
SQL> execute dbms_stats.gather_table_stats('SH','T',cascade=>TRUE);
SQL>
COUNT(*)
----------
n s e
ce
1
eli
Elapsed: 00:00:00.00
a b l
fer
Execution Plan
a n s
Plan hash value: 2609927160
o n -tr
----------------------------------------------------------
s an
) h a deฺ
--------------------------------------------------------------------
|*io2 |
n
to00:00:01 |
A n
o s e --------------------------------------------------------------------
-----
J
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("D"=1)
filter("D"=1)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
23 consistent gets
0 physical reads
0 redo size
418 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
SQL>
SQL> set timing off
SQL> set autotrace off
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
61) Compare the result of executing the previous query with the result you obtain when
you execute the following query:
select /*+ INDEX_FFS(t it) */ count(*) from t where d=1;
What do you observe?
a) The optimizer uses a fast full index scan, but this is not better than the index skip
scan.
n s e
ice
el
SQL> @query21
SQL> set echo on
a b l
SQL>
fe r
SQL> set linesize 200
a n s
SQL>
SQL> set timing on
o n -tr
SQL> set autotrace on
s an
etฺ where d=1;
SQL>
) h a fromd
SQL> select /*+ INDEX_FFS(t it) */ count(*)
i
i r ฺes nt Gu
COUNT(*)
----------
g p ฺm ude
1 d S t
@ s
j a b ia
e thi
i a (
Elapsed: 00:00:00.00
u s
b
A Plan t
Execution o
i o
n hash value: 273610729
----------------------------------------------------------
ntoPlan
e A
J o s --------------------------------------------------------------------
----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
----------
| 0 | SELECT STATEMENT | | 1 | 4 | 9 (0)|
00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 4 | |
|
|* 2 | INDEX FAST FULL SCAN| IT | 1 | 4 | 9 (0)|
00:00:01 |
--------------------------------------------------------------------
----------
2 - filter("D"=1)
0 redo size
418 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> set timing off
n s e
SQL> set autotrace off
i ce
SQL>
b l el
r a
62) Execute the iss_cleanup.sql script to clean up your environment for this case.
fe
a n s
SQL> @iss_cleanup
SQL> set echo on
o n -tr
SQL>
s an
SQL> drop table t purge;
) h a deฺ
Table dropped.
r ฺ e s Gui
p ฺ mi dent
SQL>
d g Stu
a@session,
SQL>
b i t h is
j a
63) Exit from your(SQL*Plus
s e and execute the ap_cleanup.sh script to clean
u
bia tofor this lab.
up your environment
A
io exit;
o n
SQL>
t Disconnected from Oracle Database 11g Enterprise Edition Release
e An 11.1.0.6.0 - Production
Jos With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Access_Paths]$ ./ap_cleanup.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
SQL> revoke dba from sh;
Revoke succeeded.
SQL> Rem
....
p
g Sฺ
- Changes have been committed
d tu
b i a@ this
PL/SQL procedure successfully completed.
i a (ja use
b
Commit complete.
A to
ni o
ntogathering
e A statistics ...
e A
Jos
SQL> SQL> Connected.
SQL> SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
Table created.
SQL> SQL>
1 row created.
SQL>
1 row created.
SQL>
2 rows created.
SQL>
8 rows created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
16 rows created.
SQL>
32 rows created.
SQL>
64 rows created.
n s e
SQL>
i ce
128 rows created.
b l el
SQL>
fer a
256 rows created.
a n s
n -tr
o
an
SQL>
512 rows created.
h s
a deฺ
SQL>
e )
s Gui
1024 rows created. r ฺ
i ent
p ฺ m d
SQL>
2048 rows created. @ d g S t u
b i a t h is
SQL>
i a (ja use
b
4096 rows
A to
created.
n i o
ntoSQL>
e A 8192 rows created.
J o s SQL>
16384 rows created.
SQL>
32768 rows created.
SQL>
65536 rows created.
SQL>
131072 rows created.
SQL>
262144 rows created.
SQL>
524288 rows created.
SQL>
1048576 rows created.
SQL> SQL>
Commit complete.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL> SQL>
System altered.
n s e
i ce
--------------------------------------------------------------
b l el
fer a
#!/bin/bash
a n s
o n -tr
an
cd /home/oracle/solutions/Query_Result_Cache
export ORACLE_SID=orcl
h s
a deฺ
e )
s Gui
r ฺ
i ent
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
p ฺ m d
export
d g S t u
b i a@ this
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
sqlplus b/ia
(ja u<<FIN!
se
A to
as sysdba
o
ni echo on
ntoset
e A
J o s drop user qrc cascade;
connect qrc/qrc
exec dbms_result_cache.flush;
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> @check_result_cache
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
SQL>
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
set echo on
3) Set timing on and execute the query as follows. You can use the query1.sql
n s e
script. Note the time that it takes to execute.
i ce
select /*+ result_cache q_name(Q1) */ count(*) b l el
from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv
fer a
c4,cachejfv c5,cachejfv c6, cachejfv c7
a n s
n -tr
where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
o
an
c5.c='b' and c6.c='b' and c7.c='b';
SQL> set timing on
h s
a deฺ
SQL> @query1
e )
s Gui
r ฺ
COUNT(*)
p ฺ mi dent
----------
1 d g Stu
b i a@ this
SQL>
i a (ja use
Elapsed: 00:00:02.46
A b to
i o
ton
--------------------------------------------------------------
Elapsed: 00:00:00.05
SQL>
SQL> set linesize 180
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
--------------------------------------------
Plan hash value: 2531260445
n s e
i ce
--------------------------------------------------------------------
b l el
--------------------------------------
| Id | Operation | Name
fe
|r a
Rows | Bytes | Cost (%CPU)| Time |
a n s
- tr
--------------------------------------------------------------------
n
o
an
--------------------------------------
| 0 | SELECT STATEMENT | |
1 | 1764 | 7316P (1)|999:59:59 |
h s
a deฺ
| 1 | RESULT CACHE )
s Gui
| b7rh5vw33py4ug4n8xaav6525g |
e
r ฺ
mi dent
| | | |
| 2 | SORT AGGREGATE
p ฺ
g Stu
| |
1 | 1764 | |
d |
| 3 |
294P| b i a@ this
MERGE JOIN CARTESIAN
15E| 7316P (1)|999:59:59 |
| |
| 4 |
i a (ja use
MERGE JOIN CARTESIAN | |
b
941T| 1264P|
A to
23P (1)|999:59:59 |
o
|
n io
5 |
3007G| 3446T|
MERGE JOIN CARTESIAN |
74T (1)|999:59:59 |
|
nt
e A | 6 | MERGE JOIN CARTESIAN | |
J o s 9606M| 9018G|
| 7 |
238G (1)|999:59:59 |
MERGE JOIN CARTESIAN | |
30M| 21G| 761M (1)|999:59:59 |
| 8 | MERGE JOIN CARTESIAN| |
98011 | 47M| 2432K (1)| 08:06:26 |
|* 9 | TABLE ACCESS FULL | CACHEJFV |
313 | 78876 | 7748 (1)| 00:01:33 |
| 10 | BUFFER SORT | |
313 | 78876 | 2424K (1)| 08:04:53 |
|* 11 | TABLE ACCESS FULL | CACHEJFV |
313 | 78876 | 7746 (1)| 00:01:33 |
| 12 | BUFFER SORT | |
313 | 78876 | 761M (1)|999:59:59 |
|* 13 | TABLE ACCESS FULL | CACHEJFV |
313 | 78876 | 7746 (1)| 00:01:33 |
| 14 | BUFFER SORT | |
313 | 78876 | 238G (1)|999:59:59 |
|* 15 | TABLE ACCESS FULL | CACHEJFV |
313 | 78876 | 7746 (1)| 00:01:33 |
| 16 | BUFFER SORT | |
313 | 78876 | 74T (1)|999:59:59 |
| 20 | BUFFER SORT | |
313 | 78876 | 7316P (1)|999:59:59 |
|* 21 | TABLE ACCESS FULL | CACHEJFV |
313 | 78876 | 7746 (1)| 00:01:33 |
--------------------------------------------------------------------
--------------------------------------
n s e
1 - SEL$1
i ce
9 - SEL$1 / C7@SEL$1
b l el
11
13
-
-
SEL$1
SEL$1
/
/
C6@SEL$1
C5@SEL$1
fer a
15 - SEL$1 / C4@SEL$1
a n s
17 - SEL$1 / C3@SEL$1
n - tr
o
an
19 - SEL$1 / C2@SEL$1
21 - SEL$1 / C1@SEL$1
h s eฺ
a did):
Predicate Information (identified by )operation i
i r ฺes nt Gu
---------------------------------------------------
g p ฺm ude
d
9 - filter("C7"."C"='b')
S t
@ s
thi
11 - filter("C6"."C"='b')
b ia
13 - filter("C5"."C"='b')
a
j e
ia ( to us
15 - filter("C4"."C"='b')
b
17 - filter("C3"."C"='b')
n i o Afilter("C2"."C"='b')
19 -
nto 21 - filter("C1"."C"='b')
e A
J o s Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - COUNT(*)[22]
2 - (#keys=0) COUNT(*)[22]
3 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500],
"C4"."C"[VARCHAR2,500], "C3"."C"[VARCHAR2,500],
"C2"."C"[VARCHAR2,500], "C1"."C"[VARCHAR2,500]
4 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500],
"C4"."C"[VARCHAR2,500], "C3"."C"[VARCHAR2,500],
"C2"."C"[VARCHAR2,500]
5 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500],
"C4"."C"[VARCHAR2,500], "C3"."C"[VARCHAR2,500]
6 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500],
"C4"."C"[VARCHAR2,500]
7 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500]
14 - (#keys=0) "C4"."C"[VARCHAR2,500]
15 - "C4"."C"[VARCHAR2,500]
16 - (#keys=0) "C3"."C"[VARCHAR2,500]
17 - "C3"."C"[VARCHAR2,500]
18 - (#keys=0) "C2"."C"[VARCHAR2,500]
19 - "C2"."C"[VARCHAR2,500]
20 - (#keys=0) "C1"."C"[VARCHAR2,500]
21 - "C1"."C"[VARCHAR2,500]
an
c5,cachejfv c6, cac"
h s
a deฺ
Note
e )
s Gui
r ฺ
mithisdstatement
nt
-----
ฺ
- dynamic sampling used for
p
g Stu e
89 rows selected. @d
b i a t h is
i a (ja use
Elapsed: 00:00:00.03
SQL>
A b to
ni o
nto--------------------------------------------------------------
e A
J o s set echo on
v$result_cache_objects order by 1;
b i a to
--------------------------------------------------------------
o A
ni echo on
toset
A n
o s e set long 2000
J select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
6) Flush the buffer cache of your instance and rerun the query executed in step 3. What
do you observe?
a) The execution time for the query is now almost instantaneous.
SQL> alter system flush buffer_cache;
System altered.
Elapsed: 00:00:00.05
SQL> @query1
SQL> select /*+ result_cache q_name(Q1) */ count(*)
2 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
c5,cachejfv c6, cachejfv c7
COUNT(*)
----------
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Elapsed: 00:00:00.00
SQL>
--------------------------------------------------------------
Elapsed: 00:00:00.00
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
--------------------------------------------------------------
set echo on
s an
SQL> @query1
) h i d eฺ
a*/ count(*)
es t Gc3,cachejfv
u
SQL> select /*+ result_cache q_name(Q1)
i r ฺ
2 from cachejfv c1,cachejfv c2,cachejfv
c5,cachejfv c6, cachejfv c7 m n
c4,cachejfv
i a @ his S
c5.c='b' and c6.c='b' and c7.c='b';
COUNT(*) (ja
b et
b ia to us
----------
n i oA 1
ntoElapsed: 00:00:02.33
e A SQL>
J o s SQL> @check_result_cache
SQL> set echo on
SQL>
SQL> set long 2000
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
Elapsed: 00:00:00.00
SQL>
n s e
--------------------------------------------------------------
i ce
b l el
select /*+ result_cache q_name(Q1) */ count(*)
from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
fe ra
c5,cachejfv c6, cachejfv c7
a n s
o n -tr
where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and c5.c='b'
an
and c6.c='b' and c7.c='b';
h s
a deฺ
e )
s Gui
set echo on r ฺ
i ent
p ฺ m
set long 2000
d g Stud
b i a@ this
select type,status,name,object_no,row_count,row_size_avg from
j a e
ia ( to us
v$result_cache_objects order by 1;
b
n io A a detailed result cache memory report.
9)oGenerate
t
e An SQL> set serveroutput on
Jos SQL> EXEC DBMS_RESULT_CACHE.MEMORY_REPORT(detailed=>true);
R e s u l t C a c h e M e m o r y R e p o r t
[Parameters]
Block Size = 1K bytes
Maximum Cache Size = 2080K bytes (2080 blocks)
Maximum Result Size = 104K bytes (104 blocks)
[Memory]
Total Memory = 116008 bytes [0.035% of the Shared Pool]
... Fixed Memory = 5132 bytes [0.002% of the Shared Pool]
....... Cache Mgr = 108 bytes
....... Memory Mgr = 124 bytes
....... Bloom Fltr = 2K bytes
....... State Objs = 2852 bytes
... Dynamic Memory = 110876 bytes [0.033% of the Shared Pool]
....... Overhead = 78108 bytes
........... Hash Table = 32K bytes (4K buckets)
........... Chunk Ptrs = 12K bytes (3K slots)
........... Chunk Maps = 12K bytes
........... Miscellaneous = 20764 bytes
....... Cache Memory = 32K bytes (32 blocks)
Elapsed: 00:00:00.12
SQL>
10) Execute your query from step 3 and step 6 again. What do you observe?
a) The query again uses the result that was previously cached.
SQL> @query1
n s e
ice
el
SQL> select /*+ result_cache q_name(Q1) */ count(*)
2 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
a b l
c5,cachejfv c6, cachejfv c7
fe r
3 where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
a n s
-tr
c5.c='b' and c6.c='b' and c7.c='b';
o n
an
COUNT(*)
----------
1 h s
a deฺ
e )
s Gui
r ฺ
Elapsed: 00:00:00.01
SQL> p ฺ mi dent
d g Stu
i a@ this
--------------------------------------------------------------
b
i a (ja use q_name(Q1) */ count(*)
select /*+ result_cache
A b
from cachejfv o
tcachejfv
c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
o
ni c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and c5.c='b'
c5,cachejfv c6, c7
ntowhere
e A and c6.c='b' and c7.c='b';
J o s
11) Ensure that you bypass the result cache before performing the next step.
SQL>
SQL> exec DBMS_RESULT_CACHE.BYPASS(bypass_mode=>true);
Elapsed: 00:00:00.01
SQL>
Elapsed: 00:00:02.34
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
--------------------------------------------------------------
n s e
i ce
13) Ensure that you no longer bypass the result cache and check that your query uses it
again. b l el
fe ra
SQL> exec DBMS_RESULT_CACHE.BYPASS(bypass_mode=>false);
a n s
PL/SQL procedure successfully completed. o n -tr
s an
Elapsed: 00:00:00.01
) h a deฺ
SQL> @query1
r ฺ e ui
s */Gcount(*)
2 from cachejfv c1,cachejfv
ฺ m ic2,cachejfv
SQL> select /*+ result_cache q_name(Q1)
e nt c3,cachejfv c4,cachejfv
c5,cachejfv c6, cachejfv gc7p d
tuand c3.c='b' and c4.c='b' and
3 where c1.c='b' @ anddc2.c='b'
S
b i
c5.c='b' and c6.c='b' is
a andthc7.c='b';
i a (ja use
b
COUNT(*)
A to
o
----------
i
nton 1
e A
J o s Elapsed: 00:00:00.00
SQL>
SQL>
--------------------------------------------------------------
COUNT(*)
----------
1
Elapsed: 00:00:02.41
SQL>
n s e
ice
--------------------------------------------------------------
b l el
select count(*) fe ra
from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
a n s
c5,cachejfv c6, cachejfv c7
o n -tr
an
where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and c5.c='b'
and c6.c='b' and c7.c='b';
h s
a deฺ
e )
suse the G ui result without using hints?
15) How would you force the previous query r ฺ to cached
Use the force_query2.sqlp ฺ miand dthen
script e t that you successfully used the
nverify
cached result. Finally, undo d g change.
your S tu
b i a@ this
i a
SQL> set echo (jaon use
SQL> @force_query2
SQL>
A b to result_cache_mode
ni
SQL>o show parameter
t o
e An NAME TYPE VALUE
Jos
------------------------------------ ----------- -------------------
-----------
result_cache_mode string MANUAL
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
Elapsed: 00:00:00.00
SQL>
SQL> alter session set result_cache_mode=force;
Session altered.
n s e
i ce
Elapsed: 00:00:00.04
b l el
SQL>
SQL> explain plan for
fer a
2 select count(*)
a n s
-tr
3 from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
n
o
an
c5,cachejfv c6, cachejfv c7
4 where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and
c5.c='b' and c6.c='b' and c7.c='b';
h s
a deฺ
e )
s Gui
Explained. r ฺ
i ent
p ฺ m d
Elapsed: 00:00:00.05
d g S t u
SQL>
i @ his
a180
( j a 200se t
SQL> set linesize
SQL> set pagesize
b
SQL> b ia to u
i o A plan_table_output from
SQL> select
n
ntotable(dbms_xplan.display('plan_table',null,'ALL'));
e A
J o s PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
--------------------------------------------
Plan hash value: 2531260445
--------------------------------------------------------------------
--------------------------------------
| Id | Operation | Name |
Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
--------------------------------------
| 0 | SELECT STATEMENT | |
1 | 1764 | 7316P (1)|999:59:59 |
| 1 | RESULT CACHE | b7rh5vw33py4ug4n8xaav6525g |
| | | |
| 2 | SORT AGGREGATE | |
1 | 1764 | | |
| 3 | MERGE JOIN CARTESIAN | |
294P| 15E| 7316P (1)|999:59:59 |
o n io
313 | 78876 | 7316P (1)|999:59:59 |
|* 21 | TABLE ACCESS FULL | CACHEJFV |
nt
e A 313 | 78876 | 7746 (1)| 00:01:33 |
J o s --------------------------------------------------------------------
--------------------------------------
1 - SEL$1
9 - SEL$1 / C7@SEL$1
11 - SEL$1 / C6@SEL$1
13 - SEL$1 / C5@SEL$1
15 - SEL$1 / C4@SEL$1
17 - SEL$1 / C3@SEL$1
19 - SEL$1 / C2@SEL$1
21 - SEL$1 / C1@SEL$1
9 - filter("C7"."C"='b')
11 - filter("C6"."C"='b')
13 - filter("C5"."C"='b')
-----------------------------------------------------------
1 - COUNT(*)[22]
2 - (#keys=0) COUNT(*)[22]
3 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500],
"C4"."C"[VARCHAR2,500], "C3"."C"[VARCHAR2,500],
"C2"."C"[VARCHAR2,500], "C1"."C"[VARCHAR2,500]
4 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500],
n s e
"C4"."C"[VARCHAR2,500], "C3"."C"[VARCHAR2,500],
i ce
"C2"."C"[VARCHAR2,500]
b l el
5 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500],
fer a
"C4"."C"[VARCHAR2,500], "C3"."C"[VARCHAR2,500]
a n s
-tr
6 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
n
o
an
"C5"."C"[VARCHAR2,500],
"C4"."C"[VARCHAR2,500]
h s
a deฺ
7 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500],
"C5"."C"[VARCHAR2,500]
e )
s Gui
r ฺ
mi dent
8 - (#keys=0) "C7"."C"[VARCHAR2,500], "C6"."C"[VARCHAR2,500]
9 - "C7"."C"[VARCHAR2,500]
p ฺ
g Stu
d
10 - (#keys=0) "C6"."C"[VARCHAR2,500]
b i a@ this
11 - "C6"."C"[VARCHAR2,500]
12 - (#keys=0) "C5"."C"[VARCHAR2,500]
i a (ja use
13 - "C5"."C"[VARCHAR2,500]
b to
14 - (#keys=0) "C4"."C"[VARCHAR2,500]
A
o n io
15 - "C4"."C"[VARCHAR2,500]
16 - (#keys=0) "C3"."C"[VARCHAR2,500]
nt
e A 17 - "C3"."C"[VARCHAR2,500]
J o s 18 - (#keys=0) "C2"."C"[VARCHAR2,500]
19 - "C2"."C"[VARCHAR2,500]
20 - (#keys=0) "C1"."C"[VARCHAR2,500]
21 - "C1"."C"[VARCHAR2,500]
1 - column-count=1; dependencies=(QRC.CACHEJFV);
attributes=(single-row); parameters=(nls); name="select count(*)
from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
c5,cachejfv c6, cachejfv c7
where c1.c='b' and c2."
Note
-----
- dynamic sampling used for this statement
89 rows selected.
COUNT(*)
----------
1
Elapsed: 00:00:00.04
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
n s e
i ce
TYPE STATUS NAME
b l el
OBJECT_NO ROW_COUNT
---------- --------- -----------------------------------------------
fer a
n s
--------------------------------------------------------------------
a
------------- ---------- ----------
o n -tr
an
ROW_SIZE_AVG
------------
Dependency Published QRC.CACHEJFV
h s
a deฺ
71474 0
e )
s Gui
0 r ฺ
i ent
p ฺ m d
Result Invalid
d g
select
t u
/*+ result_cache
S
q_name(Q1) */ count(*)
0 1
b i a@fromthcachejfv
is c1,cachejfv c2,cachejfv
c3,cachejfv ( j a
c4,cachejfv s e c5,cachejfv c6, cac
b i a5
to u
i o A
n
toResult Published select /*+ result_cache q_name(Q1) */ count(*)
A n 0 1
Elapsed: 00:00:00.00
SQL>
SQL> alter session set result_cache_mode=manual;
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL>
--------------------------------------------------------------
set echo on
select count(*)
from cachejfv c1,cachejfv c2,cachejfv c3,cachejfv c4,cachejfv
c5,cachejfv c6, cachejfv c7
where c1.c='b' and c2.c='b' and c3.c='b' and c4.c='b' and c5.c='b'
and c6.c='b' and c7.c='b';
an
and c6.c='b' and c7.c='b';
s
a deฺ
v$result_cache_objects order by 1; ) h
select type,status,name,object_no,row_count,row_size_avg from
r ฺ e s Gui
ฺ mi dent
alter session set result_cache_mode=manual;
p
d g Stu
i @ V$RESULT_CACHE_OBJECTS
aQuery h is
a b
16) Clear the result cache.
e t to verify the clear
operation. a (j u s
b i t o
i o A dbms_result_cache.flush;
SQL> exec
n
to
e An PL/SQL procedure successfully completed.
Jos Elapsed: 00:00:00.01
SQL> select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
no rows selected
Elapsed: 00:00:00.00
SQL>
17) Create a PL/SQL function that uses the result cache by running the cre_func.sql
script.
SQL> @cre_func
SQL> create or replace function CACHEJFV_COUNT(v varchar2)
2 return number
3 result_cache relies_on (cachejfv)
4 is
5 cnt number;
6 begin
7 select count(*) into cnt
12 /
Function created.
Elapsed: 00:00:00.15
SQL>
--------------------------------------------------------------
Anto
e no rows selected
Jos Elapsed: 00:00:00.00
SQL>
19) Call the new function with ‘b’ as its argument. What do you observe?
a) It takes a long time to execute because the result is not cached yet. After
executing the function, the function’s result for the ‘b’ argument is cached.
SQL> select cachejfv_count('b') from dual;
CACHEJFV_COUNT('B')
-------------------
1
Elapsed: 00:00:01.56
SQL>
SQL> select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
------------
Dependency Published QRC.CACHEJFV_COUNT
71475 0
0
Result Published
n s e
"QRC"."CACHEJFV_COUNT"::8."CACHEJFV_COUNT"#8440831613f0f5d3 #1
i ce
0 1
b l el
4
fe ra
a n s
Elapsed: 00:00:00.00
o n -tr
an
SQL>
SQL>
h s
a What edoฺ you observe?
20) Call the new function with ‘b’ as its argument )
s Guagain. i d
a) This time the function executes m i
almostrฺeinstantaneously.
nt
p ฺ
g Sfrom d e
d
SQL> select cachejfv_count('b') tu dual;
b i a@ this
i a (ja use
CACHEJFV_COUNT('B')
-------------------
A b to1
ni o
t o
An SQL>
Elapsed: 00:00:00.00
e
Jos 21) Call the new function with ‘c’ as its argument again. What do you observe?
a) Again it takes a long time to execute the function because of the new value for the
argument. After execution, the second result is cached.
SQL> select cachejfv_count('c') from dual;
CACHEJFV_COUNT('C')
-------------------
1
Elapsed: 00:00:04.15
SQL> select type,status,name,object_no,row_count,row_size_avg from
v$result_cache_objects order by 1;
Result Published
"QRC"."CACHEJFV_COUNT"::8."CACHEJFV_COUNT"#8440831613f0f5d3 #1
0 1
4
Result Published
n s e
"QRC"."CACHEJFV_COUNT"::8."CACHEJFV_COUNT"#8440831613f0f5d3 #1
i ce
0 1
b l el
4
fer a
a n s
Elapsed: 00:00:00.01
n -tr
o
an
SQL>
SQL>
h
SQL> select cachejfv_count('c') from dual; s
a deฺ
e )
s Gui
CACHEJFV_COUNT('C') r ฺ
i ent
-------------------
p ฺ m
1
d g Stud
b i
Elapsed: 00:00:00.00 a@ this
SQL>
i a (ja use
A b to
i o
nton
e A
J o s
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
script. This script creates a new user called EP and a table called TEST used
throughout this lab.
[oracle@edrsr33p1-orcl Explain_Plan]$ ./ep_setup.sh
b i a@ this
SQL>
i a (ja use
A b usertoep identified by ep default tablespace users
SQL> create
n i o
temporary tablespace temp;
nt o
e A User created.
J o s SQL>
SQL> grant connect, resource, dba to ep;
Grant succeeded.
SQL>
SQL> connect ep/ep
Connected.
SQL>
SQL> drop table test purge;
drop table test purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> create table test(c number, d varchar2(500));
Table created.
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
4 end loop;
5 commit;
6 end;
7 /
SQL>
n s e
SQL> create index test_c_indx on test(c);
i ce
b l el
Index created.
fer a
SQL>
a n s
SQL> exec dbms_stats.gather_schema_stats('EP');
n -tr
o
PL/SQL procedure successfully completed.
s an
) h a deฺ
SQL>
r ฺ e s Gui
ฺ m i ent
SQL> alter system flush shared_pool;
System altered.
d p
g Stud
SQL> b i a@ this
i a (ja flush
SQL> alter system
u se buffer_cache;
A b
altered. t
o
ni o
System
ntoSQL>
e A
J o s SQL> set echo off
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Explain_Plan]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Explain_Plan
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
connect ep/ep
e A
Jos
alter system flush buffer_cache;
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1;
exit;
2) From the same terminal session (referred to as session 1 in the rest of this lab), be
ready to execute the ep_session_issue.sh script. Enter the command, but do
not execute it yet.
Session 1:
----------
--------------------------------------------------------------
cd /home/oracle/solutions/Explain_Plan
export ORACLE_SID=orcl
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
n s e
set echo off
i ce
set termout off
b l el
alter session set optimizer_mode=rule;
fe r a
a n s
set termout on
o n -tr
an
set echo on
set timing on
h s
a deฺ
e )
st2 where i
ut1.c=t2.c
select count(*) from test t1, test
i r ฺ n t G and t1.c=1;
m
exit;
d gpฺ Stude
b i a@ this
ja usession
3) From a second (terminal
a se (referred to as session 2 in the rest of this lab),
connect as i to user. After this, connect to a SQL*Plus session as the SYS
b the oracle
i
user.o A
From that SQL*Plus session, be ready to use SQL Monitoring to monitor the
t o n
e An execution plan used by session 1. You can execute the ep_monitoring.sql
script for that purpose. Enter the command, but do not execute it yet. Note: Ensure
Jos that you understand the coordination between both sessions by pre-reading steps 4
and 5 before you continue.
Session 2:
----------
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> @ep_monitor
set echo on
set long 10000000
set longchunksize 10000000
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
exec dbms_lock.sleep(8);
select
dbms_sqltune.report_sql_monitor(sql_id=>'dkz7v96ym42c6',report_level
=>'ALL') from dual;
n s e
4) After you are ready in both the sessions, press [Enter] in session 1 to start the
ice
execution of the ep_session_issue.sh script. Note: Do not wait. Proceed with
b l el
the next step immediately.
fe ra
a n s
-tr
Session 1:
----------
o n
s an
[oracle@edrsr33p1-orcl Explain_Plan]$ ./ep_session_issue.sh
SQL*Plus: Release 11.1.0.6.0 - Production
h a on Wedd ฺ 2 20:12:47 2008
eApr
) i
Copyright (c) 1982, 2007, Oracle.i r ฺesAllnrights
t Gu reserved.
g p ฺm ude
d S t
@ s
thi Edition Release 11.1.0.6.0 -
ia Enterprise
Connected to:
Oracle Database b
Production ( j a 11g
e
b a to us Oracle Label Security, OLAP, Data Mining
iPartitioning,
A Application Testing options
With the
andoReal
i
to n
A n SQL>
SQL> @ep_monitor
SQL> set long 10000000
SQL> set longchunksize 10000000
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> select
dbms_sqltune.report_sql_monitor(sql_id=>'dkz7v96ym42c6',report_level
n s e
=>'ALL') from dual;
i ce
b l el
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
f e ra
ns
:SESSID,REPORT_LEVEL=>'ALL')
- t r a
--------------------------------------------------------------------
n
--------------------------------------------------------------------
o
an
----------------------------------------------------------------
SQL Monitoring Report
h s
a deฺ
SQL Text
e )
s Gui
r ฺ
mi dent
--------------------------------------------------------------------
p ฺ
--------------------------------------------------------------------
dg S tu t2 where t1.c=t2.c and t1.c=1
-------------------------------------------
select count(*) from@
b i a t h is
test t1, test
(ja use
--------------------------------------------------------------------
b a
--------------------------------------------------------------------
i to
-------------------------------------------
o A
t o ni Information
Global
An Status : EXECUTING
e
Jos
Instance ID : 1
Session ID : 138
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777222
Plan Hash Value : 1643938535
Execution Started : 04/02/2008 20:12:46
First Refresh Time : 04/02/2008 20:12:54
Last Refresh Time : 04/02/2008 20:12:56
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
| 8.10 | 8.09 | 0.01 | 134K |
-----------------------------------------
=================================================================
| 0 | SELECT STATEMENT | | | |
| | 1 | | | |
| 1 | SORT AGGREGATE | | | |
1 | +6 | 1 | 0 | 12.50 | Cpu (1) |
| -> 2 | NESTED LOOPS | | | |
3 | +8 | 1 | 79096K | | |
| -> 3 | INDEX RANGE SCAN | TEST_C_INDX | | |
3 | +8 | 1 | 3954 | | |
| -> 4 | INDEX RANGE SCAN | TEST_C_INDX | | |
n s e
9 | +2 | 3955 | 79096K | 87.50 | Cpu (7) |
i ce
====================================================================
b l el
=================================================================
fer a
a n s
SQL>
o n -tr
an
SQL> /
h s
a deฺ
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
:SESSID,REPORT_LEVEL=>'ALL')
e )
s Gui
r ฺ
i ent
--------------------------------------------------------------------
ฺ m
--------------------------------------------------------------------
p d
d g t u
----------------------------------------------------------------
S
SQL Monitoring Report
b i a@ this
SQL Text
i a (ja use
b to
--------------------------------------------------------------------
A
i o
--------------------------------------------------------------------
n
nto-------------------------------------------
e A select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
J o s --------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
Status : EXECUTING
Instance ID : 1
Session ID : 138
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777222
Plan Hash Value : 1643938535
Execution Started : 04/02/2008 20:12:46
First Refresh Time : 04/02/2008 20:12:54
Last Refresh Time : 04/02/2008 20:12:58
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
| 10 | 10 | 0.01 | 167K |
-----------------------------------------
an
====================================================================
=================================================================
h s
a deฺ
e )
s Gui
SQL> / r ฺ
i ent
p ฺ m d
d g t u
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
S
b i a@ this
:SESSID,REPORT_LEVEL=>'ALL')
--------------------------------------------------------------------
i a (ja use
--------------------------------------------------------------------
b to
----------------------------------------------------------------
A
o
ni Text
SQL Monitoring Report
ntoSQL
e A
J o s --------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
Status : EXECUTING
Instance ID : 1
Session ID : 138
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777222
Plan Hash Value : 1643938535
Execution Started : 04/02/2008 20:12:46
First Refresh Time : 04/02/2008 20:12:54
Last Refresh Time : 04/02/2008 20:13:00
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
an
| -> 3 | INDEX RANGE SCAN | TEST_C_INDX | | |
7 | +8 | 1 | 5664 | | |
| -> 4 |
h s
a deฺ
INDEX RANGE SCAN | TEST_C_INDX | | |
13 | +2 | 5665 | 113M |
e )
s Gui
91.67 | Cpu (11) |
r ฺ
mi dent
====================================================================
p ฺ
=================================================================
g Stu
d
SQL> / b i a@ this
i a (ja use
b to
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
A
i o
:SESSID,REPORT_LEVEL=>'ALL')
n
nto--------------------------------------------------------------------
e A --------------------------------------------------------------------
J o s ----------------------------------------------------------------
SQL Monitoring Report
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
Status : EXECUTING
Instance ID : 1
Session ID : 138
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777222
Plan Hash Value : 1643938535
Execution Started : 04/02/2008 20:12:46
First Refresh Time : 04/02/2008 20:12:54
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
| 20 | 20 | 0.04 | 334K |
-----------------------------------------
i a (ja use
=================================================================
Ab to
o n io
SQL> /
nt
e A
J o s DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
:SESSID,REPORT_LEVEL=>'ALL')
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL Monitoring Report
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
Status : EXECUTING
Instance ID : 1
Session ID : 138
SQL ID : dkz7v96ym42c6
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
| 28 | 28 | 0.05 | 468K |
-----------------------------------------
24 | +8 |
i a (ja use
1 | 12518 | | |
| -> 4 |
Ab to
INDEX RANGE SCAN | TEST_C_INDX | | |
o n io
30 | +2 | 12519 | 250M | 96.55 | Cpu (28) |
====================================================================
nt
e A =================================================================
J o s
SQL> /
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
:SESSID,REPORT_LEVEL=>'ALL')
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL Monitoring Report
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
| 40 | 40 | 0.06 | 669K |
-----------------------------------------
n s e
i ce
b l el
SQL Plan Monitoring Details
fer
==================================================================== a
n s
=================================================================
a
| Id | Operation | Name | Rows
n - tr
| Cost |
o
an
Time | Start | Starts | Rows | Activity | Activity Detail |
| | | | (Estim) | |
Active(s) | Active |
h s
a deฺ
| (Actual) | (percent) | (sample #)
|
e )
s Gui
r ฺ
mi dent
====================================================================
p ฺ
=================================================================
g Stu
|
d
0 | SELECT STATEMENT | | | |
|
| 1 |
| 1 |
b i a@ this
SORT AGGREGATE
|
|
|
| |
|
|
35 | +6 |
i a (ja use
1 | 0 | 4.88 | Cpu (2) |
| -> 2 |
Ab to
NESTED LOOPS | | | |
o n io
36 |
| -> 3 |
+8 | 1 | 353M | |
INDEX RANGE SCAN | TEST_C_INDX | | |
|
nt
e A 36 | +8 | 1 | 17663 | | |
J o s | -> 4 |
42 |
INDEX RANGE SCAN | TEST_C_INDX |
+2 | 17664 | 353M | 95.12 | Cpu (39)
| |
|
====================================================================
=================================================================
SQL> /
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
:SESSID,REPORT_LEVEL=>'ALL')
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL Monitoring Report
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
Global Information
Status : DONE (ALL ROWS)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Instance ID : 1
Session ID : 138
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777222
Plan Hash Value : 1643938535
Execution Started : 04/02/2008 20:12:46
First Refresh Time : 04/02/2008 20:12:54
Last Refresh Time : 04/02/2008 20:13:34
-------------------------------------------------
n s e
| Elapsed | Cpu | Other | Fetch | Buffer |
ice
| Time(s) | Time(s) | Waits(s) | Calls | Gets |
b l el
-------------------------------------------------
| 46 | 46 | 0.06 | 1 | 760K |
fe r a
-------------------------------------------------
a n s
o n -tr
SQL Plan Monitoring Details
s an
h a deฺ
====================================================================
)
s G| uRows i
===============================================================
e
| rฺName
| iActivity t
| Id | Operation | Cost | Time
| Start | Starts | Rows ฺm n
p | tude | (Estim) |
| Activity Detail |
| |
Active(s) | Active |@ d g | S
|
i a (ja use
====================================================================
b to
===============================================================
A
1ni|
o
| 0 | SELECT STATEMENT | | | |
e A | | |
J o s 43 |
| 2 |
+6 | 1 |
NESTED LOOPS |
1 | 4.35 | Cpu (2)
| | |
|
41 | +8 | 1 | 400M | | |
| 3 | INDEX RANGE SCAN | TEST_C_INDX | | |
41 | +8 | 1 | 20000 | | |
| 4 | INDEX RANGE SCAN | TEST_C_INDX | | |
47 | +2 | 20000 | 400M | 95.65 | Cpu (44) |
====================================================================
===============================================================
SQL>
6) After approximately 47 seconds (depending on your environment), you should see the
following output in your session 1:
Session 1:
----------
COUNT(*)
----------
400000000
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Elapsed: 00:00:47.21
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Explain_Plan]$
n s e
i ce
7) From session 1, connect as the EP user in the SQL*Plus session.
b l el
Session 1:
fe ra
----------
a n s
o
[oracle@edrsr33p1-orcl Explain_Plan]$ sqlplus ep/ep n -tr
n
SQL*Plus: Release 11.1.0.6.0 - Production s onaWed Apr 2 20:14:03 2008
) h a deฺ
Copyright (c) 1982, 2007, Oracle.ฺes
r G uireserved.
All rights
p ฺ mi dent
d g Stu
a@
Connected to:
b i
Oracle Database 11g
t h is Edition Release 11.1.0.6.0 -
Enterprise
Production
a (ja useOracle Label Security, OLAP, Data Mining
With the iPartitioning,
A
and Real to Testing options
b Application
ni o
ntoSQL>
e A
J o s 8) Use PLAN_TABLE to determine the execution plan of the query that was executed in
step 4. What do you observe?
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1;
a) This time the execution plan uses a hash join on top of two index fast full scans.
Session 1:
----------
SQL> @ep_explain
SQL>
SQL> set linesize 200 pagesize 1000
SQL>
SQL> explain plan for
2 select count(*) from test t1, test t2 where t1.c=t2.c and
t1.c=1;
Explained.
SQL>
SQL> select * from table(dbms_xplan.display);
--------------------------------------------------------------------
------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 2131
(99)| 00:00:22 |
| 1 | SORT AGGREGATE | | 1 | 6 |
n s e
| |
i ce
|* 2 | HASH JOIN | | 400M| 2288M| 2131
b l el
(99)| 00:00:22 |
|* 3 | INDEX FAST FULL SCAN| TEST_C_INDX | 20000 | 60000 | 13
fe r a
(0)| 00:00:01 |
a n s
|* 4 | -
INDEX FAST FULL SCAN| TEST_C_INDX | 20000 | 60000 |
n tr
13
o
an
(0)| 00:00:01 |
--------------------------------------------------------------------
------------------
h s
a deฺ
e )
s Gui id):
r ฺ
mi dent
Predicate Information (identified by operation
p ฺ
---------------------------------------------------
g Stu
d
b i a@ this
2 - access("T1"."C"="T2"."C")
3 - filter("T1"."C"=1)
i a (ja use
4 - filter("T2"."C"=1)
A bselected.to
ni o
18 rows
ntoSQL>
e A
J o s --------------------------------------------------------------
set echo on
9) Now, you want to monitor the previous execution plan to compare it with the one
generated in step 4. In addition, you want to make sure you use the correct plan this
time. So, in your session 1, start autotrace, and be ready to execute the following
query. Do not execute it yet as you need to start SQL Monitoring in your session 2:
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1;
Session 1:
----------
10) From your session 2, be ready to execute your SQL Monitoring command again. Do
not execute it yet though.
Session 2:
----------
SQL> @ep_monitor
n s e
i ce
--------------------------------------------------------------
b l el
fe r a
set echo on
a n s
-tr
set long 10000000
set longchunksize 10000000
o n
an
set linesize 200
set pagesize 1000
h s
a deฺ
exec dbms_lock.sleep(8);
e )
s Gui
r ฺ
select
p ฺ mi dent
dg Stu
dbms_sqltune.report_sql_monitor(sql_id=>'dkz7v96ym42c6',report_level
=>'ALL') from dual; @
b i a t h is
i a (ja use
execution tofoyour query from session 1 by pressing [Enter]. Note: Move to
11) Start the b
i
next o A
stepwithout waiting.
t o n
e An
Jos
Session 1:
----------
SQL> @ep_execute
SQL> set echo on
SQL>
SQL> set timing on
SQL>
SQL> select count(*) from test t1, test t2 where t1.c=t2.c and
t1.c=1;
--------------------------------------------------------------
set echo on
set timing on
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1;
hash join by reading the driving index in memory first. This operation is quick.
Though you cannot see it run, it is already done the first time you can look at it.
Then the probe in performed on the index again. This operation takes more time.
Also note that cost information is provided in the execution plan.
Session 2:
----------
n s e
ice
el
SQL> @ep_monitor
SQL> set echo on
a b l
SQL> set long 10000000
fe r
SQL> set longchunksize 10000000
a n s
-tr
SQL> set linesize 200
SQL> set pagesize 1000
o n
an
SQL>
SQL>exec dbms_lock.sleep(8);
h s
a deฺ
e
PL/SQL procedure successfully completed.)
s Gui
r ฺ
SQL> p ฺ mi dent
SQL> select d g Stu
=>'ALL') from a b ia@ this
dbms_sqltune.report_sql_monitor(sql_id=>'dkz7v96ym42c6',report_level
(j se
dual;
b i a to u
A
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
o
ni
:SESSID,REPORT_LEVEL=>'ALL')
to--------------------------------------------------------------------
A n --------------------------------------------------------------------
o s e ----------------------------------------------------------------
J SQL Monitoring Report
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
Status : EXECUTING
Instance ID : 1
Session ID : 124
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777223
Plan Hash Value : 3253233075
Execution Started : 04/02/2008 20:14:41
First Refresh Time : 04/02/2008 20:14:49
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
o
1 |
|n io +8 | 1 | 20000 | | |
nt
e A | -> 4 | INDEX FAST FULL SCAN | TEST_C_INDX | 20000 | 13 |
J o s 1 |
|
+8 | 1 | 5632 | | |
====================================================================
====================================================================
==========
SQL>
SQL> /
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
:SESSID,REPORT_LEVEL=>'ALL')
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL Monitoring Report
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Status : EXECUTING
Instance ID : 1
Session ID : 124
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777223
Plan Hash Value : 3253233075
Execution Started : 04/02/2008 20:14:41
First Refresh Time : 04/02/2008 20:14:49
Last Refresh Time : 04/02/2008 20:14:51
n s e
-----------------------------------------
i ce
| Elapsed | Cpu | Other | Buffer |
b l el
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
fer a
| 7.86 | 7.86 | 0.00 | 10 |
a n s
-----------------------------------------
o n -tr
s an
SQL Plan Monitoring Details
) h a deฺ
r ฺ e s Gui
====================================================================
========== ฺ m i ent
====================================================================
| Id |
d g
Operation p t u|d Name | Rows | Cost |
Time
a@ this
| Start | Starts | S
Rows | Memory | Activity | Activity
Detail | b i
| |
a ja use
(Active | | (Estim) | |
Active(s) i
b#) | to
| | | (Actual) | | (percent) |
i o A
(sample
n
to====================================================================
A n ====================================================================
o s e ==========
J |
|
0 | SELECT STATEMENT
| 1 | |
|
|
|
|
| 2131 |
|
| 1 | SORT AGGREGATE | | 1 | |
8 | +0 | 1 | 0 | | 20.00 | Cpu (2)
|
| -> 2 | HASH JOIN | | 400M | 2131 |
10 | +1 | 1 | 133M | 1138K | 80.00 | Cpu (8)
|
| 3 | INDEX FAST FULL SCAN | TEST_C_INDX | 20000 | 13 |
1 | +8 | 1 | 20000 | | |
|
| -> 4 | INDEX FAST FULL SCAN | TEST_C_INDX | 20000 | 13 |
3 | +8 | 1 | 6656 | | |
|
====================================================================
====================================================================
==========
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
:SESSID,REPORT_LEVEL=>'ALL')
--------------------------------------------------------------------
--------------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
----------------------------------------------------------------
SQL Monitoring Report
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
--------------------------------------------------------------------
n s e
-------------------------------------------
i ce
b l el
Global Information
Status : EXECUTING
fer a
Instance ID : 1
a n s
Session ID : 124
n -tr
o
an
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777223
Plan Hash Value : 3253233075
h s
a deฺ
Execution Started : )
s Gui
04/02/2008 20:14:41
e
r ฺ
mi dent
First Refresh Time : 04/02/2008 20:14:49
Last Refresh Time : ฺ
04/02/2008 20:14:55
p
g Stu
d
| Elapsed | b
Cpu a@ t
| Other is | Buffer |
-----------------------------------------
i h
| Time(s) | (
a ja u|seWaits(s) | Gets |
Time(s)
b i to12 | 0.00 | 15 |
-----------------------------------------
o A
ni
| 12 |
nto-----------------------------------------
e A
J o s SQL Plan Monitoring Details
====================================================================
====================================================================
==========
| Id | Operation | Name | Rows | Cost |
Time | Start | Starts | Rows | Memory | Activity | Activity
Detail |
| | | | (Estim) | |
Active(s) | Active | | (Actual) | | (percent) |
(sample #) |
====================================================================
====================================================================
==========
| 0 | SELECT STATEMENT | | | 2131 |
| | 1 | | | |
|
| 1 | SORT AGGREGATE | | 1 | |
8 | +0 | 1 | 0 | | 14.29 | Cpu (2)
|
SQL> /
n s e
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
i ce
:SESSID,REPORT_LEVEL=>'ALL')
b l el
fer a
--------------------------------------------------------------------
--------------------------------------------------------------------
n s
----------------------------------------------------------------
a
SQL Monitoring Report
o n -tr
SQL Text
s an
h a deฺ
--------------------------------------------------------------------
)
r ฺ e s Gui
--------------------------------------------------------------------
b i a@ this
--------------------------------------------------------------------
-------------------------------------------
i a (ja use
b to : EXECUTING
Global Information
A
i o
Status
ntonInstance ID : 1
e A Session ID : 124
J o s SQL ID
SQL Execution ID
:
:
dkz7v96ym42c6
16777223
Plan Hash Value : 3253233075
Execution Started : 04/02/2008 20:14:41
First Refresh Time : 04/02/2008 20:14:49
Last Refresh Time : 04/02/2008 20:15:05
-----------------------------------------
| Elapsed | Cpu | Other | Buffer |
| Time(s) | Time(s) | Waits(s) | Gets |
-----------------------------------------
| 22 | 22 | 0.01 | 28 |
-----------------------------------------
====================================================================
====================================================================
==========
| 0 | SELECT STATEMENT | | | 2131 |
| | 1 | | | |
|
| 1 | SORT AGGREGATE | | 1 | |
8 | +0 | 1 | 0 | | 8.33 | Cpu (2)
|
| -> 2 | HASH JOIN | | 400M | 2131 |
n s e
24 | +1 | 1 | 317M | 1138K | 91.67 | Cpu (22)
i ce
|
b l el
|
1 |
3 |
+8 |
INDEX FAST FULL SCAN | TEST_C_INDX |
1 | 20000 | |
20000 |
|
13 |
fer a
|
a n s
| -> 4 | INDEX FAST FULL SCAN | TEST_C_INDX |
o n -tr
20000 | 13 |
an
17 | +8 | 1 | 15872 | | |
|
h s
a deฺ
====================================================================
)
s Gui
====================================================================
e
r ฺ
mi dent
==========
p ฺ
g Stu
d
SQL> /
b i a@ this
i a (ja use
DBMS_SQLTUNE.REPORT_SQL_MONITOR(SQL_ID=>'DKZ7V96YM42C6',SESSION_ID=>
b to
:SESSID,REPORT_LEVEL=>'ALL')
A
i o
--------------------------------------------------------------------
n
nto--------------------------------------------------------------------
e A ----------------------------------------------------------------
SQL Text
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------------------------------
Global Information
Status : DONE (ALL ROWS)
Instance ID : 1
Session ID : 124
SQL ID : dkz7v96ym42c6
SQL Execution ID : 16777223
Plan Hash Value : 3253233075
Execution Started : 04/02/2008 20:14:41
First Refresh Time : 04/02/2008 20:14:49
Last Refresh Time : 04/02/2008 20:15:11
-------------------------------------------------
| 3 |
i a (ja use
INDEX FAST FULL SCAN | TEST_C_INDX | 20000 | 13 |
1 |
Ab
+8 |
to
1 | 20000 | | |
o
|
n io
| 4 | INDEX FAST FULL SCAN | TEST_C_INDX | 20000 | 13 |
nt
e A 23 | +8 | 1 | 20000 | | |
J o s |
====================================================================
====================================================================
========
SQL>
13) When your query is executed, what do you observe in your session 1?
a) Session 1 also reports the same execution plan as the one you observed in session
2.
Session 1:
----------
COUNT(*)
Elapsed: 00:00:30.70
Execution Plan
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
----------------------------------------------------------
Plan hash value: 3253233075
--------------------------------------------------------------------
------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 2131
n s e
(99)| 00:00:22 |
i ce
| 1 | SORT AGGREGATE | | 1 | 6 |
b l el
|
|* 2 |
|
HASH JOIN | |
fe
400M| 2288M| 2131 r a
(99)| 00:00:22 |
a n s
|* 3 | - tr
INDEX FAST FULL SCAN| TEST_C_INDX | 20000 | 60000 |
n 13
o
an
(0)| 00:00:01 |
|* 4 | INDEX FAST FULL SCAN| TEST_C_INDX | 20000 | 60000 | 13
(0)| 00:00:01 |
h s
a deฺ
)
s Gui
--------------------------------------------------------------------
e
------------------ r ฺ
i ent
p ฺ m d operation id):
d g
Predicate Information (identified
S t uby
b i a@ this
---------------------------------------------------
i a (ja use
2 - access("T1"."C"="T2"."C")
b to
3 - filter("T1"."C"=1)
A
i o
4 - filter("T2"."C"=1)
nton
e A
J o s Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
90 consistent gets
0 physical reads
0 redo size
418 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
Session 1:
----------
15) From your session 1, how can you ensure that you gather all execution plan statistics
for the following query without changing any session parameters? Implement your
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
solution.
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1;
Session 1:
----------
SQL> @ep_execute_with_all
SQL> set echo on
SQL>
n s e
SQL> set timing on
ice
SQL>
select /*+ gather_plan_statistics */ count(*) from test t1, bl
el
SQL>
test t2 where t1.c=t2.c and t1.c=1; f e ra
t r a ns
COUNT(*)
o n -
an
----------
400000000
h s
a deฺ
Elapsed: 00:00:59.95
e )
s Gui
r ฺ
mi dent
SQL>
p
g Stuฺ
16) From your session 1, retrieve
d
@ hexecution
all plans corresponding to all the queries you
executed since the b i a t i s
( j abeginning
s eof this lab. What is your conclusion?
u
bia waytoto find out all the plans is to look at the content of the SGA using
a) The easiest
A
iothe dbms_xplan.display_cursor function. First, you must determine the
o n
t SQL_Ids used to represent your queries. You essentially have two queries, and
e An one that has two children. You should now understand what happened at step 4.
Jos The fact that there was no cost information is probably due to the use of the rule-
based optimizer instead of the cost-based one.
Session 1:
----------
SQL> @ep_retrieve_all_plans
SQL> set echo on
SQL>
SQL> set linesize 200 pagesize 1000
SQL>
SQL> col sql_text format a50
SQL>
SQL> select sql_id,plan_hash_value,sql_text from v$sql where
sql_text like '%from test t1, test t2%';
p ฺ
g Stu
d
6 rows selected.
b i a@ this
i a (ja use
Elapsed: 00:00:00.02
SQL>
A b * from to
ni o
SQL> select
ntotable(dbms_xplan.display_cursor('dkz7v96ym42c6',null,'TYPICAL'));
e A
J o s PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID dkz7v96ym42c6, child number 0
-------------------------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
------------------
| 0 | SELECT STATEMENT | | | | 2131
(100)| |
| 1 | SORT AGGREGATE | | 1 | 6 |
| |
--------------------------------------------------------------------
------------------
2 - access("T1"."C"="T2"."C")
3 - filter("T1"."C"=1)
4 - filter("T2"."C"=1)
n s e
SQL_ID dkz7v96ym42c6, child number 1
i ce
-------------------------------------
b l el
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
fer a
Plan hash value: 1643938535
a n s
n -tr
o
an
------------------------------------------
| Id | Operation | Name |
------------------------------------------
h s
a deฺ
| 0 | SELECT STATEMENT |
e )
s Gui
|
r ฺ
mi dent
| 1 | SORT AGGREGATE | |
| 2 | NESTED LOOPS |
p ฺ
g Stu
|
|* 3 |
d
INDEX RANGE SCAN| TEST_C_INDX |
|* 4 |
b i a@ this
INDEX RANGE SCAN| TEST_C_INDX |
------------------------------------------
n t o
e A
Jos
4 - access("T1"."C"="T2"."C")
Note
-----
- rule based optimizer used (consider using cbo)
49 rows selected.
Elapsed: 00:00:00.04
SQL>
SQL> select * from
table(dbms_xplan.display_cursor('8w580dd6ncgqw',null,'ADVANCED
ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 8w580dd6ncgqw, child number 0
-------------------------------------
--------------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
-------------------
| Id | Operation | Name | Starts | E-Rows |E-
Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem
| 1Mem | Used-Mem |
--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------
| 1 | SORT AGGREGATE | | 1 | 1 |
6 | | | 1 |00:00:59.94 | 90 | |
n s e
| |
i ce
|* 2 | HASH JOIN | | 1 | 400M|
b l el
2288M| 2131 (99)| 00:00:22 |
1155K| 1155K| 1115K (0)|
400M|00:00:00.01 | 90 |
fer a
|* 3 | INDEX FAST FULL SCAN| TEST_C_INDX | n s
1 | 20000 |
a
60000 | 13 (0)| 00:00:01 | 20000 |00:00:00.02 |
o n -tr 45 |
an
| | |
|* 4 | INDEX FAST FULL SCAN| TEST_C_INDX | 1 | 20000 |
60000 | 13
h s
a deฺ
(0)| 00:00:01 | 20000 |00:00:00.16 | 45 |
| | |
e )
s Gui
r ฺ
mi dent
--------------------------------------------------------------------
p ฺ
--------------------------------------------------------------------
g Stu
-------------------
d
@ Alias
Query Block Namebi/aObjectth is (identified by operation id):
i a (ja use
-------------------------------------------------------------
A b to
i o
1 - SEL$1
e A SEL$1 / T2@SEL$1
J o s Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.1.0.6')
DB_VERSION('11.1.0.6')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
INDEX_FFS(@"SEL$1" "T1"@"SEL$1" ("TEST"."C"))
INDEX_FFS(@"SEL$1" "T2"@"SEL$1" ("TEST"."C"))
LEADING(@"SEL$1" "T1"@"SEL$1" "T2"@"SEL$1")
USE_HASH(@"SEL$1" "T2"@"SEL$1")
END_OUTLINE_DATA
*/
1 - (#keys=0) COUNT(*)[22]
2 - (#keys=1)
3 - "T1"."C"[NUMBER,22]
4 - "T2"."C"[NUMBER,22]
55 rows selected.
Elapsed: 00:00:00.12
n s e
SQL>
i ce
b l el
--------------------------------------------------------------
fe r a
set echo on
a n s
o n -tr
an
set linesize 200 pagesize 1000
p ฺ
like '%from test t1, test t2%';
g Stu
d
select * from
b i a@ this
table(dbms_xplan.display_cursor('dkz7v96ym42c6',null,'TYPICAL'));
i a (ja use
b
select *
A
from
to
ni o
table(dbms_xplan.display_cursor('8w580dd6ncgqw',null,'ADVANCED
ntoALLSTATS LAST'));
e A
J o s 17) From session 1, try to retrieve your execution plans from the Automatic Workload
Repository. What happens and why?
a) You can use the previously found SQL_Ids to search through the
DBA_HIST_SQLTEXT view. You should see that right now, none of your
queries were stored in the AWR.
Session 1:
----------
SQL> @ep_retrieve_awr
SQL> set echo on
SQL>
SQL> set linesize 200
SQL>
SQL> SELECT SQL_ID, SQL_TEXT FROM dba_hist_sqltext
2 WHERE SQL_ID in ('dkz7v96ym42c6','8w580dd6ncgqw');
no rows selected
Elapsed: 00:00:00.01
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
set echo on
n s e
18) How can you ensure that you retrieve your queries from the Automatic Workload
i ce
Repository? Implement your solution.
b l el
a) You must flush the SGA information to the AWR. You can use fer a
DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT for this purpose. a n s
o n -tr
Session 1: a n
----------
h s
a deฺ
e )
s Gui
r ฺ
mi dent
SQL> @ep_save_awr
SQL> set echo on
p ฺ
g Stu
SQL>
d
b i a@ this
SQL> EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT('ALL');
(ja successfully
PL/SQL procedure
i a u se completed.
A to
b 00:00:02.27
ni o
Elapsed:
ntoSQL>
e A
J o s --------------------------------------------------------------
set echo on
EXEC DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT('ALL');
Session 1:
----------
SQL> @ep_show_awr
SQL> set echo on
SQL>
SQL> set linesize 200 pagesize 1000
SQL>
SQL> SELECT PLAN_TABLE_OUTPUT
2 FROM
3 TABLE (DBMS_XPLAN.DISPLAY_AWR('dkz7v96ym42c6'));
--------------------
select count(*) from test t1, test t2 where t1.c=t2.c and t1.c=1
------------------------------------------
| Id | Operation | Name |
------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT AGGREGATE | |
n s e
| 2 | NESTED LOOPS | |
i ce
| 3 | INDEX RANGE SCAN| TEST_C_INDX |
b l el
| 4 | INDEX RANGE SCAN| TEST_C_INDX |
------------------------------------------
fer a
a n s
Note
o n -tr
an
-----
- rule based optimizer used (consider using cbo)
h s
a deฺ
SQL_ID dkz7v96ym42c6
e )
s Gui
-------------------- r ฺ
i t2enwheret t1.c=t2.c and t1.c=1
ฺ
select count(*) from test t1,
p mtest d
d g Stu
b i a@ this
Plan hash value: 3253233075
i a (ja use
--------------------------------------------------------------------
b to
------------------
| Id A
n i o | Operation | Name | Rows | Bytes | Cost
nto--------------------------------------------------------------------
(%CPU)| Time |
e A
J o s ------------------
| 0 | SELECT STATEMENT | | | | 543
(100)| |
| 1 | SORT AGGREGATE | | 1 | 6 |
| |
| 2 | HASH JOIN | | 100M| 572M| 543
(98)| 00:00:06 |
| 3 | INDEX FAST FULL SCAN| TEST_C_INDX | 10000 | 30000 | 8
(0)| 00:00:01 |
| 4 | INDEX FAST FULL SCAN| TEST_C_INDX | 10000 | 30000 | 8
(0)| 00:00:01 |
--------------------------------------------------------------------
------------------
36 rows selected.
Elapsed: 00:00:00.04
SQL>
SQL> SELECT PLAN_TABLE_OUTPUT
2 FROM
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 8w580dd6ncgqw
--------------------
select /*+ gather_plan_statistics */ count(*) from test t1, test t2
where t1.c=t2.c and t1.c=1
--------------------------------------------------------------------
n s e
-------------------
i ce
| Id | Operation | Name | E-Rows |E-Bytes| Cost
b l el
(%CPU)| E-Time |
fer
-------------------------------------------------------------------- a
-------------------
a n s
| 0 | SELECT STATEMENT | |
n -
| tr |
o
an
2131 (100)| |
| 1 | SORT AGGREGATE | | 1 | 6 |
| |
h s
a deฺ
| 2 | HASH JOIN |
e )
s Gui | 400M| 2288M|
r ฺ
mi dent
2131 (99)| 00:00:22 |
| 3 | ฺ
INDEX FAST FULL SCAN| TEST_C_INDX | 20000 | 60000 |
p
g Stu
13 (0)| 00:00:01 |
d
|
13
4 |
b
(0)| 00:00:01 |i a@ this
INDEX FAST FULL SCAN| TEST_C_INDX | 20000 | 60000 |
i a (ja use
--------------------------------------------------------------------
b to
-------------------
A
o n io
Note
nt
e A -----
23 rows selected.
Elapsed: 00:00:00.02
SQL>
--------------------------------------------------------------
set echo on
SELECT PLAN_TABLE_OUTPUT
FROM
TABLE (DBMS_XPLAN.DISPLAY_AWR('dkz7v96ym42c6'));
20) Exit from both SQL*Plus sessions, and clean up your environment by executing the
ep_cleanup.sh script from one of your terminal sessions.
Session 1:
----------
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
n s e
11.1.0.6.0 - Production
i ce
With the Partitioning, Oracle Label Security, OLAP, Data Mining
b l el
and Real Application Testing options
[oracle@edrsr33p1-orcl Explain_Plan]$ ./ep_cleanup.sh fe r a
a n s
n -tr
SQL*Plus: Release 11.1.0.6.0 - Production on Wed Apr 2 20:19:37 2008
o
Copyright (c) 1982, 2007, Oracle. All rights
n
a reserved.
h s
a deฺ
e )
s Gui
r ฺ
miEdition t
Connected to:
p
Oracle Database 11g Enterprise ฺ d e nRelease 11.1.0.6.0 -
Production g
dOracle S t u
@ s
thi options
ia Testing
With the Partitioning, Label Security, OLAP, Data Mining
a b
and Real Application
j e
SQL> b ia ( to us
i
SQL> A user ep cascade;
o drop
to n
A n User dropped.
o s e
J SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Explain_Plan]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Explain_Plan
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
--------------------------------------------------------------
set echo on
exit;
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
/home/oracle/solutions/Star_Schema_Tuning directory.
[oracle@edrsr33p1-orcl Star_Schema_Tuning]$
./setup_star_schema_lab.sh
nt oand options
e A [oracle@edrsr33p1-orcl Star_Schema_Tuning]$
J o s --------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Star_Schema_Tuning
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
set echo on
FIN!
2) From the same terminal window, start a SQL*Plus session connected as the SH user
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
and do not disconnect from it until this lab finishes. Before executing the following
SQL statement, ensure that you flush both the shared pool and the buffer cache to
avoid caching issues as much as possible. After this, analyze the execution of the
following query (You can use the query.sql script.):
-tr
GROUP BY ch.channel_class, c.cust_city, t.calendar_quarter_desc;
o n
What are your conclusions?
s an
a) As you can see in the output of the executionhplan,
) i eฺ seems to use a large
a thisdquery
number of bytes to access the SALESฺe
r s Basically,
table. G u the optimizer performs a
i t
enbest way to handle it.
ฺmnot ubedthe
full scan of this table. This might
d g p t
@ s S
[oracle@edrsr33p1-orcl
j a b e thi
ia Star_Schema_Tuning]$ sqlplus sh/sh
SQL*Plus:ia
( u s
2008 A b t o
Release 11.1.0.6.0 - Production on Fri Mar 21 00:31:10
o n io
nt Copyright (c) 1982, 2007, Oracle. All rights reserved.
e A
J o s
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> @first_run
SQL>
SQL> alter system flush shared_pool;
System altered.
System altered.
SQL>
SQL> set pagesize 200
SQL> set linesize 250
i
----------------------------------------------------------
b
(ja use
Plan hash value: 1647000731
b i a
-------------------------------------------------------------------------------------------------------------
| Id | Operation
to | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
|
i A
-------------------------------------------------------------------------------------------------------------
ton
| 1 | HASH GROUP BY | | 1144 | 96096 | 935 (4)| 00:00:12 | | |
|* 2 | HASH JOIN | | 6231 | 511K| 934 (3)| 00:00:12 | | |
A n |* 3 |
|* 4 |
TABLE ACCESS FULL
HASH JOIN
| CHANNELS |
|
2 |
| 12462 |
42 |
766K|
3
930
(0)| 00:00:01 |
(3)| 00:00:12 |
|
|
|
|
J
|* 6 | TABLE ACCESS FULL | TIMES | 365 | 5840 | 18 (0)| 00:00:01 | | |
|* 7 | HASH JOIN | | 49822 | 2286K| 911 (3)| 00:00:11 | | |
|* 8 | TABLE ACCESS FULL | CUSTOMERS | 383 | 9958 | 406 (1)| 00:00:05 | | |
| 9 | PARTITION RANGE JOIN-FILTER| | 918K| 18M| 498 (4)| 00:00:06 |:BF0000|:BF0000|
| 10 | TABLE ACCESS FULL | SALES | 918K| 18M| 498 (4)| 00:00:06 |:BF0000|:BF0000|
-------------------------------------------------------------------------------------------------------------
2 -
access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
3 -
filter("CH"."CHANNEL_DESC"='Catalog' OR "CH"."CHANNEL_DESC"='Internet')
4 -
access("S"."TIME_ID"="T"."TIME_ID")
6 -
filter("T"."CALENDAR_QUARTER_DESC"='1999-01' OR "T"."CALENDAR_QUARTER_DESC"='1999-02' OR
"T"."CALENDAR_QUARTER_DESC"='2000-03' OR "T"."CALENDAR_QUARTER_DESC"='2000-04')
7 - access("S"."CUST_ID"="C"."CUST_ID")
8 - filter("C"."CUST_STATE_PROVINCE"='CA')
Statistics
----------------------------------------------------------
16783 recursive calls
0 db block gets
5491 consistent gets
2021 physical reads
0 redo size
1888 bytes sent via SQL*Net to client
442 bytes received via SQL*Net from client
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
--------------------------------------------------------------
set echo on
i a (ja use
Ab to
3) Without modifying the SH schema, how can you improve the execution plan for the
o n io
query mentioned in step 2? Verify your solution and explain why it is probably a
nt
e A better solution.
J o s a) Enable star transformation in your session. In this step, you do not want to use a
temporary table for the star transformation. Looking at the previous execution
plan, the optimizer estimates the data that is to be manipulated in megabytes.
Using the star transformation as follows, the estimation is now expressed in
kilobytes. That is why this new execution plan is probably a much better
alternative. However, note that this time the CUSTOMERS table is accessed using
full scan twice. If the table is larger, the impact is significant.
SQL> @second_run
SQL> set echo on
SQL>
SQL>
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.10
SQL> alter system flush buffer_cache;
Elapsed: 00:00:00.20
SQL>
SQL> set pagesize 200
SQL> set linesize 250
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Session altered.
Elapsed: 00:00:00.00
SQL>
n s e
SQL>
i ce
SQL> SELECT ch.channel_class, c.cust_city, t.calendar_quarter_desc,
b l el
2 SUM(s.amount_sold) sales_amount
3 FROM sales s, times t, customers c, channels ch
fer a
4 WHERE s.time_id = t.time_id
a n s
5 AND s.cust_id = c.cust_id
o n -tr
an
6 AND s.channel_id = ch.channel_id
7 AND c.cust_state_province = 'CA'
8 AND
h s
a deฺ
ch.channel_desc in ('Internet','Catalog')
9 AND )
s Gui
t.calendar_quarter_desc IN ('1999-01','1999-02','2000-
e
r ฺ
mi dent
03','2000-04')
p ฺ
10 GROUP BY ch.channel_class, c.cust_city,
g Stu
d
t.calendar_quarter_desc;
@ his
CHANNEL_CLASS bia CUST_CITY
t CALENDA
SALES_AMOUNT(ja e
b ia to us------------------------------ ------- --------
--------------------
---- A
o n io
Indirect San Francisco 2000-04
nt 13227.99
e A
J o s Indirect
1319
Montara 2000-04
41 rows selected.
Elapsed: 00:00:00.33
Execution Plan
----------------------------------------------------------
Plan hash value: 2525768690
a n s
tr
|* 14 | BITMAP INDEX RANGE SCAN | SALES_CHANNEL_BIX | | | |
|KEY(SQ)|KEY(SQ)|
| 15 | BITMAP MERGE |
o n - | | | | |
an
| |
| 16 | BITMAP KEY ITERATION | | | | | |
|
| 17 |
|
BUFFER SORT
h
| s
a deฺ | | | | |
|
|* 18 |
|
TABLE ACCESS FULL
e )
s Gui
| TIMES | 365 | 5840 | 18 (0)| 00:00:01 |
| |
r ฺ
mi dent
|* 19 | BITMAP INDEX RANGE SCAN | SALES_TIME_BIX | | | |
|KEY(SQ)|KEY(SQ)|
| 20 | BITMAP MERGE
p ฺ
g Stu
| | | | | |
| |
d
a@ this
| 21 | BITMAP KEY ITERATION | | | | | |
|
| 22 |
|
b i
BUFFER SORT | | | | | |
(ja use
| |
a
|* 23 | TABLE ACCESS FULL | CUSTOMERS | 383 | 9958 | 406 (1)| 00:00:05 |
| |
b i to
|* 24 |
io A
|KEY(SQ)|KEY(SQ)|
BITMAP INDEX RANGE SCAN | SALES_CUST_BIX | | | |
t o|n
|* 25 |
|
TABLE ACCESS FULL | TIMES | 365 | 5840 | 18 (0)| 00:00:01 |
A n |* 26 |
| |
TABLE ACCESS FULL | CHANNELS | 2 | 42 | 3 (0)| 00:00:01 |
o s e ------------------------------------------------------------------------------------------------------------------
----------
2 - access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
3 - access("S"."TIME_ID"="T"."TIME_ID")
4 - access("S"."CUST_ID"="C"."CUST_ID")
5 - filter("C"."CUST_STATE_PROVINCE"='CA')
13 - filter("CH"."CHANNEL_DESC"='Catalog' OR "CH"."CHANNEL_DESC"='Internet')
14 - access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
18 - filter("T"."CALENDAR_QUARTER_DESC"='1999-01' OR "T"."CALENDAR_QUARTER_DESC"='1999-02' OR
"T"."CALENDAR_QUARTER_DESC"='2000-03' OR "T"."CALENDAR_QUARTER_DESC"='2000-04')
19 - access("S"."TIME_ID"="T"."TIME_ID")
23 - filter("C"."CUST_STATE_PROVINCE"='CA')
24 - access("S"."CUST_ID"="C"."CUST_ID")
25 - filter("T"."CALENDAR_QUARTER_DESC"='1999-01' OR "T"."CALENDAR_QUARTER_DESC"='1999-02' OR
"T"."CALENDAR_QUARTER_DESC"='2000-03' OR "T"."CALENDAR_QUARTER_DESC"='2000-04')
26 - filter("CH"."CHANNEL_DESC"='Catalog' OR "CH"."CHANNEL_DESC"='Internet')
Note
-----
- star transformation used for this statement
Statistics
----------------------------------------------------------
17362 recursive calls
0 db block gets
36930 consistent gets
0 sorts (disk)
41 rows processed
SQL>
--------------------------------------------------------------
set echo on
n s e
alter system flush shared_pool;
ice
alter system flush buffer_cache;
b l el
set pagesize 200
fe ra
set linesize 250
a n s
set timing on
o n -tr
an
set autotrace on
h s
a deฺ
)
s Gui
ALTER SESSION SET star_transformation_enabled=TEMP_DISABLE;
e
r ฺ
i ent
p ฺ m
SELECT ch.channel_class, gc.cust_city, d t.calendar_quarter_desc,
d S t u
SUM(s.amount_sold)
b
FROM sales s, timesi a@ t h is c, channels ch
sales_amount
t, customers
i a (ja == t.time_id
WHERE s.time_id
u se
AND
AND A
b
s.cust_id
to = ch.channel_id
c.cust_id
n o
i c.cust_state_province = 'CA'
s.channel_id
ntoAND
e A AND ch.channel_desc in ('Internet','Catalog')
4) How would you enhance the previous optimization without changing the SH schema?
a) Let the optimizer decide if it is better to use a temporary table. You can try to set
the STAR_TRANSFORMATION_ENABLED parameter to TRUE.
SQL> @third_run
SQL> set echo on
SQL>
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.10
SQL> alter system flush buffer_cache;
Elapsed: 00:00:00.21
SQL>
SQL> set pagesize 200
SQL> set linesize 250
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> SELECT ch.channel_class, c.cust_city, t.calendar_quarter_desc,
n s e
2 SUM(s.amount_sold) sales_amount
ice
3 FROM sales s, times t, customers c, channels ch
b l el
4 WHERE s.time_id = t.time_id
5 AND s.cust_id = c.cust_id
fe r a
6 AND s.channel_id = ch.channel_id
a n s
7 AND c.cust_state_province = 'CA'
o n -tr
an
8 AND ch.channel_desc in ('Internet','Catalog')
9 AND t.calendar_quarter_desc IN ('1999-01','1999-02','2000-
03','2000-04')
h s
a deฺ
10 GROUP BY ch.channel_class, c.cust_city,
e )
s Gui
t.calendar_quarter_desc; r ฺ
i ent
p ฺ m d
CHANNEL_CLASS
d g
CUST_CITY
S t u CALENDA
SALES_AMOUNT
b
--------------------i a@------------------------------
t h is ------- --------
j a e
ia ( to usSan Francisco
----
Indirect
A b 2000-04
o io
13227.99
n
Indirect Montara 2000-04
nt 1319
e A
J o s …
Indirect San Francisco 1999-01
3058.27
Indirect Pala 1999-01
3263.93
41 rows selected.
Elapsed: 00:00:00.30
Execution Plan
----------------------------------------------------------
Plan hash value: 163104418
------------------------------------------------------------------------------------------------------------------
------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
| Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------
------------------
| 0 | SELECT STATEMENT | | 3 | 219 | 985 (1)| 00:00:12
| | |
| 1 | TEMP TABLE TRANSFORMATION | | | | |
| | |
| 2 | LOAD AS SELECT | SYS_TEMP_0FD9D660F_8947E | | | |
| | |
|* 3 | TABLE ACCESS FULL | CUSTOMERS | 383 | 9958 | 406 (1)| 00:00:05
| | |
a n s
tr
|* 21 | TABLE ACCESS FULL | TIMES | 365 | 5840 | 18 (0)| 00:00:01
|
|* 22 |
| |
BITMAP INDEX RANGE SCAN
n -
| SALES_TIME_BIX
o
| | | |
an
|KEY(SQ)|KEY(SQ)|
| 23 | BITMAP MERGE | | | | |
|
| 24 |
| |
BITMAP KEY ITERATION
h
| s
a deฺ | | | |
|
| 25 |
| |
BUFFER SORT
e )
s Gui
| | | | |
| | |
r ฺ
mi dent
| 26 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_8947E | 1 | 13 | 2 (0)| 00:00:01
|
|* 27 |
| |
p ฺ
g Stu
BITMAP INDEX RANGE SCAN | SALES_CUST_BIX | | | |
|KEY(SQ)|KEY(SQ)|
d
a@ this
|* 28 | TABLE ACCESS FULL | TIMES | 365 | 5840 | 18 (0)| 00:00:01
|
|* 29 |
| |
b i
TABLE ACCESS FULL | CHANNELS | 2 | 42 | 3 (0)| 00:00:01
(ja use
| | |
a
------------------------------------------------------------------------------------------------------------------
b i
------------------
to
io A
Predicate Information (identified by operation id):
t o n
---------------------------------------------------
n 3 - filter("C"."CUST_STATE_PROVINCE"='CA')
eA
5 - access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
Jos
6 - access("S"."TIME_ID"="T"."TIME_ID")
7 - access("S"."CUST_ID"="C0")
16 - filter("CH"."CHANNEL_DESC"='Catalog' OR "CH"."CHANNEL_DESC"='Internet')
17 - access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
21 - filter("T"."CALENDAR_QUARTER_DESC"='1999-01' OR "T"."CALENDAR_QUARTER_DESC"='1999-02' OR
"T"."CALENDAR_QUARTER_DESC"='2000-03' OR "T"."CALENDAR_QUARTER_DESC"='2000-04')
22 - access("S"."TIME_ID"="T"."TIME_ID")
27 - access("S"."CUST_ID"="C0")
28 - filter("T"."CALENDAR_QUARTER_DESC"='1999-01' OR "T"."CALENDAR_QUARTER_DESC"='1999-02' OR
"T"."CALENDAR_QUARTER_DESC"='2000-03' OR "T"."CALENDAR_QUARTER_DESC"='2000-04')
29 - filter("CH"."CHANNEL_DESC"='Catalog' OR "CH"."CHANNEL_DESC"='Internet')
Note
-----
- star transformation used for this statement
Statistics
----------------------------------------------------------
17911 recursive calls
19 db block gets
35577 consistent gets
2157 physical reads
1616 redo size
1896 bytes sent via SQL*Net to client
442 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
SQL>
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
set echo on
SQL> @create_bji.sql
SQL>
SQL> CREATE BITMAP INDEX sales_c_state_bjix ON
sales(customers.cust_state_province) FROM sales, customers WHERE
sales.cust_id=customers.cust_id
2 LOCAL NOLOGGING COMPUTE STATISTICS;
CREATE BITMAP INDEX sales_c_state_bjix ON
sales(customers.cust_state_province) FROM sales, customers WHERE
sales.cust_id=customers.cust_id
SQL>
--------------------------------------------------------------
set echo on
Table altered. p ฺ
g Stu
d
SQL>
b i a@ this
SQL> CREATE (
a ja uINDEX
BITMAP se sales_c_state_bjix ON
b i to
sales(customers.cust_state_province) FROM sales, customers WHERE
o A
sales.cust_id=customers.cust_id
i
nton 2 LOCAL NOLOGGING COMPUTE STATISTICS;
e A Index created.
J o s
SQL>
SQL>
--------------------------------------------------------------
set echo on
SQL> @fourth_run
Session altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> alter system flush shared_pool;
System altered.
System altered.
SQL>
n s e
SQL> set pagesize 200
ice
SQL> set linesize 250
b l el
SQL> set timing on
SQL> set autotrace on
fe r a
SQL>
a n s
-
SQL> SELECT ch.channel_class, c.cust_city, t.calendar_quarter_desc,
n tr
o
an
2 SUM(s.amount_sold) sales_amount
3 FROM sales s, times t, customers c, channels ch
4 WHERE s.time_id = t.time_id
h s
a deฺ
5 AND s.cust_id = c.cust_id
e )
s Gui
r ฺ
mi dent
6 AND s.channel_id = ch.channel_id
7 AND ฺ
c.cust_state_province = 'CA'
p
g Stu
8 AND
d
ch.channel_desc in ('Internet','Catalog')
9 AND
03','2000-04') b i a@ this
t.calendar_quarter_desc IN ('1999-01','1999-02','2000-
i a (ja use
10 GROUP BY ch.channel_class, c.cust_city,
b to
t.calendar_quarter_desc;
A
o n io
CHANNEL_CLASS CUST_CITY CALENDA
t
e An SALES_AMOUNT
Jos
-------------------- ------------------------------ ------- --------
----
Indirect Quartzhill 1999-01
987.3
Indirect Arbuckle 1999-02
241.2
Indirect Pala 2000-03
…
Indirect Montara 1999-02
1618.01
Indirect Quartzhill 1999-02
412.83
41 rows selected.
Elapsed: 00:00:00.23
Execution Plan
----------------------------------------------------------
Plan hash value: 632695221
------------------------------------------------------------------------------------------------------------------
-----------
a n s
tr
|* 15 | TABLE ACCESS FULL | CHANNELS | 2 | 42 | 3 (0)| 00:00:01 |
|
|* 16 |
|
BITMAP INDEX RANGE SCAN
n -
| SALES_CHANNEL_BIX |
o
| | |
an
|KEY(SQ)|KEY(SQ)|
| 17 | BITMAP MERGE | | | | | |
|
| 18 |
|
BITMAP KEY ITERATION
h
| s
a deฺ | | | | |
|
| 19 |
|
BUFFER SORT
e )
s Gui
| | | | | |
| |
r ฺ
mi dent
|* 20 | TABLE ACCESS FULL | TIMES | 365 | 5840 | 18 (0)| 00:00:01 |
|
|* 21 |
|
p ฺ
g Stu
BITMAP INDEX RANGE SCAN | SALES_TIME_BIX | | | |
|KEY(SQ)|KEY(SQ)|
d
a@ this
|* 22 | BITMAP INDEX SINGLE VALUE | SALES_C_STATE_BJIX | | | |
|KEY(SQ)|KEY(SQ)|
b i
------------------------------------------------------------------------------------------------------------------
(ja use
-----------
b i a to
Predicate Information (identified by operation id):
A
---------------------------------------------------
io
t o n2
3
-
-
access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
filter("CH"."CHANNEL_DESC"='Catalog' OR "CH"."CHANNEL_DESC"='Internet')
A n 4
5
-
-
access("S"."TIME_ID"="T"."TIME_ID")
filter("T"."CALENDAR_QUARTER_DESC"='1999-01' OR "T"."CALENDAR_QUARTER_DESC"='1999-02' OR
o s e 6 -
"T"."CALENDAR_QUARTER_DESC"='2000-03' OR "T"."CALENDAR_QUARTER_DESC"='2000-04')
access("S"."CUST_ID"="C"."CUST_ID")
J 7
15
16
-
-
-
filter("C"."CUST_STATE_PROVINCE"='CA')
filter("CH"."CHANNEL_DESC"='Catalog' OR "CH"."CHANNEL_DESC"='Internet')
access("S"."CHANNEL_ID"="CH"."CHANNEL_ID")
20 - filter("T"."CALENDAR_QUARTER_DESC"='1999-01' OR "T"."CALENDAR_QUARTER_DESC"='1999-02' OR
"T"."CALENDAR_QUARTER_DESC"='2000-03' OR "T"."CALENDAR_QUARTER_DESC"='2000-04')
21 - access("S"."TIME_ID"="T"."TIME_ID")
22 - access("S"."SYS_NC00008$"='CA')
Note
-----
- star transformation used for this statement
Statistics
----------------------------------------------------------
18151 recursive calls
0 db block gets
8759 consistent gets
2002 physical reads
0 redo size
1888 bytes sent via SQL*Net to client
442 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
154 sorts (memory)
0 sorts (disk)
SQL>
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
set echo on
b i a@ this
9) Determine how(the
a ja system
u e dynamically determine which SALES partitions to
scould
i to query.
access forbthe previous
o A
t o ni View the OTHER column of PLAN_TABLE for the PARTITION RANGE
a)
An operation.
e
Jos SQL>
SQL>
@dynamic_partition_pruning
Session altered.
SQL>
SQL> explain plan for
2 SELECT ch.channel_class, c.cust_city, t.calendar_quarter_desc,
3 SUM(s.amount_sold) sales_amount
4 FROM sales s, times t, customers c, channels ch
5 WHERE s.time_id = t.time_id
6 AND s.cust_id = c.cust_id
7 AND s.channel_id = ch.channel_id
8 AND c.cust_state_province = 'CA'
Explained.
SQL>
SQL> SELECT other
2 FROM plan_table
3 WHERE operation='PARTITION RANGE';
OTHER
--------------------------------------------------------------------
------------
n s e
SELECT distinct TBL$OR$IDX$PART$NUM("SALES", 0, d#, p#,
i ce
PAP_ALIAS_0."PAP_COL_ALI
b l el
AS_0") FROM (SELECT /*+ SEMIJOIN_DRIVER */ "T"."TIME_ID"
"PAP_COL_ALIAS_0" FROM
fer a
n
"TIMES" "T" WHERE "T"."CALENDAR_QUARTER_DESC"='1999-01' OR
a s
"T"."CALENDAR_QUARTER
o n -tr
an
_DESC"='1999-02' OR "T"."CALENDAR_QUARTER_DESC"='2000-03' OR
"T"."CALENDAR_QUART
h
ER_DESC"='2000-04') PAP_ALIAS_0 ORDER BY 1 s
a deฺ
e )
s Gui
r ฺ
SQL>
p ฺ mi dent
d g Stu
b i a@ this
--------------------------------------------------------------
i a (ja use
b
set echo
A
on
to
n o
i autotrace off
ntoset
e A set timing off
SELECT other
FROM plan_table
WHERE operation='PARTITION RANGE';
SQL> @cleanup_star_schema_lab
SQL> set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> set timing off
SQL> set autotrace off
SQL>
SQL> drop index sales_c_state_bjix;
Index dropped.
SQL>
SQL> alter table customers enable novalidate constraint
n s e
customers_pk;
i ce
b l el
Table altered.
fe r a
SQL>
a n s
SQL> connect / as sysdba
o n -tr
an
Connected.
SQL>
SQL> revoke dba from sh;
h s
a deฺ
e )
s Gui
r ฺ
mi dent
Revoke succeeded.
p
g Stuฺ
SQL> d
@ Database
SQL> exit
b i aOracle t h is 11g Enterprise Edition Release
a
11.1.0.6.0 -(jProduction
Disconnected from
se
i a to
b Partitioning, u
A
With the
andoReal
Oracle Label Security, OLAP, Data Mining
connect / as sysdba
exit;
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
n s e
ce
SQL*Plus: Release 11.1.0.6.0 - Production on Mon Mar 31 19:11:42
2008
el i
a b l
Copyright (c) 1982, 2007, Oracle. All rights reserved.
fe r
a n s
n - tr
Connected to:
o
an
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
s
Production
) h a deฺ
r ฺ
and Real Application Testing options s Gui
With the Partitioning, Oracle Label Security, OLAP, Data Mining
e
p ฺ mi dent
SQL>
d g Stu
a@ this
SQL> connect / as sysdba;
Connected.
b i
SQL>
(ja cascade;
user jfv u
SQL> dropia se
A b to
o
i dropped.
ton
User
A n
o s e SQL>
J SQL> create user jfv identified by jfv default tablespace users
temporary tablespace temp;
User created.
SQL>
SQL> grant connect, resource, dba to jfv;
Grant succeeded.
SQL>
SQL>
SQL> connect jfv/jfv
Connected.
SQL>
SQL> drop table t purge;
drop table t purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> drop table z purge;
drop table z purge
*
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> create table t(c number);
Table created.
SQL>
n s e
SQL> insert into t values (1);
i ce
b l el
1 row created.
fer a
SQL>
a n s
SQL> commit;
n - tr
o
Commit complete.
s an
) h a deฺ
SQL>
e
SQL> insert into t select * fromrฺt;
s Gui
ฺ m i ent
1 row created.
d p
g Stud
SQL> b i a@ this
SQL> /
i a (ja use
A b
created. t
o
o
ni /
2 rows
ntoSQL>
e A
J o s 4 rows created.
SQL> /
8 rows created.
SQL> /
16 rows created.
SQL> /
32 rows created.
SQL> /
64 rows created.
SQL> /
SQL> /
SQL> /
SQL> /
SQL>
SQL> commit;
n s e
i ce
Commit complete.
b l el
SQL>
fer a
SQL> insert into t select * from t;
a n s
n -tr
o
an
2048 rows created.
SQL>
h s
a deฺ
SQL> /
e )
s Gui
r ฺ
4096 rows created.
p ฺ mi dent
d g Stu
SQL> /
b i a@ this
i a (ja use
8192 rows created.
A b to
i o
SQL> /
n
t o
n 16384 rows created.
e A
Jos SQL> /
SQL> /
SQL> /
SQL> /
SQL>
SQL> commit;
Commit complete.
Table created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> begin
2 for i in 1..100 loop
3 insert into z values (i);
4 end loop;
5 commit;
6 end;
7 /
a@ this completed.
PL/SQL procedurebisuccessfully
i a (ja use
SQL>
SQL> A
b to
n i o
ntoSQL>
e A SQL> connect / as sysdba;
J o s Connected.
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> alter system flush buffer_cache;
System altered.
SQL>
SQL> execute dbms_stats.delete_system_stats;
SQL>
SQL> execute DBMS_STATS.SET_SYSTEM_STATS (pname => 'cpuspeednw',
pvalue => 0);
SNAME PNAME
PVAL1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SNAME PNAME
h s
a deฺ
PVAL1
e )
s Gui
i r ฺ n t
------------------------------ ------------------------------ ------
---- m
pฺ MAXTHR de
SYSSTATS_MAIN
d g t u
SYSSTATS_MAIN
i a @ his SSLAVETHR
( j ab se t
13 rows selected.
b ia to u
SQL> A
o n io exit;
SQL>
nt Disconnected from Oracle Database 11g Enterprise Edition Release
e A
J o s 11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl System_Stats]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/System_Stats
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
connect / as sysdba;
n s e
connect jfv/jfv
i ce
b l el
drop table t purge;
fer a
drop table z purge;
a n s
n -tr
o
an
create table t(c number);
/ b i a@ this
/
i a (ja use
/
A b to
/ni
/
o
t
n /o
e A
Jos
/
/
/
/
commit;
/
/
/
/
/
/
/
commit;
execute dbms_stats.gather_table_stats('JFV','T',cascade=>true);
execute dbms_stats.gather_table_stats('JFV','Z',cascade=>true);
n s e
connect / as sysdba;
i ce
b l el
alter system flush shared_pool;
fe r a
alter system flush buffer_cache;
a n s
o n -tr
execute dbms_stats.delete_system_stats;
n
a 'cpuspeednw',
execute DBMS_STATS.SET_SYSTEM_STATS (pname
h a s=>
e ฺ pvalue
=> 0);
s) Gui d
r ฺ
i ente
select sname,pname,pval1 from
p ฺ maux_stats$;
d
d g S t u
exit;
b i a@ this
ja use
2. Frombyouria (terminal
t o session, connect as the JFV user in the SQL*Plus session.
A
ioAfter this, execute the following statement and determine how long it takes to
t o n execute:
A n
o s e select /* Without system stats */ count(*)
from t,z
J where t.c=z.d;
[oracle@edrsr33p1-orcl System_Stats]$ sqlplus jfv/jfv
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> @select_without_sysstats
SQL>
SQL> set timing on
SQL>
COUNT(*)
----------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
524288
Elapsed: 00:00:00.24
SQL>
SQL> set timing off
SQL>
SQL>
--------------------------------------------------------------
set echo on
n s e
ice
set timing on
b l el
select /* Without system stats */ count(*)
fe r a
from t,z
a n s
where t.c=z.d;
o n -tr
set timing off
s an
) h a deฺ
3. Determine the execution plan used to r ฺ e
execute ui statement. In addition,
s theGprevious
determine the optimizer’s cost,ฺm
i
CPU cost,eand ntI/O cost for the previous execution.
What do you observe? dg
p tu d
@use CPU
anot S
is costing. This is because system statistics were
b
a) The optimizer doesi t h
(jathe first
deleted during
i a u e of this lab. The plan chosen by the optimizer might
sstep
notA to
bebthe best one.
o
ni @show_latest_exec_plan
t oSQL>
n SQL> set echo on
e A
Jos
SQL>
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
------------
SQL_ID 6avdu58tamzju, child number 0
-------------------------------------
select /* Without system stats */ count(*) from t,z where t.c=z.d
------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 134 |
| 1 | SORT AGGREGATE | | 1 | 6 | |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
------------
---------------------------------------------------
4 - access("T"."C"="Z"."D")
Note
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
------------
-----
n s e
- cpu costing is off (consider enabling it)
i ce
b l el
25 rows selected.
fer a
a n s
SQL>
n - tr
o
an
SQL> col operations format a20
SQL> col object_name format a11
SQL> col options format a15
h s
a deฺ
SQL> col cost_cpu_io format a30
e )
s Gui
r ฺ
mi dent
SQL>
SQL>
p ฺ
g Stu
d
SQL> select operation operations, object_name, options,
2
b i a@ this
cost||' -- '||cpu_cost||' -- '||io_cost cost_cpu_io
3 from (select * from v$sql_plan where address in (select address
4
i a (ja use from v$sql
5
Ab to where sql_text
o 6io
like '%system stats%' and
n sql_text
nt
e A not like '%connect%'));
SQL>
--------------------------------------------------------------
set echo on
from v$sql
where sql_text like
'%system stats%' and
sql_text not
like '%connect%'));
4. How can you ensure that the optimizer finds a better plan during future executions
of the same statement? Implement your solution.
b) Gather system statistics again. Because you do not have yet a real workload, you n s e
ice
can gather system statistics in NOWORKLOAD mode.
b l el
SQL> connect / as sysdba;
fe r a
Connected.
a n s
SQL> @gather_system_stats
o n -tr
an
SQL> set echo on
SQL>
h s
a deฺ
SQL> execute DBMS_STATS.GATHER_SYSTEM_STATS(gathering_mode =>
'NOWORKLOAD');
e )
s Gui
r ฺ
i ent
ฺ
PL/SQL procedure successfully
p mcompleted.
d
d g S t u
SQL>
b i a@ this from aux_stats$;
SQL> select sname,pname,pval1
SNAME bia
(ja use
PVAL1 A to PNAME
o n io
------------------------------ ------------------------------ ------
nt
e A ----
J o s SYSSTATS_INFO
SYSSTATS_INFO
STATUS
DSTART
SYSSTATS_INFO DSTOP
SYSSTATS_INFO FLAGS
1
SYSSTATS_MAIN CPUSPEEDNW
1893.021
SYSSTATS_MAIN IOSEEKTIM
8.043
SYSSTATS_MAIN IOTFRSPEED
4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SNAME PNAME
PVAL1
------------------------------ ------------------------------ ------
----
SYSSTATS_MAIN MAXTHR
13 rows selected.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
set echo on
n s e
5. Before verifying your solution, you should flush the System Global Area (SGA)
ice
pools, such as the shared pool and the buffer cache. This is done to prevent
b l el
interferences from the previous steps.
fe ra
SQL> @flush_sga
a n s
SQL>
n - tr
o
an
SQL> set echo on
SQL>
SQL> alter system flush shared_pool;
h s
a deฺ
e )
s Gui
r ฺ
mi dent
System altered.
p ฺ
g Stu
SQL>
d
b i a@ this
SQL> alter system flush buffer_cache;
a (ja use
System altered.
i
A b to
ni o
SQL>
ntoSQL>
e A
J o s --------------------------------------------------------------
set echo on
6. Connected as the JFV user again, check your solution against the following
query:
select /* With system stats */ count(*)
from t,z
where t.c=z.d;
What do you observe?
c) The optimizer can make a better decision because it was able to use meaningful
system statistics. You can see that the execution time is now half the value it was
previously, and the execution plan now includes CPU costing information.
2 from t,z
3 where t.c=z.d;
COUNT(*)
----------
524288
Elapsed: 00:00:00.11
SQL>
SQL> set timing off
n s e
SQL>
i ce
SQL> @show_latest_exec_plan
b l el
SQL> set echo on
fer a
SQL>
SQL> select * from table(dbms_xplan.display_cursor);
a n s
o n -tr
an
PLAN_TABLE_OUTPUT
------------
h s
--------------------------------------------------------------------
a deฺ
SQL_ID 2x55txn3742by, child number 0
e )
s Gui
r ฺ
mi dent
-------------------------------------
p ฺ
select /* With system stats */ count(*) from t,z where t.c=z.d
g Stu
d
b i a@ this
Plan hash value: 2407521827
a (ja use
--------------------------------------------------------------------
i
--------
A b to
n i
| Id o | Operation | Name | Rows | Bytes | Cost (%CPU)|
ntoTime |
e A --------------------------------------------------------------------
J o s --------
| 0 | SELECT STATEMENT | | | | 272 (100)|
|
| 1 | SORT AGGREGATE | | 1 | 6 | |
|
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
------------
|* 2 | HASH JOIN | | 524K| 3072K| 272 (3)|
00:00:03 |
| 3 | INDEX FULL SCAN | IZ | 100 | 300 | 1 (0)|
00:00:01 |
| 4 | TABLE ACCESS FULL| T | 524K| 1536K| 267 (2)|
00:00:03 |
--------------------------------------------------------------------
--------
21 rows selected.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
i a (ja use
SQL>
Ab to
o n io
--------------------------------------------------------------
nt
e A
J o s set timing on
--------------------------------------------------------------
set echo on
like '%connect%'));
7. Exit from your SQL*Plus session and clean up your environment for this lab by
executing the systats_cleanup.sh script.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
n s e
With the Partitioning, Oracle Label Security, OLAP, Data Mining
i ce
and Real Application Testing options
b l el
[oracle@edrsr33p1-orcl System_Stats]$ ./sysstats_cleanup.sh
fer a
SQL*Plus: Release 11.1.0.6.0 - Production on Mon Mar 31 19:13:54
a n s
2008
o n -tr
Copyright (c) 1982, 2007, Oracle. All rights
n
a reserved.
h s
a deฺ
e )
s Gui
r ฺ
miEdition t
Connected to:
p
Oracle Database 11g Enterprise ฺ d e nRelease 11.1.0.6.0 -
Production g
dOracle S t u
@ s
thi options
ia Testing
With the Partitioning, Label Security, OLAP, Data Mining
a b
and Real Application
j e
SQL> b ia ( to us
i
SQL> A user jfv cascade;
o drop
to n
A n User dropped.
o s e
J SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl System_Stats]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/System_Stats
export ORACLE_SID=orcl
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
set echo on
this lab by executing the ags_setup.sh script. This script creates a user called
AGS that you use throughout this lab. The script also creates a table called EMP and
an index.
[oracle@edrsr33p1-orcl Automatic_Gather_Stats]$ ./ags_setup.sh
n s e
ce
Copyright (c) 1982, 2007, Oracle. All rights reserved.
el i
a b l
Connected to:
fe r
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
a n s
Production
n - tr
o
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
s an
) h a deฺ
SQL>
SQL> drop user ags cascade;
r ฺ e s Gui
drop user ags cascade
p ฺ mi dent
*
d g Stu
a@doesthinot
ERROR at line 1:
b i
ORA-01918: user 'AGS' s exist
i a (ja use
SQL> Ab to
o
i create user ags identified by ags;
ton
SQL>
A n
o s e User created.
J SQL>
SQL> grant dba to ags;
Grant succeeded.
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> --
SQL> -- Turn off AUTOTASK
SQL> --
SQL>
SQL> alter system set "_enable_automatic_maintenance"=0;
System altered.
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> create table emp
2 (
3 empno number,
4 ename varchar2(20),
n s e
5 phone varchar2(20),
i ce
6 deptno number
b l el
7 );
fer a
Table created.
a n s
n - tr
o
an
SQL>
SQL>
SQL> insert into emp
h s
a deฺ
2 with tdata as
e )
s Gui
r ฺ
mi dent
3 (select rownum empno
4 ฺ
from all_objects
p
g Stu
5
d
where rownum <= 1000)
6
7
select rownum,
b i a@ this
dbms_random.string ('u', 20),
8
i a (ja use
dbms_random.string ('u', 20),
9
Ab case
to
o
10
n
10)io when rownum/100000 <= 0.001 then mod(rownum,
nt
e A 11 else 10
J o s 12
13
end
from tdata a, tdata b
14 where rownum <= 100000;
SQL>
SQL> commit;
Commit complete.
SQL>
SQL> create index emp_i1 on emp(deptno);
Index created.
SQL>
SQL> exec dbms_stats.delete_schema_stats('AGS');
[oracle@edrsr33p1-orcl Automatic_Gather_Stats]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Automatic_Gather_Stats
export ORACLE_SID=orcl
n s e
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
i ce
b l el
export
fer
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/locaa
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
a n s
o n -tr
an
sqlplus / as sysdba @ags_setup.sql
h s
a deฺ
--------------------------------------------------------------
e )
s Gui
set echo on r ฺ
i ent
p ฺ m
drop user ags cascade; g
d S tud
create user ags b i a@ thibys ags;
identified
a
(jags; se
b
grant dba i a
to
to u
o A
ni system flush shared_pool;
toalter
A n
o s e --
J -- Turn off AUTOTASK
--
connect ags/ags
case
when rownum/100000 <= 0.001 then mod(rownum, 10)
else 10
end
from tdata a, tdata b
where rownum <= 100000;
commit;
p ฺ mi dAll e t
nrights
Copyright (c) 1982, 2007,
d g Stu
Oracle. reserved.
b i a@ this
Connected to:
i a (ja 11guEnterprise
se
b
Oracle Database
A to Edition Release 11.1.0.6.0 -
3) Determine the distribution of the deptno values found in the EMP table. What do
you observe?
a) You can see that there are 11 different department values, each repeating 0.01%
of the time except value 10 that repeats 99.9% of the time.
SQL> @show_deptno_distribution
SQL>
SQL> select deptno, count(*) cnt_per_deptno, (count(*)*100)/nr
deptno_percent
2 from emp, (select max(empno) nr
3 from emp)
4 group by deptno, nr
5 order by deptno;
7 10 .01
8 10 .01
9 10 .01
10 99900 99.9
11 rows selected.
SQL>
--------------------------------------------------------------
n s e
i ce
set echo on
b l el
select deptno, count(*) cnt_per_deptno, (count(*)*100)/nr
fe r a
deptno_percent
a n s
from emp, (select max(empno) nr
o n -tr
an
from emp)
group by deptno, nr
order by deptno;
h s
a deฺ
e )
s Gui
r ฺ
ฺ mi doneany
4) Determine if there are histograms available
p nt column of the EMP table. What do
you observe? d g Stu
i @histograms
ano h is defined on any column of the EMP table.
a) Currently, therebare t
i a (ja use
b echo onto
SQL> @check_emp_histogram
A
o
SQL> set
ni select column_name, histogram, num_buckets
t oSQL>
e An 2 from user_tab_columns
SQL>
SQL>
--------------------------------------------------------------
set echo on
--------------------------------------------------------------
set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
7) Execute the following two statements and determine their execution plans:
n s e
select count(*), max(empno) from emp where deptno = 9;
ice
select count(*), max(empno) from emp where deptno = 10;
b l el
What do you observe and why?
f a
er
a) You see that for literal 9, the optimizer decided to use the indexra
s
n for literal
whereas
10, the optimizer decided to do TABLE ACCESS FULL. - t
n optimizer
The
n o
a dynamic sampling was
determined the correct plans in both cases. This is because
sobjects.
used, as there were no statistics gathered on h
) a
both
i d eฺ
SQL> @check_exec_plans
i r ฺ es t Gu
SQL> set echo on
g p ฺm uden
SQL>
d S t
SQL> set linesize 200 @ pagesize
s 1000
SQL>
j a b ia
e thi
ia ( to us
SQL> set autotrace on
SQL>
b
n i o A count(*), max(empno) from emp where deptno = 9;
SQL> select
Execution Plan
----------------------------------------------------------
Plan hash value: 3184478295
--------------------------------------------------------------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT | | 1 | 26 |
2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 26 |
| |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 10 | 260 |
2 (0)| 00:00:01 |
---------------------------------------------------
3 - access("DEPTNO"=9)
Note
-----
- dynamic sampling used for this statement
Statistics
n s e
----------------------------------------------------------
i ce
9 recursive calls
b l el
0 db block gets
64 consistent gets
fer a
1 physical reads
a n s
0 redo size
o n -tr
an
481 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
h
2 SQL*Net roundtrips to/from client s
a deฺ
0 sorts (memory)
e )
s Gui
r ฺ
mi dent
0 sorts (disk)
1 rows processed
p
g Stuฺ
d
SQL>
b i a@max(empno)
SQL> select count(*), t h is from emp where deptno = 10;
i a (ja use
COUNT(*)
A to
b ----------
MAX(EMPNO)
o
oni 99900 100000
----------
nt
eA
Jos Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
--------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
-------
| 0 | SELECT STATEMENT | | 1 | 26 | 265 (1)|
00:00:03 |
| 1 | SORT AGGREGATE | | 1 | 26 | |
|
|* 2 | TABLE ACCESS FULL| EMP | 86262 | 2190K| 265 (1)|
00:00:03 |
--------------------------------------------------------------------
-------
2 - filter("DEPTNO"=10)
Note
-----
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Statistics
----------------------------------------------------------
7 recursive calls
0 db block gets
871 consistent gets
5 physical reads
0 redo size
n s e
482 bytes sent via SQL*Net to client
i ce
420 bytes received via SQL*Net from client
b l el
2 SQL*Net roundtrips to/from client
0 sorts (memory)
fer a
0 sorts (disk)
a n s
1 rows processed
o n -tr
SQL>
s an
SQL> set autotrace off
) h a deฺ
SQL>
r ฺ e s Gui
ฺ mi dent
--------------------------------------------------------------
p
d g Stu
set echo on
b i a@ this
a pagesize
set linesize(j200 se 1000
b i a o u
A ont
o
ni count(*), max(empno) from emp where deptno = 9;
set autotrace
ntoselect
e A
J o s select count(*), max(empno) from emp where deptno = 10;
9) Make sure you disable the mechanism found in the previous step.
SQL> alter session set optimizer_dynamic_sampling=0;
Session altered.
SQL>
COUNT(*) MAX(EMPNO)
---------- ----------
n s e
10 99
i ce
b l el
Execution Plan
fe r a
----------------------------------------------------------
a n s
Plan hash value: 3184478295
o n -tr
an
--------------------------------------------------------------------
s
-------------------
|h
a | eRows
Name id
ฺ | Bytes | Cost
| Id | Operation )
es t Gu
(%CPU)| Time |
i r ฺ
g p ฺm uden
--------------------------------------------------------------------
-------------------
d S t |
| 0 | SELECT STATEMENT
(0)| 00:00:01ia
@ i s | 1 | 26 |
5
( j b e th
|
aAGGREGATE
| 1 | SORT
i a u s | | 1 | 26 |
|
2A
|
o
b TABLE tACCESS
|
o |
5ni (0)| 00:00:01 |
BY INDEX ROWID| EMP | 714 | 18564 |
3 - access("DEPTNO"=9)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
481 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
SQL>
SQL> select count(*), max(empno) from emp where deptno = 10;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
Execution Plan
----------------------------------------------------------
Plan hash value: 3184478295
--------------------------------------------------------------------
n s e
-------------------
i ce
| Id | Operation | Name | Rows | Bytes | Cost
b l el
(%CPU)| Time |
fer
-------------------------------------------------------------------- a
-------------------
a n s
| 0 | SELECT STATEMENT | | -
1 |
n tr 26 |
o
an
5 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 26 |
| |
h s
a deฺ
| 2 | )
s Gui
TABLE ACCESS BY INDEX ROWID| EMP
e
| 714 | 18564 |
r ฺ
mi dent
5 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN
p ฺ
g Stu
| EMP_I1 | 286 | |
1 (0)| 00:00:01 |
d
b
-------------------i a@ this
--------------------------------------------------------------------
n t o
e A
Jos Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
954 consistent gets
190 physical reads
0 redo size
482 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> set autotrace off
SQL>
--------------------------------------------------------------
set autotrace on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
eli
Session altered.
a b l
fer
SQL>
a n s
n -tr
12) Set the following wrong statistic values for your EMP table:
o
- Set its number of rows to 10.
s an
- Set its number of blocks to 5.
) h a deฺ
r ฺ e s Gui
mi dent
SQL> @set_wrong_stats
SQL> set echo on
SQL> p ฺ
g Stu
d
a@ this
SQL> exec
b i
dbms_stats.set_table_stats('AGS','EMP',null,null,null,10,5);
i a (ja successfully
u se
b
PL/SQL procedure
A to completed.
o n io
SQL>
nt
e A --------------------------------------------------------------
J o s
set echo on
exec dbms_stats.set_table_stats('AGS','EMP',null,null,null,10,5);
13) Check that you modified correctly the statistics of the EMP table.
SQL> @check_table_last_analyzed
SQL> set echo on
SQL>
SQL> set linesize 200 pagesize 1000
SQL>
SQL> SELECT
last_analyzed,sample_size,monitoring,num_rows,blocks,table_name
2 FROM user_tables
3 WHERE table_name = 'EMP';
SQL>
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
set echo on
SELECT
last_analyzed,sample_size,monitoring,num_rows,blocks,table_name
FROM user_tables
WHERE table_name = 'EMP';
n s e
14) Perform step 7 again. What do you observe and why?
ice
l el
a) Because there are statistics defined on the EMP table, the optimizer uses them, and
b
fe
not dynamic sampling. However, because the statistics are incorrect, the ra
n s
generated plans are also incorrect, at least for the second statement.
a
o n -tr
an
SQL> @check_exec_plans
SQL> set echo on
s
a deฺ
set linesize 200 pagesize 1000 ) h
SQL>
SQL>
r ฺ e s Gui
mi dent
SQL>
SQL> set autotrace on
p ฺ
g Stufrom emp where deptno = 9;
SQL>
d
SQL>
b i a@ this
select count(*), max(empno)
i a (ja use
COUNT(*) MAX(EMPNO)
b10
----------
A to 99
----------
i o
nton
e A
J o s Execution Plan
----------------------------------------------------------
Plan hash value: 3184478295
--------------------------------------------------------------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT | | 1 | 26 |
2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 26 |
| |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 26 |
2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMP_I1 | 1 | |
1 (0)| 00:00:01 |
--------------------------------------------------------------------
-------------------
3 - access("DEPTNO"=9)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
481 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
n s e
0 sorts (memory)
i ce
0 sorts (disk)
b l el
1 rows processed
fer a
SQL>
a n s
o n -tr
SQL> select count(*), max(empno) from emp where deptno = 10;
COUNT(*) MAX(EMPNO)
s an
---------- ----------
) h a deฺ
99900 100000
r ฺ e s Gui
ฺ m i ent
Execution Plan
d g p t u d
a@ this S
----------------------------------------------------------
Plan hash value:bi3184478295
i a (ja use
b to
--------------------------------------------------------------------
A
o
niId | Operation
-------------------
e A Time |
J o s --------------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT | | 1 | 26 |
2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 26 |
| |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 26 |
2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMP_I1 | 1 | |
1 (0)| 00:00:01 |
--------------------------------------------------------------------
-------------------
3 - access("DEPTNO"=10)
Statistics
----------------------------------------------------------
SQL>
SQL> set autotrace off
SQL>
n s e
--------------------------------------------------------------
i ce
b l el
set echo on
fer a
set linesize 200 pagesize 1000
a n s
o n -tr
a n = 9;
set autotrace on
SQL>
--------------------------------------------------------------
set echo on
SQL>
SQL> @check_index_last_analyzed
SQL> set echo on
SQL>
SQL> set linesize 200 pagesize 1000
n s e
SQL>
ice
SQL> SELECT index_name name,num_rows,
b l el
2
3
last_analyzed,distinct_keys,leaf_blocks,
avg_leaf_blocks_per_key,join_index
fe r a
4 FROM user_indexes
a n s
5 WHERE table_name = 'EMP';
o n -tr
NAME a n DISTINCT_KEYS
NUM_ROWS LAST_ANAL
LEAF_BLOCKS AVG_LEAF_BLOCKS_PER_KEY JOI as
) h i d eฺ ------------- --
------------------------------ ----------
r ฺ s Gu
e---
---------
--------- -----------------------
EMP_I1 ฺ m i e nt 07-APR-08
100000 11
196
d g p
17 NO
t u d
@ s S
SQL>
j a b ia
e thi
SQL> setb a ( onto us
SQL> @check_emp_histogram
iecho
SQL> A
o n io select column_name, histogram, num_buckets
SQL>
nt 2 from user_tab_columns
e A
J o s 3 where table_name='EMP';
SQL>
COUNT(*) MAX(EMPNO)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
---------- ----------
10 99
Execution Plan
----------------------------------------------------------
Plan hash value: 3184478295
--------------------------------------------------------------------
-------------------
n s e
| Id | Operation | Name | Rows | Bytes | Cost
i ce
(%CPU)| Time |
b l el
-------------------
fer a
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 |
a n s
8 |
2 (0)| 00:00:01 |
n -tr
o
an
| 1 | SORT AGGREGATE | | 1 | 8 |
| |
| 2 |
h
TABLE ACCESS BY INDEX ROWID| EMP s
a deฺ
| 18 | 144 |
2 (0)| 00:00:01 |
e )
s Gui
r ฺ
mi dent
|* 3 | INDEX RANGE SCAN | EMP_I1 | 18 | |
1 (0)| 00:00:01 |
p ฺ
g Stu
d
--------------------------------------------------------------------
-------------------
b i a@ this
i a (ja use(identified by operation id):
Predicate Information
b to
---------------------------------------------------
A
i o
nton 3 - access("DEPTNO"=9)
e A
J o s Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
481 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> select count(*), max(empno) from emp where deptno = 10;
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
Execution Plan
----------------------------------------------------------
Plan hash value: 2083865914
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
-------
| 0 | SELECT STATEMENT | | 1 | 8 | 265 (1)|
00:00:03 |
| 1 | SORT AGGREGATE | | 1 | 8 | |
|
n s e
|* 2 | TABLE ACCESS FULL| EMP | 99864 | 780K| 265 (1)|
i ce
00:00:03 |
b l el
--------------------------------------------------------------------
-------
fer a
a n s
Predicate Information (identified by operation id):
o n -tr
an
---------------------------------------------------
2 - filter("DEPTNO"=10)
h s
a deฺ
e )
s Gui
r ฺ
i ent
Statistics
p ฺ m d
d g t u
----------------------------------------------------------
S
0 db b i a@gets
0 recursive
block
calls
t h is
a sereads
805 (jconsistent gets
i a
b 0 redotosize
0 u
physical
i o A
nton 482 bytes sent via SQL*Net to client
J o s 2
0
SQL*Net roundtrips to/from client
sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> set autotrace off
SQL>
18) Ensure you delete all statistics previously generated on your objects.
SQL> @delete_stats
SQL> set echo on
SQL>
SQL> exec dbms_stats.delete_schema_stats('AGS');
SQL>
--------------------------------------------------------------
set echo on
19) Verify that you no longer have statistics gathered on both objects.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL> @check_table_last_analyzed
SQL> set echo on
SQL>
SQL> set linesize 200 pagesize 1000
SQL>
SQL> SELECT
last_analyzed,sample_size,monitoring,num_rows,blocks,table_name
2 FROM user_tables
3 WHERE table_name = 'EMP';
n s e
i ce
LAST_ANAL SAMPLE_SIZE MON NUM_ROWS BLOCKS TABLE_NAME
--------- ----------- --- ---------- ---------- -------------------- b l el
----------
fer a
YES EMP
a n s
n - tr
SQL> o
SQL> @check_index_last_analyzed
s an
SQL> set echo on
) h a deฺ
SQL>
SQL>
r
set linesize 200 pagesize 1000ฺ e s Gui
SQL>
p ฺ mi dent
SQL> g Stu
SELECT index_name name,num_rows,
d
a@ this
2 last_analyzed,distinct_keys,leaf_blocks,
3
b i
avg_leaf_blocks_per_key,join_index
4 (ja use= 'EMP';
FROM user_indexes
i a
5
b
WHERE
A to
table_name
n i o
n t oNAME
LEAF_BLOCKS
NUM_ROWS LAST_ANAL DISTINCT_KEYS
AVG_LEAF_BLOCKS_PER_KEY JOI
e A ------------------------------ ---------- --------- ------------- --
Jos --------- ----------------------- ---
EMP_I1
NO
SQL>
SQL> @check_emp_histogram
SQL> set echo on
SQL>
SQL> select column_name, histogram, num_buckets
2 from user_tab_columns
3 where table_name='EMP';
SQL>
TASK_NAME
----------------------------------------------------------------
gather_stats_prog
auto_space_advisor_prog
n s e
i ce
el
AUTO_SQL_TUNING_PROG
a b l
SQL>
fe r
21) Exit from your SQL*Plus session. a n s
o n -tr
an
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
h s
a deฺ
)
s Gui
With the Partitioning, Oracle Label Security, OLAP, Data Mining
e
r ฺ
mi dent
and Real Application Testing options
p ฺ
[oracle@edrsr33p1-orcl Automatic_Gather_Stats]$
g ofSthe
22) You now want to observe d
the effects tu automatic statistics-gathering feature of
b i
your database. However, a@you dot h is want to wait until the database automatically
not
opens the next
a ja usewindow. So from your terminal session, execute the
(maintenance
i
b script. toThis script forces the execution of the automatic statistics-
A
run_ags.sh
o
t o ni
gathering task.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
SQL> exec dbms_workload_repository.create_snapshot;
SQL>
SQL> variable window varchar2(20);
SQL>
SQL> begin
SQL>
SQL> print window;
WINDOW
--------------------------------
MONDAY_WINDOW
SQL>
SQL> --
n s e
SQL> -- Open the corresponding maintenance window, but with other
i ce
clients disabled
b l el
SQL> --
SQL>
fer a
SQL> alter system set "_enable_automatic_maintenance"=1
a n s
2 /
n -tr
o
System altered.
s an
) h a deฺ
SQL>
r ฺ e s - Gui
mi :window);
nt
SQL> exec dbms_auto_task_admin.disable(
> ฺ
'auto space advisor', null,
p
g S d e
d tu
b i a@ this
PL/SQL procedure successfully completed.
SQL>
i a (ja use
A o
b tuning tadvisor',
SQL> exec dbms_auto_task_admin.disable( -
o
>
n io'sql null, :window);
SQL>
SQL> --
SQL> -- Close the maintenance window when auto optimizer stats
collection is done
SQL> --
SQL>
SQL>
SQL> exec dbms_lock.sleep(120);
SQL>
SQL> exec dbms_scheduler.close_window(:window);
SQL>
SQL>
SQL> alter system set "_enable_automatic_maintenance"=0
2 /
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
System altered.
SQL>
SQL> --
SQL> -- Re-enable the other guys so they look like they are enabled
in EM.
SQL> -- Still they will be disabled because we have set the
underscore.
SQL> --
n s e
SQL>
i ce
SQL> exec dbms_auto_task_admin.enable( -
b l el
> 'auto space advisor', null, :window);
fer a
PL/SQL procedure successfully completed.
a n s
o n -tr
an
SQL>
SQL> exec dbms_auto_task_admin.enable( -
> 'sql tuning advisor', null, :window);
h s
a deฺ
e )
s Gui
r ฺ
i ent
PL/SQL procedure successfully completed.
p ฺ m d
SQL>
d g S t u
SQL> exit;
i @ Database
aOracle h is 11g Enterprise Edition Release
Disconnected from
a b t
11.1.0.6.0 -(jProduction
i a u seOracle Label Security, OLAP, Data Mining
With the
A to Testing options
b Application
Partitioning,
ni o
and Real
nto[oracle@edrsr33p1-orcl Automatic_Gather_Stats]$
e A
J o s --------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Automatic_Gather_Stats
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
set echo on
exec dbms_workload_repository.create_snapshot;
begin
select upper(to_char(sysdate,'fmday'))||'_WINDOW' into :window from
dual;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
end;
/
print window;
--
-- Open the corresponding maintenance window, but with other clients
disabled
--
n s e
alter system set "_enable_automatic_maintenance"=1
i ce
/
b l el
exec dbms_auto_task_admin.disable( -
fer a
'auto space advisor', null, :window);
a n s
o n -tr
an
exec dbms_auto_task_admin.disable( -
'sql tuning advisor', null, :window);
h s
a deฺ
e )
s null, ui true);
r ฺ
i ent
exec dbms_scheduler.open_window(:window, G
p ฺ m d
--
d g S t u
is done b i a@ twindow
-- Close the maintenance
h is when auto optimizer stats collection
--
i a (ja use
A b to
o
ni dbms_lock.sleep(120);
ntoexec
e A
J o s exec dbms_scheduler.close_window(:window);
--
-- Re-enable the other guys so they look like they are enabled in
EM.
-- Still they will be disabled because we have set the underscore.
--
exec dbms_auto_task_admin.enable( -
'auto space advisor', null, :window);
exec dbms_auto_task_admin.enable( -
'sql tuning advisor', null, :window);
exit;
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
n s e
i ce
24) View the statistics of your objects. What do you observe and why?
b l el
f e ra
a) The statistics were automatically gathered by the database during the maintenance
window. You can also see this directly from the Automated Maintenance
t r a ns Tasks
o n -
page in Enterprise Manager. The important thing is that the database
n
automatically gathered the right statistics and histograms. Depending on your
environment, you may see different sample sizes.s a
) h a deฺ
SQL> @check_table_last_analyzed
r ฺ e s Gui
mi1000dent
SQL>
SQL> set linesize 200 pagesize
p
g Stuฺ
SQL> d
SQL> SELECT
b i a@ this
(ja use
last_analyzed,sample_size,monitoring,num_rows,blocks,table_name
i a
2 FROM user_tables
to = 'EMP';
b table_name
A
3 WHERE
o
t ni
oLAST_ANAL SAMPLE_SIZE MON NUM_ROWS BLOCKS TABLE_NAME
n
eA
--------- ----------- --- ---------- ---------- --------------------
Jos
----------
07-APR-08 100000 YES 100000 874 EMP
SQL>
SQL> @check_index_last_analyzed
SQL> set echo on
SQL>
SQL> set linesize 200 pagesize 1000
SQL>
SQL> SELECT index_name name,num_rows,
2 last_analyzed,distinct_keys,leaf_blocks,
3 avg_leaf_blocks_per_key,join_index
4 FROM user_indexes
5 WHERE table_name = 'EMP';
2 from user_tab_columns
3 where table_name='EMP';
n s e
SQL>
ice
25) Perform step 7 again. What do you observe and why? b l el
fe r a
a n s
a) The optimizer can make the right decisions for both statements. This is because of
o n -tr
the statistics that were automatically gathered by the database previously.
SQL> @check_exec_plans
s an
SQL> set echo on
) h a deฺ
s Gui
SQL>
SQL> set linesize 200 pagesize 1000
r ฺ e
SQL>
p ฺ mi dent
SQL> set autotrace on
SQL> d g Stu
i
SQL> select count(*),
b a@max(empno)
t h is from emp where deptno = 9;
COUNT(*)i a (ja use
MAX(EMPNO)
A
---------- to
b ----------
i o
ton
10 99
A n
o s e Execution Plan
J ----------------------------------------------------------
Plan hash value: 3184478295
--------------------------------------------------------------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT | | 1 | 8 |
2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 8 |
| |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 9 | 72 |
2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMP_I1 | 9 | |
1 (0)| 00:00:01 |
--------------------------------------------------------------------
-------------------
3 - access("DEPTNO"=9)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
481 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
n s e
0 sorts (memory)
i ce
0 sorts (disk)
b l el
1 rows processed
fer a
SQL>
a n s
o n -tr
SQL> select count(*), max(empno) from emp where deptno = 10;
COUNT(*) MAX(EMPNO)
s an
---------- ----------
) h a deฺ
99900 100000
r ฺ e s Gui
ฺ m i ent
Execution Plan
d g p t u d
a@ this S
----------------------------------------------------------
Plan hash value:bi2083865914
i a (ja use
b to
--------------------------------------------------------------------
A
o
niId | Operation
-------
e A |
J o s --------------------------------------------------------------------
-------
| 0 | SELECT STATEMENT | | 1 | 8 | 265 (1)|
00:00:03 |
| 1 | SORT AGGREGATE | | 1 | 8 | |
|
|* 2 | TABLE ACCESS FULL| EMP | 99863 | 780K| 265 (1)|
00:00:03 |
--------------------------------------------------------------------
-------
2 - filter("DEPTNO"=10)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> set autotrace off
SQL>
ฺ m
SQL*Plus: Release 11.1.0.6.0
d gp SProduction
-
tud
on Mon Apr 7 16:03:37 2008
i a (ja use
A
Connectedb to: to
n i o
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
t o
An With the Partitioning, Oracle Label Security, OLAP, Data Mining
Production
e
Jos and Real Application Testing options
SQL>
SQL> drop user ags cascade;
User dropped.
SQL>
SQL> alter system set "_enable_automatic_maintenance"=1;
System altered.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Automatic_Gather_Stats]$
--------------------------------------------------------------
cd /home/oracle/solutions/Automatic_Gather_Stats
export ORACLE_SID=orcl
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
--------------------------------------------------------------
n s e
i ce
set echo on
b l el
drop user ags cascade;
fer a
a n s
alter system set "_enable_automatic_maintenance"=1;
n - tr
o
exit;
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
n s e
i ce
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - b l el
Production
fe ra
With the Partitioning, Oracle Label Security, OLAP, Data Mining
a n s
and Real Application Testing options
o n -tr
SQL>
s an
SQL> drop user acs cascade;
) h a deฺ
drop user acs cascade
r ฺ e s Gui
miexistdent
*
ERROR at line 1:
ORA-01918: user 'ACS' does p ฺ
g Stu
not
d
b i a@ this
SQL>
a ja use
(user
i toacs identified
b tablespace
SQL> create by acs default tablespace users
io A
temporary temp;
o n
t User created.
A n
o s e
J SQL>
SQL> grant dba, connect to acs;
Grant succeeded.
SQL>
SQL> connect acs/acs
Connected.
SQL>
SQL> drop table emp purge;
drop table emp purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> create table emp
2 (
3 empno number,
Table created.
SQL>
SQL>
SQL> insert into emp
2 with tdata as
3 (select rownum empno
4 from all_objects
5
6
where rownum <= 1000)
select rownum,
n s e
i ce
el
7 dbms_random.string ('u', 20),
8 dbms_random.string ('u', 20),
a b l
9 case
fer
10
s
when rownum/100000 <= 0.001 then mod(rownum,
a n
-tr
10)
11 else 10
o n
12
13
end
from tdata a, tdata b
s an
14 where rownum <= 100000;
) h a deฺ
r ฺ e s Gui
100000 rows created.
p ฺ mi dent
SQL> d g Stu
SQL> create index a
i @ on
emp_i1
h isemp(deptno);
b t
i a (ja use
Index created.
A b to
o
ni exec dbms_stats.gather_table_stats(null, 'EMP', METHOD_OPT =>
SQL>
ntoSQL>
e A 'FOR COLUMNS DEPTNO SIZE 10', CASCADE => TRUE);
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Adaptive_Cursor_Sharing]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Adaptive_Cursor_Sharing
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
set echo on
n s e
ce
drop user acs cascade;
eli
create user acs identified by acs default tablespace users temporary
a b l
tablespace temp;
fer
a n s
grant dba, connect to acs;
n -tr
o
connect acs/acs
s an
drop table emp purge;
) h a deฺ
r ฺ e s Gui
create table emp
( ฺ m i ent
empno number,
d g p t u d
ename
a@ this
varchar2(20), S
phone b i
varchar2(20),
i a (ja use
deptno number
);
A b to
o
ni into emp
ntoinsert
e A with tdata as
n s e
ce
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
eli
Production
a b l
With the Partitioning, Oracle Label Security, OLAP, Data Mining
fe r
and Real Application Testing options
a n s
SQL> @check_emp_histogram
o n -tr
SQL>
s an
SQL>
a deฺ
select column_name, histogram, num_buckets
) h
2
3
from user_tab_columns
where table_name='EMP';
r ฺ e s Gui
p ฺ miHISTOGRAM
d e nt
COLUMN_NAME
d g S---------------
tu NUM_BUCKETS
i a @ his NONE
------------------------------ -----------
ab se t
EMPNO
ENAME
a ( j u
NONE
PHONE
b i t o NONE
DEPTNO
i o A HEIGHT BALANCED 10
n
toSQL>
A n
o s e
J --------------------------------------------------------------
set echo on
3) Determine the distribution of all the distinct values found in the DEPTNO column of
the EMP table. What do you find?
a) Values distribution is uniform for all of them (0.01%) except for value 10
(99.9%). This is typical of what is called data skew.
SQL> @show_deptno_distribution
SQL> set echo on
SQL>
SQL> select deptno, count(*) cnt_per_deptno, (count(*)*100)/nr
deptno_percent
o n
SQL>
s an
h a deฺ
--------------------------------------------------------------
)
r ฺ e s Gui
set echo on
p ฺ mi dent
g Stu
select deptno, count(*)dcnt_per_deptno, (count(*)*100)/nr
@ s
thi nr
iamax(empno)
deptno_percent
j
from emp, (selecta b
( emp)us e
b afrom
ideptno, tonr
i o A
group by
ton
order by deptno;
A n
o s e 4) Before you study the adaptive cursor sharing feature, disable its functionality by
J setting the OPTIMIZER_FEATURES_ENABLE session parameter back to
10.2.0.1. After this is done, ensure that you execute the following command in
your SQL*Plus session: set lines 200 pages 10000. This is used in the lab
to print execution plans correctly.
SQL> alter session set optimizer_features_enable="10.2.0.1";
Session altered.
3 where deptno = 9;
COUNT(*) MAX(EMPNO)
---------- ----------
10 99
SQL>
SQL> @show_latest_exec_plan
SQL> set echo on
SQL> n s e
i ce
el
SQL> select * from table(dbms_xplan.display_cursor);
a b l
PLAN_TABLE_OUTPUT
fer
n s
--------------------------------------------------------------------
a
o n -tr
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 64ngy4j55d1z5, child number 0
s an
-------------------------------------
) h a deฺ
s Gui
select /*ACS_L9*/ count(*), max(empno) from emp where deptno = 9
r ฺ e
Plan hash value: 3184478295
p ฺ mi dent
d g Stu
--------------------------------------------------------------------
-------------------
b i a@ this
( j
| Id | Operation a | se | Name | Rows | Bytes | Cost
bia to
(%CPU)| Time u
A
--------------------------------------------------------------------
io
t o n
-------------------
A n | 0 | SELECT STATEMENT | | | |
o s e 2 (100)|
|
|
1 | SORT AGGREGATE | | 1 | 16 |
J | |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 12 | 192 |
2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMP_I1 | 12 | |
1 (0)| 00:00:01 |
--------------------------------------------------------------------
-------------------
3 - access("DEPTNO"=9)
20 rows selected.
SQL>
--------------------------------------------------------------
COUNT(*) MAX(EMPNO)
h s
a deฺ
---------- ----------
e )
s Gui
r ฺ
mi dent
99900 100000
p ฺ
g Stu
SQL> d
@ his
SQL> set echo onbia
SQL> @show_latest_exec_plan
j a e t
SQL> (
ia * from s
utable(dbms_xplan.display_cursor);
b t o
oA
SQL> select
n i
ntoPLAN_TABLE_OUTPUT
e A --------------------------------------------------------------------
J o s --------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 3232j5gkp2u5h, child number 0
-------------------------------------
select /*ACS_L10*/ count(*), max(empno) from emp where deptno = 10
--------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
-------
| 0 | SELECT STATEMENT | | | | 240 (100)|
|
| 1 | SORT AGGREGATE | | 1 | 16 | |
|
|* 2 | TABLE ACCESS FULL| EMP | 95000 | 1484K| 240 (1)|
00:00:03 |
2 - filter("DEPTNO"=10)
19 rows selected.
SQL>
--------------------------------------------------------------
n s e
i ce
el
set echo on
a b l
select /*ACS_L10*/ count(*), max(empno)
fe r
from emp
a n s
-tr
where deptno = 10;
o n
n set it to value 9,
7) Define a bind variable called DEPTNO in your SQL*Plus s a session,
and execute the following query, and determine ) itsaexecution
h i d eฺplan:
select /*ACS_1*/ count(*), rmax(empno)
i ฺes nt Gu
from emp
g p ฺm ude
where deptno = :deptno; d S t
What do you notice b
@
iawhy? thi
and
s
( j a e
suses
a) Becauseiathe optimizer u bind peeking the first time you execute a statement
to and because
bbind variable,
i A
oexecution plan with index access isforused.
with a this first execution, value 9 is used, the
to n
e An SQL> variable deptno number;
Jos SQL> exec :deptno := 9
SQL> @select_deptno_bind
SQL> set echo on
SQL>
SQL> select /*ACS_1*/ count(*), max(empno)
2 from emp
3 where deptno = :deptno;
COUNT(*) MAX(EMPNO)
---------- ----------
10 99
SQL>
SQL> @show_latest_exec_plan
SQL> set echo on
SQL>
SQL> select * from table(dbms_xplan.display_cursor);
--------------------------------------------------------------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
n s e
i ce
el
(%CPU)| Time |
--------------------------------------------------------------------
a b l
-------------------
fer
| 0 | SELECT STATEMENT | | |
a n s
|
2 (100)|
|
|
1 | SORT AGGREGATE | | n -
1 |tr 16 |
o
|
| 2 |
|
TABLE ACCESS BY INDEX ROWID| EMP
s|an 12 | 192 |
2 (0)| 00:00:01 |
) h a deฺ
|* 3 | INDEX RANGE SCAN
r ฺ e s Gui
| EMP_I1 | 12 | |
1 (0)| 00:00:01 |
p ฺ mi dent
--------------------------------------------------------------------
------------------- d g Stu
b i a@(identified
t h is by operation id):
i a (ja use
Predicate Information
---------------------------------------------------
A b to
i o
ton
3 - access("DEPTNO"=:DEPTNO)
A n
o s e 20 rows selected.
J
SQL>
--------------------------------------------------------------
set echo on
--------------------------------------------------------------
set echo on
n s e
CHILD_NUMBER EXECUTIONS BUFFER_GETS
ice
------------ ---------- -----------
0 1 3 b l el
fe r a
SQL>
a n s
--------------------------------------------------------------o n -tr
s an
set echo on
) h a deฺ
e
select child_number, executions, ฺbuffer_gets
r s Gui
from v$sql
p ฺ mi dent
where sql_text like 'select
d g Stu /*ACS_1%';
b i a@ this
a 8 again,
9) Perform steps 7(jand s ebut this time using 10 as the bind value for DEPTNO.
What do b i a
you observe u
toand why?
o A
t o ni The execution plan is identical. The index path is used although value 10 is not
a)
e An selective. This is because bind peeking only operates the first time you execute
Jos
your statement. Looking at V$SQL, you can clearly see that there is still only one
child cursor associated with your statement. However, this time, the number of
buffer gets was raised significantly due to the full table scan.
SQL> exec :deptno := 10
SQL> @select_deptno_bind
SQL> set echo on
SQL>
SQL> select /*ACS_1*/ count(*), max(empno)
2 from emp
3 where deptno = :deptno;
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
SQL>
SQL> @show_latest_exec_plan
PLAN_TABLE_OUTPUT
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 272gr4hapc9w1, child number 0
-------------------------------------
select /*ACS_1*/ count(*), max(empno) from emp where deptno =
:deptno
o
| 0 | SELECT STATEMENT
2 (100)| |
| |
s an | |
| 1 | SORT AGGREGATE |
) h a deฺ
| 1 | 16 |
| |
r ฺ e s Gui
|
2
2 |
(0)| 00:00:01 | p ฺ mi dent
TABLE ACCESS BY INDEX ROWID| EMP | 12 | 192 |
|* 3 | d
INDEX RANGE SCANg Stu | EMP_I1 | 12 | |
1 (0)| 00:00:01 |
b i a@ this
i a (ja use
--------------------------------------------------------------------
-------------------
A b to
o n io
Predicate Information (identified by operation id):
nt ---------------------------------------------------
e A
J o s 3 - access("DEPTNO"=:DEPTNO)
20 rows selected.
SQL>
SQL> @show_latest_exec_stats
SQL> set echo on
SQL>
SQL> select child_number, executions, buffer_gets
2 from v$sql
3 where sql_text like 'select /*ACS_1%';
SQL>
10) Before the next step, flush your shared pool to make sure you wipe out all cursor’s
information.
System altered.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
COUNT(*) MAX(EMPNO) h s
a deฺ
---------- ----------
e )
s Gui
r ฺ
99900 100000
p ฺ mi dent
SQL> d g Stu
onbi
a@ this
SQL> @show_latest_exec_plan
SQL> set echo a
SQL>
i a (j u se
A b * from
SQL> select to table(dbms_xplan.display_cursor);
ni o
ntoPLAN_TABLE_OUTPUT
e A --------------------------------------------------------------------
J o s --------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 272gr4hapc9w1, child number 0
-------------------------------------
select /*ACS_1*/ count(*), max(empno) from emp where deptno =
:deptno
--------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
-------
| 0 | SELECT STATEMENT | | | | 240 (100)|
|
| 1 | SORT AGGREGATE | | 1 | 16 | |
|
|* 2 | TABLE ACCESS FULL| EMP | 95000 | 1484K| 240 (1)|
00:00:03 |
2 - filter("DEPTNO"=:DEPTNO)
19 rows selected.
SQL>
SQL> @show_latest_exec_stats
SQL>
SQL>
set echo on
n s e
ice
el
SQL> select child_number, executions, buffer_gets
2 from v$sql
a b l
3 where sql_text like 'select /*ACS_1%';
fe r
a n s
-tr
CHILD_NUMBER EXECUTIONS BUFFER_GETS
------------ ---------- -----------
o n
0 1 872
s an
SQL>
) h a deฺ
esyour bind
12) Perform step 9 again, but this time usei9rฺas G ui What do you observe and
why? p ฺ m dent value.
d g Stu
a) Although value 9 is
i a @ his a full table scan is still used. This is because
very selective,
the second time
j b
a you execute
e t your statement, bind peeking is not done. So you
(
iato use tthe
continue s
u child cursor.
same
b
A :deptno := 9 o
n i
SQL>o exec
to
e An PL/SQL procedure successfully completed.
Jos SQL> @select_deptno_bind
SQL> set echo on
SQL>
SQL> select /*ACS_1*/ count(*), max(empno)
2 from emp
3 where deptno = :deptno;
COUNT(*) MAX(EMPNO)
---------- ----------
10 99
SQL>
SQL> @show_latest_exec_plan
SQL> set echo on
SQL>
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
-------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
n s e
ice
el
-------
| 0 | SELECT STATEMENT | | | | 240 (100)|
a b l
|
fe r
| 1 | SORT AGGREGATE | | 1 | 16 | |
a n s
|
|* 2 | TABLE ACCESS FULL| EMP | 95000 | 1484K| n -240 (1)| tr
o
00:00:03 |
s an
--------------------------------------------------------------------
-------
) h a deฺ
r ฺ e s Gui
ฺ m i eoperation
Predicate Information (identified by
n t id):
gp Stud
---------------------------------------------------
d
i a@ this
2 - filter("DEPTNO"=:DEPTNO)
b
i a (ja use
to
19 rows bselected.
A
ni o
ntoSQL>
e A SQL> @show_latest_exec_stats
J o s SQL>
SQL>
set echo on
SQL>
13) Before the next step, reset your session to use adaptive cursor sharing, and ensure that
you flush your shared pool again.
SQL> alter session set optimizer_features_enable="11.1.0.6";
Session altered.
SQL>
a) Because this is the first time you execute the statement, bind peeking is used, and
because value 9 is very selective, the index path is used. Only one child cursor is
used to handle this statement.
SQL> exec :deptno := 9
SQL> @select_deptno_bind
n s e
SQL> set echo on
ice
SQL>
b l el
SQL> select /*ACS_1*/ count(*), max(empno)
fe ra
2
3
from emp
where deptno = :deptno;
a n s
o n -tr
an
COUNT(*) MAX(EMPNO)
---------- ----------
10 99
h s
a deฺ
e )
s Gui
SQL> r ฺ
i ent
SQL> @show_latest_exec_plan ฺm
SQL> set echo on d p
g Stud
SQL>
i @ his
atable(dbms_xplan.display_cursor);
a
SQL> select * from
j b e t
(
ia to u s
b
oA
PLAN_TABLE_OUTPUT
i
--------------------------------------------------------------------
n
nto--------------------------------------------------------------------
e A ----------------------------------------------------------------
--------------------------------------------------------------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT | | | |
2 (100)| |
| 1 | SORT AGGREGATE | | 1 | 16 |
| |
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 16 |
2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | EMP_I1 | 1 | |
1 (0)| 00:00:01 |
3 - access("DEPTNO"=:DEPTNO)
20 rows selected.
SQL>
SQL> @show_latest_exec_stats
SQL>
SQL>
set echo on
n s e
i ce
el
SQL> select child_number, executions, buffer_gets
2 from v$sql
a b l
3 where sql_text like 'select /*ACS_1%';
fe r
a n s
-tr
CHILD_NUMBER EXECUTIONS BUFFER_GETS
------------ ---------- -----------
o n
0 1 54
s an
SQL>
) h a deฺ
r ฺ e s 10 G ui bind value. What do you
observe and why? p ฺ mi dent
15) Perform step 14 again, but this time using value as your
e An
Jos
SQL> @select_deptno_bind
SQL> set echo on
SQL>
SQL> select /*ACS_1*/ count(*), max(empno)
2 from emp
3 where deptno = :deptno;
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
SQL>
SQL> @show_latest_exec_plan
SQL> set echo on
SQL>
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
--------------------------------------------------------------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
--------------------------------------------------------------------
-------------------
| 0 | SELECT STATEMENT
2 (100)| |
| | | |
n s e
ice
el
| 1 | SORT AGGREGATE | | 1 | 16 |
| |
a b l
| 2 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 16 |
fe r
2 (0)| 00:00:01 |
a n s
|* 3 |
1
INDEX RANGE SCAN
(0)| 00:00:01 |
| EMP_I1 |
n
1 |
-
|
tr
o
-------------------
s an
--------------------------------------------------------------------
) h a deฺ
Predicate Information (identified by
r ฺ e s Gui id):
operation
p ฺ mi dent
---------------------------------------------------
d g Stu
3 - access("DEPTNO"=:DEPTNO)
b i a@ this
i a (ja use
20 rows selected.
A b to
o
ni @show_latest_exec_stats
SQL>
ntoSQL>
e A SQL> set echo on
J o s SQL>
SQL> select child_number, executions, buffer_gets
2 from v$sql
3 where sql_text like 'select /*ACS_1%';
SQL>
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
SQL>
SQL> @show_latest_exec_plan
SQL> set echo on
SQL>
n s e
i ce
el
SQL> select * from table(dbms_xplan.display_cursor);
a b l
PLAN_TABLE_OUTPUT
fer
a n s
--------------------------------------------------------------------
-tr
--------------------------------------------------------------------
n
----------------------------------------------------------------
o
SQL_ID 272gr4hapc9w1, child number 1
-------------------------------------
s an
h a deฺ
select /*ACS_1*/ count(*), max(empno) from emp where deptno =
)
:deptno
r ฺ e s Gui
p
Plan hash value: 2083865914 ฺ mi dent
d g Stu
i a@ this
--------------------------------------------------------------------
b
-------
i a (ja use | Name | Rows | Bytes | Cost (%CPU)|
| Id | Operation
Time
A b| to
ni o
--------------------------------------------------------------------
nto-------
e A | 0 | SELECT STATEMENT | | | | 240 (100)|
J o s |
| 1 | SORT AGGREGATE | | 1 | 16 | |
|
|* 2 | TABLE ACCESS FULL| EMP | 95000 | 1484K| 240 (1)|
00:00:03 |
--------------------------------------------------------------------
-------
2 - filter("DEPTNO"=:DEPTNO)
19 rows selected.
SQL>
SQL> @show_latest_exec_stats
SQL> set echo on
SQL>
SQL> select child_number, executions, buffer_gets
0 2 1008
1 1 821
SQL>
17) Exit your SQL*Plus session, and execute the acs_cleanup.sh script to clean up
your environment.
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
n s e
i ce
el
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
a b l
and Real Application Testing options
fe r
[oracle@edrsr33p1-orcl Adaptive_Cursor_Sharing]$ ./acs_cleanup.sh
a n s
n -tr
SQL*Plus: Release 11.1.0.6.0 - Production on Fri Mar 28 16:59:18
o
an
2008
System altered.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Adaptive_Cursor_Sharing]$
n s e
SQL*Plus: Release 11.1.0.6.0 - Production on Mon Mar 31 14:10:59
i ce
2008
b l el
Copyright (c) 1982, 2007, Oracle. All rights reserved.
fe ra
a n s
Connected to: o n -tr
an
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
s
Production
) h a deฺ
r ฺ e s Gui
With the Partitioning, Oracle Label Security, OLAP, Data Mining
mi dent
and Real Application Testing options
SQL> p ฺ
g Stu
d
a@ this
SQL> drop user cs cascade;
b i
User dropped.
i a (ja use
SQL> A
b to
o
ni createtablespace
n t oSQL>
temporary
user cs identified by cs default tablespace users
temp;
e A
Jos User created.
SQL>
SQL> grant dba, connect to cs;
Grant succeeded.
SQL>
SQL> connect cs/cs
Connected.
SQL>
SQL> drop table emp purge;
drop table emp purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> create table emp
Table created.
SQL>
SQL>
SQL> insert into emp
2 with tdata as
3 (select rownum empno
4 from all_objects
5 where rownum <= 1000)
n s e
6 select rownum,
i ce
7 dbms_random.string ('u', 20),
b l el
8
9
dbms_random.string ('u', 20),
case
fer a
10 n s
when rownum/100000 <= 0.001 then mod(rownum,
a
10)
o n -tr
an
11 else 10
12 end
13 from tdata a, tdata b
h s
a deฺ
14 where rownum <= 100000;
e )
s Gui
r ฺ
100000 rows created.
p ฺ mi dent
d g Stu
SQL>
i @ on
aemp_i1 h isemp(deptno);
SQL> create indexb t
i a (ja use
b
Index created.
A to
n i o
ntoSQL>
e A SQL> execute dbms_stats.gather_table_stats(null, 'EMP', cascade =>
J o s true);
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> connect / as sysdba
Connected.
SQL>
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup;
ORACLE instance started.
Database opened.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Cursor_Sharing]$
--------------------------------------------------------------
n s e
i ce
#!/bin/bash
b l el
cd /home/oracle/solutions/Cursor_Sharing
fer a
a n s
export ORACLE_SID=orcl
o n -tr
an
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
s
) h a deฺ
export
r ฺ e s Gui
mi dent
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
ฺ
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
p
sqlplus / as sysdba @ dg Stu
b i a t h is
@cs_setup.sql
i a (ja use
--------------------------------------------------------------
A b on to
o
ni user cs cascade;
set echo
ntodrop
e A
J o s create user cs identified by cs default tablespace users temporary
tablespace temp;
connect cs/cs
case
when rownum/100000 <= 0.001 then mod(rownum, 10)
else 10
end
from tdata a, tdata b
where rownum <= 100000;
n i oA
[oracle@edrsr33p1-orcl Cursor_Sharing]$ sqlplus cs/cs
t o
e An SQL*Plus: Release 11.1.0.6.0 - Production on Mon Mar 31 14:11:38
Jos
2008
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
3) Check the existence of histograms on the columns of the EMP table, and then
determine the data distribution in the DEPTNO column of the EMP table. What do you
observe?
b i2 t o .01
i o A 3 10 .01
t o n 10 .01
A n 5
4 10
10
.01
.01
o s e 6 10 .01
J 7 10 .01
8 10 .01
9 10 .01
10 99900 99.9
11 rows selected.
SQL>
--------------------------------------------------------------
set echo on
--------------------------------------------------------------
set echo on
order by deptno;
4) Before you continue, ensure that you flush your shared pool.
SQL> alter system flush shared_pool;
System altered.
SQL>
n s e
ice
5) How would you force your SQL*Plus session to automatically replace statement b l el
ra
literals with bind variables to make sure the same cursor is used independently of the
fe
literal values?
a n s
SQL> alter session set cursor_sharing = force; o n -tr
s an
Session altered.
) h a deฺ
r ฺ e s Gui
mi dent
SQL>
p ฺ
g execute
6) From the same SQL*Plus d
session, S tuthe following two queries, and then
determine how many b i a@ arethgenerated
cursors is to handle these two statements, and what
(
execution plans j a used.seWhat do you observe
were and why?
b ia count(*),
t o u
i o
select A
select /*CS*/
/*CS*/ count(*),
max(empno)
max(empno)
from
from
emp where deptno = 9;
emp where deptno = 10;
t o n
e An a) Because of the previous step, literal values are replaced with bind variables. The
Jos
FORCE option forces the system to share only one child cursor in this case and
use the exact same execution plan (index range scan).
SQL> @select_deptno_literal_9
SQL> set echo on
SQL>
SQL> select /*CS*/ count(*), max(empno) from emp where deptno = 9;
COUNT(*) MAX(EMPNO)
---------- ----------
10 99
SQL>
SQL> @select_deptno_literal_10
SQL> set echo on
SQL>
SQL> select /*CS*/ count(*), max(empno) from emp where deptno = 10;
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
SQL>
SQL> select sql_text,hash_value
2 from v$sql
3 where sql_text like '%select /*CS%';
SQL_TEXT
HASH_VALUE
--------------------------------------------------------------------
-- ----------
select /*CS*/ count(*), max(empno) from emp where deptno =
n s e
:"SYS_B_0" 3434097775
i ce
b l el
SQL> @show_latest_exec_plans
SQL> set echo on
fer a
SQL>
a n s
SQL> col object_name format a5
n -tr
o
an
SQL> col operation format a16
SQL> col options format a15
SQL>
h s
a deฺ
)
s Gui
SQL> select address,hash_value,child_number,
e
r ฺ
mi dent
operation,options,object_name
2 from v$sql_plan
p ฺ
g Stu
d
3 where (address,hash_value) in
4
5 from v$sql b i a@ this
(select address,hash_value
6 (ja use
where sql_text like '%select /*CS%');
i a
A b to
o n io
ADDRESS
OBJEC
HASH_VALUE CHILD_NUMBER OPERATION OPTIONS
nt
e A -------- ---------- ------------ ---------------- --------------- --
J o s ---
4C9C53D4 3434097775 0 SELECT STATEMENT
4C9C53D4 3434097775 0 SORT AGGREGATE
4C9C53D4 3434097775 0 TABLE ACCESS BY INDEX ROWID
EMP
4C9C53D4 3434097775 0 INDEX RANGE SCAN
EMP_I
1
SQL>
--------------------------------------------------------------
set echo on
--------------------------------------------------------------
set echo on
--------------------------------------------------------------
set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
select sql_text,hash_value
from v$sql
where sql_text like '%select /*CS%';
--------------------------------------------------------------
set echo on
n s e
i ce
col object_name format a5
b l el
col operation format a16
col options format a15
fe r a
a n s
select address,hash_value,child_number,
o n -tr
an
operation,options,object_name
from v$sql_plan
where (address,hash_value) in
h s
a deฺ
(select address,hash_value
e )
s Gui
r ฺ
mi dent
from v$sql
p
g Stuฺ
where sql_text like '%select /*CS%');
d
b i
7) Ensure that you create aa @ t h ishistogram on the DEPTNO column of the EMP
10 buckets
table.
i a (ja use
A to
b dbms_stats.gather_table_stats(null,
i o
SQL> exec
n
'EMP', METHOD_OPT =>
nto
'FOR COLUMNS DEPTNO SIZE 10', CASCADE => TRUE);
e A
Jos
PL/SQL procedure successfully completed.
SQL> @check_emp_histogram
SQL> set echo on
SQL>
SQL> select column_name, histogram, num_buckets
2 from user_tab_columns
3 where table_name='EMP';
SQL>
--------------------------------------------------------------
set echo on
8) Before you continue, ensure that you flush your shared pool.
SQL> alter system flush shared_pool;
System altered.
SQL>
e A SQL>
J o s SQL> select /*CS*/ count(*), max(empno) from emp where deptno = 10;
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
SQL>
SQL> @show_latest_cursors
SQL> set echo on
SQL>
SQL> col sql_text format a70
SQL>
SQL> select sql_text,hash_value
2 from v$sql
3 where sql_text like '%select /*CS%';
SQL_TEXT
HASH_VALUE
--------------------------------------------------------------------
-- ----------
SQL>
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
set echo on
--------------------------------------------------------------
set echo on
Session altered.
SQL> @select_deptno_literal_9
SQL> set echo on
SQL>
SQL> select /*CS*/ count(*), max(empno) from emp where deptno = 9;
COUNT(*) MAX(EMPNO)
---------- ----------
10 99
COUNT(*) MAX(EMPNO)
---------- ----------
99900 100000
SQL>
SQL> @show_latest_cursors
SQL> set echo on
SQL>
SQL> col sql_text format a70
SQL>
n s e
SQL> select sql_text,hash_value
i ce
2 from v$sql
b l el
3 where sql_text like '%select /*CS%';
fer a
SQL_TEXT
a n s
HASH_VALUE
n -tr
o
an
--------------------------------------------------------------------
-- ----------
h s
a deฺ
select /*CS*/ count(*), max(empno) from emp where deptno =
:"SYS_B_0" 3434097775
e )
s Gui
r ฺ
mi dent
select /*CS*/ count(*), max(empno) from emp where deptno =
:"SYS_B_0" 3434097775
p ฺ
g Stu
d
@ his
SQL> @show_latest_exec_plans
SQL> set echo onbia t
SQL> ( j a s e
SQL> colb a to u format a5
iobject_name
i A operation format a16
o col
SQL> col
n
toSQL> options format a15
SQL>
A n
o s e SQL> select address,hash_value,child_number,
J operation,options,object_name
2 from v$sql_plan
3 where (address,hash_value) in
4 (select address,hash_value
5 from v$sql
6 where sql_text like '%select /*CS%');
7 rows selected.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
--------------------------------------------------------------
set echo on
--------------------------------------------------------------
n s e
ice
set echo on
b l el
select /*CS*/ count(*), max(empno) from emp where deptno = 10;
fe r a
a n s
o n -tr
--------------------------------------------------------------
set echo on
s an
) h a deฺ
col sql_text format a70
r ฺ e s Gui
select sql_text,hash_value ฺmi e nt
from v$sql p
dg /*CS%'; tu d
where sql_text like @
a '%select
is S
b i t h
i a (ja use
--------------------------------------------------------------
A b on to
o
ni object_name format a5
set echo
ntocol
e A col operation format a16
12) Exit your SQL*Plus session and execute the cs_cleanup.sh script to clean up
your environment for this lab.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Cursor_Sharing]$
[oracle@edrsr33p1-orcl Cursor_Sharing]$ ./cs_cleanup.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
SQL> drop user cs cascade;
User dropped.
n s e
i ce
SQL>
b l el
SQL> alter system flush shared_pool;
fer a
System altered.
a n s
o n -tr
an
SQL>
SQL> exit;
h s
a deฺ
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
e )
s Gui
r ฺ
mi dent
With the Partitioning, Oracle Label Security, OLAP, Data Mining
p ฺ
and Real Application Testing options
g Stu
d
[oracle@edrsr33p1-orcl Cursor_Sharing]$
b i a@ this
--------------------------------------------------------------
i a (ja use
b
#!/bin/bash
A to
o
cdi /home/oracle/solutions/Cursor_Sharing
nton
e A export ORACLE_SID=orcl
J o s
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
sqlplus / as sysdba @cs_cleanup.sql
--------------------------------------------------------------
set echo on
drop user cs cascade;
alter system flush shared_pool;
exit;
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
1) From your terminal session, execute the iot_setup.sh script. This script creates
an index-organized table.
[oracle@edrsr33p1-orcl Hints]$ ./iot_setup.sh
J o s SQL>
SQL> grant connect, resource, dba to iot;
Grant succeeded.
SQL>
SQL> connect iot/iot
Connected.
SQL>
SQL> drop table iottab purge;
drop table iottab purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> CREATE TABLE IOTTAB (
2 OBJECT_ID NUMBER(14, 0) NOT NULL ENABLE
3 , OBJECT_ID_ATT NUMBER(14, 0) NOT NULL ENABLE
Table created.
SQL>
n s e
SQL> CREATE INDEX OBJECT_ID_ATT_INDX ON IOTTAB (OBJECT_ID_ATT);
i ce
b l el
Index created.
fer a
SQL>
a n s
SQL> -- load data
n -tr
o
an
SQL>
SQL> begin
2 for i in 400001..500000 loop
h s
a deฺ
3 )
s Gui
insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
e
r ฺ
mi dent
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
|i);
p ฺ
g Stu
4 end loop;
d
5 commit;
6 end; b i a@ this
7 /
i a (ja use
A b to
o n io
PL/SQL procedure successfully completed.
nt SQL>
e A
J o s SQL>
SQL> begin
2 for i in 100001..200000 loop
3 insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
|i);
4 end loop;
5 commit;
6 end;
7 /
SQL>
SQL>
SQL> begin
2 for i in 300001..400000 loop
3 insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
|i);
4 end loop;
SQL>
SQL>
SQL> begin
2 for i in 500001..600000 loop
3 insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
|i);
4 end loop;
5 commit;
6 end;
n s e
7 /
i ce
b l el
PL/SQL procedure successfully completed.
fer a
SQL>
a n s
SQL>
n -tr
o
an
SQL> begin
2 for i in 1..100000 loop
3
h s
a deฺ
insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
)
s Gui
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
e
r ฺ
mi dent
|i);
4 end loop;
p ฺ
g Stu
5 commit;
d
6 end;
7 / b i a@ this
i a (ja successfully
u se
b
PL/SQL procedure
A to completed.
o n io
SQL>
Ant SQL>
e
Jos
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> alter system flush buffer_cache;
System altered.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Hints]$
--------------------------------------------------------------
#!/bin/bash
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
set echo on
n s e
i ce
drop user iot cascade;
b l el
fer
create user iot identified by iot default tablespace users temporary a
tablespace temp;
a n s
n -tr
o
an
grant connect, resource, dba to iot;
connect iot/iot
h s
a deฺ
e )
s Gui
drop table iottab purge; r ฺ
i ent
p ฺ m d
CREATE TABLE IOTTAB (
d g S t u
OBJECT_ID
, OBJECT_ID_ATTbia
@ his0)
NUMBER(14, NOT NULL ENABLE
t
NUMBER(14, 0) NOT NULL ENABLE
i a (ja NUMBER(14,
, OBJECT_ID_CAT
u seNOT NULL0) NOT NULL ENABLE
, BEGIN
A b toDATE NOT NULL ENABLE
DATE
n o
,i STATUS
, END ENABLE
J o s , CONSTRAINT IOTTAB_PK
PRIMARY KEY (OBJECT_ID
, OBJECT_ID_ATT
, OBJECT_ID_CAT
, BEGIN
, END) ENABLE )
ORGANIZATION INDEX PCTTHRESHOLD 50 ;
-- load data
begin
for i in 400001..500000 loop
insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
|i);
end loop;
commit;
end;
/
begin
for i in 100001..200000 loop
insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
|i);
end loop;
commit;
end;
/
begin
for i in 300001..400000 loop
insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
n s e
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
i ce
|i);
b l el
end loop;
commit;
fer a
end;
a n s
/
o n -tr
s an
begin
) h a deฺ
for i in 500001..600000 loop
r ฺ e s Gui
ฺ m i ent
insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
|i);
d g p t u d
end loop;
a@ this S
commit; b i
end;
i a (ja use
/
A b to
ni o
ntobegin
e A
J o s for i in 1..100000 loop
insert into iottab values(i,mod(i,428),mod(i,20),sysdate-
mod(i,100),sysdate+mod(i,100),mod(i,3),'aaaaaaaaaaaaaaaaaaaaaaaaaa'|
|i);
end loop;
commit;
end;
/
exit;
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
n s e
ce
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
el i
a b l
SQL> @set_session
fe r
a n s
Session altered.
o n -tr
SQL>
s an
) h a deฺ
r ฺ e s Gui
--------------------------------------------------------------
ฺ mi dent
ALTER SESSION SET OPTIMIZER_INDEX_CACHING=2;
p
d g Stu
a@ th1000
set timing on
set linesize 200 ipagesize
b is
i a (ja use
A
3) From your tosession, execute the following query and note down the time it
b SQL*Plus
n o
i to execute:
takes
t o
e An SELECT comm.
Jos
FROM iottab
WHERE object_id = 1
AND object_id_cat = 0
AND object_id_att = 426 ;
SQL> @select_iot
SQL>
SQL> SELECT comm
2 FROM iottab
3 WHERE object_id = 1
4 AND object_id_cat = 0
5 AND object_id_att = 426 ;
no rows selected
Elapsed: 00:00:00.07
SQL>
--------------------------------------------------------------
set echo on
4) Use the DBMS_XPLAN package to display the execution plan associated with the
statement you executed in the previous step. What do you observe?
a) It is strange to see that the optimizer chooses a plan that accesses the secondary
index while the query references all columns of the primary key.
SQL> @show_latest_exec_plan
SQL> set echo on
n s e
SQL>
i ce
SQL> select * from
b l el
table(dbms_xplan.display_cursor(null,null,'TYPICAL'));
fe r a
PLAN_TABLE_OUTPUT
a n s
o n -tr
--------------------------------------------------------------------
an
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 6u4tsfpprgvzn, child number 0
h s
a deฺ
-------------------------------------
e )
s Gui
r ฺ
mi dent
SELECT comm FROM iottab WHERE object_id = 1 AND object_id_cat
= 0
p ฺ
g Stu
d
AND object_id_att = 426
a@ this
Plan hash value:bi2544181447
i a (ja use
b to
--------------------------------------------------------------------
A
i o
--------------------
J o s --------------------------------------------------------------------
--------------------
| 0 | SELECT STATEMENT | | | |
1 (100)| |
|* 1 | INDEX UNIQUE SCAN| IOTTAB_PK | 1 | 57 |
1 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN| OBJECT_ID_ATT_INDX | 50 | |
1 (0)| 00:00:01 |
--------------------------------------------------------------------
--------------------
1 - access("OBJECT_ID_ATT"=426)
filter(("OBJECT_ID"=1 AND "OBJECT_ID_CAT"=0))
2 - access("OBJECT_ID_ATT"=426)
Note
-----
- dynamic sampling used for this statement
26 rows selected.
Elapsed: 00:00:00.13
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
set echo on
5) Before trying to fix this issue, make sure you flush the important content of your SGA
by executing the flush_sga.sql script.
n s e
i ce
SQL> @flush_sga
b l el
SQL> set echo on
SQL>
fe r a
SQL> alter system flush shared_pool;
a n s
o n -tr
an
System altered.
Elapsed: 00:00:00.11
h s
a deฺ
SQL>
e )
s Gui
r ฺ
i ent
SQL> alter system flush buffer_cache;
p ฺ m
System altered.
d g Stud
b i
Elapsed: 00:00:00.43 a@ this
SQL>
i a (ja use
A b to
i o
--------------------------------------------------------------
nton
e A set echo on
6) Using hints only, how would you fix the issue raised at step 4? Implement your
solution and check if it works.
a) The idea is to use a hint to prevent the optimizer from using the secondary index.
You will not use the NO_INDEX hint.
SQL> @select_iot_hint
SQL> set echo on
SQL>
SQL> SELECT /*+ NO_INDEX(t OBJECT_ID_ATT_INDX) */ comm
2 FROM iottab t
3 WHERE object_id = 1
4 AND object_id_cat = 0
5 AND object_id_att = 426 ;
Elapsed: 00:00:00.03
SQL>
SQL> @show_latest_exec_plan
SQL> set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> select * from
table(dbms_xplan.display_cursor(null,null,'TYPICAL'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 4zcxy7z1cg8da, child number 0
-------------------------------------
n s e
SELECT /*+ NO_INDEX(t OBJECT_ID_ATT_INDX) */ comm FROM iottab t
i ce
WHERE object_id = 1 AND object_id_cat = 0 AND object_id_att =
b l el
426
fer a
Plan hash value: 181430399
a n s
n - tr
o
an
--------------------------------------------------------------------
----------
| Id | Operation | Name
h s
a deฺ
| Rows | Bytes | Cost (%CPU)|
Time |
e )
s Gui
r ฺ
mi dent
--------------------------------------------------------------------
----------
p ฺ
g Stu
|
d
0 | SELECT STATEMENT | | | | 1 (100)|
|
b i a@ this
|* 1 | INDEX RANGE SCAN| IOTTAB_PK | 1 | 57 | 1 (0)|
00:00:01 |
i a (ja use
b to
--------------------------------------------------------------------
n i oA
----------
Note
-----
- dynamic sampling used for this statement
24 rows selected.
Elapsed: 00:00:00.13
SQL>
--------------------------------------------------------------
set echo on
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
set echo on
7) Exit from your SQL*Plus session, and clean up your environment by executing the
iot_cleanup.sh script.
SQL> exit;
n s e
Disconnected from Oracle Database 11g Enterprise Edition Release
i ce
11.1.0.6.0 - Production
b l el
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options fe r a
[oracle@edrsr33p1-orcl Hints]$
a n s
[oracle@edrsr33p1-orcl Hints]$ ./iot_cleanup.sh
o n -tr
n
SQL*Plus: Release 11.1.0.6.0 - Production onaTue Apr 1 15:21:09 2008
s eฺ
a dreserved.
hrights
Copyright (c) 1982, 2007, Oracle. s ) i
ฺe nt Gu
All
i r
g p ฺm ude
Connected to:
Oracle Database 11g @
d S t
b ia hi s
Enterprise
t
Edition Release 11.1.0.6.0 -
Production
j a e
and Realb a ( to usTesting
With the Partitioning,
iApplication Oracle Label Security, OLAP, Data Mining
options
io A
t o n
SQL>
A n SQL> drop user iot cascade;
o s e
J User dropped.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Hints]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Hints
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
--------------------------------------------------------------
set echo on
exit;
8) You study a second case of hint utilization to specify hints in lower query blocks.
n s e
From your terminal session connected as the oracle user, execute the
i ce
hr_hint_setup.sh script.
b l el
fe r a
[oracle@edrsr33p1-orcl Hints]$ ./hr_hint_setup.sh
a n s
n -tr
SQL*Plus: Release 11.1.0.6.0 - Production on Tue Apr 1 16:08:51 2008
o
n
a reserved.
Copyright (c) 1982, 2007, Oracle. All rights
h s
a deฺ
e )
s Gui
r ฺ
Connected to:
Oracle Database 11g Enterprise
p ฺ miEdition
d e t
nRelease 11.1.0.6.0 -
Production d g Stu
b i
With the Partitioning,
a@Testing isoptions
Oracle
t h Label Security, OLAP, Data Mining
i a (ja use
and Real Application
SQL>
A b o
thr
n i
SQL> o alter user identified by hr account unlock;
nt o
e A User altered.
J o s SQL>
SQL> grant dba to hr
2
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Hints]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Hints
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
--------------------------------------------------------------
set echo on
grant dba to hr
exit;
n s e
i ce
9) From your terminal session, connect as the HR user in the SQL*Plus session. After
b l el
fe r a
you are connected, execute the create_hr_view1.sql script that creates a view
a n s
called V1 on top of the EMPLOYEES table. After this is done, execute the
o n -tr
create_hr_view2.sql script that creates a view V2 on top of V1.
[oracle@edrsr33p1-orcl Hints]$ sqlplus hr/hr
s an
h a on Tued ฺ 1 16:09:02 2008
eApr
SQL*Plus: Release 11.1.0.6.0 - Production ) i
i r ฺesAllnrights
t Gu reserved.
g p ฺm ude
Copyright (c) 1982, 2007, Oracle.
d S t
@ s
Connected to:
j a b ia
e thi Edition Release 11.1.0.6.0 -
a ( to us
Oracle Database 11g Enterprise
b
Productioni
i o A Partitioning,
With the Oracle Label Security, OLAP, Data Mining
ton
and Real Application Testing options
A n
o s e SQL> @create_hr_view1
J SQL>
SQL> CREATE OR REPLACE VIEW v1 AS
2 SELECT *
3 FROM employees
4 WHERE employee_id < 150;
View created.
SQL>
SQL> @create_hr_view2
SQL> set echo on
SQL>
SQL> CREATE OR REPLACE VIEW v2 AS
2 SELECT v1.employee_id employee_id, departments.department_id
department_id
3 FROM v1, departments
4 WHERE v1.department_id = departments.department_id;
View created.
--------------------------------------------------------------
set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
--------------------------------------------------------------
set echo on
A n
o s e SQL>
J SQL> select * from table(DBMS_XPLAN.DISPLAY(null,null,'ALL'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
Plan hash value: 389887213
--------------------------------------------------------------------
------------------------------
| Id | Operation | Name | Rows |
Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
------------------------------
| 0 | SELECT STATEMENT | | 3 |
33 | 1 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 3 |
33 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | DEPT_ID_PK | 1 |
4 | 0 (0)| 00:00:01 |
1 - SEL$5C160134
2 - SEL$5C160134 / DEPARTMENTS@SEL$2
3 - SEL$5C160134 / EMPLOYEES@SEL$3
4 - SEL$5C160134 / EMPLOYEES@SEL$3
i a (ja use
34 rows selected.
SQL> A
b to
ni o
nto--------------------------------------------------------------
e A
J o s set echo on
11) How do you force the query from step 10 to do a full table scan of the
departments table and a range scan of the emp_emp_id_pk index?
a) You have to use extended hint syntax to be able to specify hints that apply to
tables and indexes that appear in views. The NO_MERGE hint is used to make sure
that the view is not merged into the surrounding query blocks.
SQL> @show_exec_plan_view2_hints
SQL> set echo on
SQL>
Explained.
SQL>
SQL> select * from table(DBMS_XPLAN.DISPLAY(null,null,'ALL'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
Plan hash value: 1511767168
n s e
i ce
--------------------------------------------------------------------
b l el
---------------------------
| Id | Operation | Name | Rows |
fer a
Bytes | Cost (%CPU)| Time |
a n s
-tr
--------------------------------------------------------------------
n
o
an
---------------------------
| 0 | SELECT STATEMENT | | 3 |
78 | 5 (0)| 00:00:01 |
h s
a deฺ
| 1 | VIEW | V2
e )
s Gui | 3 |
r ฺ
mi dent
78 | 5 (0)| 00:00:01 |
| 2 | NESTED LOOPS
p ฺ
g Stu
| | |
| | |
d
|
57 |
3 |
5
NESTED LOOPS
b i a@ this
(0)| 00:00:01 |
| | 3 |
|* 4 |
i a (ja use
TABLE ACCESS FULL | DEPARTMENTS | 1 |
8 | 3
A b to
(0)| 00:00:01 |
o|n io
|* 5 |
1
INDEX RANGE SCAN
(0)| 00:00:01 |
| EMP_EMP_ID_PK | 50 |
nt
e A |* 6 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 3 |
J o s 33 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------
---------------------------
1 - SEL$335DD26A / V2@SEL$1
2 - SEL$335DD26A
4 - SEL$335DD26A / DEPARTMENTS@SEL$2
5 - SEL$335DD26A / EMPLOYEES@SEL$3
6 - SEL$335DD26A / EMPLOYEES@SEL$3
4 - filter("DEPARTMENTS"."DEPARTMENT_ID"=30)
5 - access("EMPLOYEE_ID"<150)
6 - filter("DEPARTMENT_ID"=30)
1 - "V2"."EMPLOYEE_ID"[NUMBER,22],
"V2"."DEPARTMENT_ID"[NUMBER,22]
2 - (#keys=0) "DEPARTMENTS"."DEPARTMENT_ID"[NUMBER,22],
"EMPLOYEE_ID"[NUMBER,22]
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
3 - (#keys=0) "DEPARTMENTS"."DEPARTMENT_ID"[NUMBER,22],
"EMPLOYEES".ROWID[ROWID,10], "EMPLOYEE_ID"[NUMBER,22]
4 - "DEPARTMENTS"."DEPARTMENT_ID"[NUMBER,22]
5 - "EMPLOYEES".ROWID[ROWID,10], "EMPLOYEE_ID"[NUMBER,22]
39 rows selected.
SQL>
--------------------------------------------------------------
n s e
i ce
set echo on
b l el
explain plan for
fer a
SELECT /*+ NO_MERGE(v2) INDEX(v2.v1.employees emp_emp_id_pk)
a n s
FULL(v2.departments) */ *
o n -tr
an
FROM v2
WHERE department_id = 30;
h s
a deฺ
)
s Gui
select * from table(DBMS_XPLAN.DISPLAY(null,null,'ALL'));
e
r ฺ
i ent
p ฺ m
g andSclean
12) Exit from your SQL*Plus session
d t udup your environment by executing the
hr_hint_cleanup.sh
b i a@script.
t h is
SQL> exit; (ja se Database 11g Enterprise Edition Release
i a to
b - Production
Disconnected from u
Oracle
o A
ni the Partitioning, Oracle Label Security, OLAP, Data Mining
11.1.0.6.0
t oWith
Jos
[oracle@edrsr33p1-orcl Hints]$ ./hr_hint_cleanup.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
SQL> revoke dba from hr;
revoke dba from hr
*
ERROR at line 1:
ORA-01951: ROLE 'DBA' not granted to 'HR'
View dropped.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
View dropped.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
n s e
[oracle@edrsr33p1-orcl Hints]$
i ce
b l el
--------------------------------------------------------------
fe ra
#!/bin/bash
a n s
o n -tr
an
cd /home/oracle/solutions/Hints
export ORACLE_SID=orcl
h s
a deฺ
e )
s Gui
r ฺ
i ent
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
p ฺ m d
export
d g S t u
b i a@ this
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
sqlplus b/ia
(ja u@hr_hint_cleanup.sql
se
A to
as sysdba
ni o
nto--------------------------------------------------------------
e A
J o s set echo on
exit;
13) In this third case, you investigate how to influence optimizer’s joins. From your
terminal session, execute the sh_hint_setup.sh script.
[oracle@edrsr33p1-orcl Hints]$ ./sh_hint_setup.sh
SQL>
SQL> alter user sh identified by sh acccount unlock;
alter user sh identified by sh acccount unlock
*
ERROR at line 1:
ORA-00922: missing or invalid option
SQL>
SQL> grant dba to sh;
n s e
i ce
Grant succeeded.
b l el
SQL>
fer a
SQL> connect sh/sh
a n s
Connected.
o n -tr
an
SQL>
SQL> exec dbms_stats.delete_schema_stats('SH');
h s
a deฺ
PL/SQL procedure successfully completed.
e )
s Gui
r ฺ
i ent
SQL>
p ฺ m d
SQL> exec
d g S t u
b i a@ this
dbms_stats.set_table_stats('SH','SALES',null,null,null,10,5);
i a (ja successfully
PL/SQL procedure
u se completed.
SQL> A
b to
n o
i exit;
ntoSQL>
e A Disconnected from Oracle Database 11g Enterprise Edition Release
J o s 11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Hints]$
[oracle@edrsr33p1-orcl Hints]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Hints
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
set echo on
connect sh/sh
exec dbms_stats.delete_schema_stats('SH');
exec dbms_stats.set_table_stats('SH','SALES',null,null,null,10,5);
exit;
n s e
i ce
14) From your terminal session, connect as the SH user in the SQL*Plus session. After b l el
you are connected, ensure that you flush your SGA content using the f e ra
flush_sga.sql script, and set some important session parameters a s the
nusing
n t r
- from your
set_sh_session.sql script. Ensure that you do not disconnect
o
established SQL*Plus session.
s an
h a
sh/sh ide
ฺ
)
rฺes nt GonuTue Apr 1 19:38:35 2008
[oracle@edrsr33p1-orcl Hints]$ sqlplus
( j ab se t
Connectedia
b to:
t o u
i o
Oracle A Database 11g Enterprise Edition Release 11.1.0.6.0 -
n the Partitioning, Oracle Label Security, OLAP, Data Mining
toWith
Production
n
A and Real Application Testing options
e
Jos SQL> @flush_sga
SQL>
SQL> alter system flush shared_pool;
System altered.
SQL>
SQL> alter system flush buffer_cache;
System altered.
SQL>
SQL> @set_sh_session
SQL>
SQL> set linesize 200
SQL>
SQL> set pagesize 200
SQL>
SQL> set timing on
Session altered.
Elapsed: 00:00:00.00
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
--------------------------------------------------------------
set echo on
n s e
--------------------------------------------------------------
i ce
b l el
set linesize 200
fe r a
set pagesize 200
a n s
o n -tr
an
set timing on
a
SQL> set iecho
(jaon use
SQL> @exec_and_show_sh_exec_plan
SQL> A
b to
o
ni select count(*) from sales s, customers c where
t oSQL>
e An s.cust_id=c.cust_id;
Jos COUNT(*)
----------
918843
Elapsed: 00:00:03.59
SQL>
SQL> select * from
table(dbms_xplan.display_cursor(null,null,'TYPICAL'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
--------------------------------------------------------------------
----------------------------------------------------------------
SQL_ID 88r79fy8nphrc, child number 0
-------------------------------------
select count(*) from sales s, customers c where s.cust_id=c.cust_id
| 0 | SELECT STATEMENT | | | | 3
(100)| | | |
| 1 | SORT AGGREGATE | | 1 | 26 |
| | | |
| 2 | NESTED LOOPS | | 121K| 3081K| 3
(0)| 00:00:01 | | |
| 3 | PARTITION RANGE ALL| | 10 | 130 | 3
(0)| 00:00:01 | 1 | 28 |
| 4 | TABLE ACCESS FULL | SALES | 10 | 130 | 3
(0)| 00:00:01 | 1 | 28 |
n s e
|* 5 | INDEX UNIQUE SCAN | CUSTOMERS_PK | 12138 | 154K| 0
i ce
(0)| | | |
b l el
--------------------------------------------------------------------
----------------------------------
fe r a
a n s
Predicate Information (identified by operation id):
o n -tr
an
---------------------------------------------------
5 - access("S"."CUST_ID"="C"."CUST_ID")
h s
a deฺ
e )
s Gui
r ฺ
22 rows selected.
p ฺ mi dent
Elapsed: 00:00:00.15@d
g Stu
SQL> b i a t h is
i a (ja use
b to
--------------------------------------------------------------
A
o
ni echo on
ntoset
e A
J o s select count(*) from sales s, customers c where s.cust_id=c.cust_id;
16) Before you continue, ensure that you flush the content of your SGA to avoid caching
issues later. Use the flush_sga.sql script.
SQL> @flush_sga
SQL> set echo on
SQL>
SQL> alter system flush shared_pool;
System altered.
Elapsed: 00:00:00.12
SQL>
SQL> alter system flush buffer_cache;
System altered.
--------------------------------------------------------------
set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
17) Using hints only, how would you enhance the performance of the same query you
executed in step 15? Make sure you verify your implementation.
a) In step 15, the optimizer chose a NESTED LOOPS join. You can try to force a
n s e
hash join instead, using the LEADING and USE_HASH hints.
i ce
b l el
SQL> @exec_and_show_sh_hint_exec_plan
SQL> set echo on fe r a
SQL>
a n s
o n -tr
SQL> select /*+ LEADING(c s) USE_HASH(s) */ count(*) from sales s,
customers c where s.cust_id=c.cust_id;
a n
COUNT(*)
h s
a deฺ
----------
e )
s Gui
r ฺ
mi dent
918843
p ฺ
g Stu
Elapsed: 00:00:00.40
d
SQL>
b i a@ this
(ja use
SQL> select * from
table(dbms_xplan.display_cursor(null,null,'TYPICAL'));
b i a to
o A
ni
PLAN_TABLE_OUTPUT
nto--------------------------------------------------------------------
e A --------------------------------------------------------------------
J o s ----------------------------------------------------------------
SQL_ID 9k8wcn7ckb7c1, child number 0
-------------------------------------
select /*+ LEADING(c s) USE_HASH(s) */ count(*) from sales s,
customers
c where s.cust_id=c.cust_id
--------------------------------------------------------------------
-------------------------------------------
| Id | Operation | Name | Rows | Bytes
|TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------
-------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 182 (100)| | | |
| 1 | SORT AGGREGATE | | 1 | 26 |
| | | | |
|* 2 | HASH JOIN | | 121K| 3081K|
2968K| 182 (2)| 00:00:02 | | |
--------------------------------------------------------------------
-------------------------------------------
2 - access("S"."CUST_ID"="C"."CUST_ID")
23 rows selected.
n s e
i ce
Elapsed: 00:00:00.13
b l el
SQL>
fer a
--------------------------------------------------------------
a n s
o n -tr
a nfrom sales s,
set echo on
h
select /*+ LEADING(c s) USE_HASH(s) */ count(*) s
a deฺ
customers c where s.cust_id=c.cust_id;
e )
s Gui
r ฺ
ฺ mi dent
select * from table(dbms_xplan.display_cursor(null,null,'TYPICAL'));
p
d g Stu
i a@session
18) Exit from your SQL*Plus
b t h s clean up your environment by executing the
iand
a (ja usescript.
sh_hint_cleanup.sh
i
A b to
ni o
SQL> exit
e A 11.1.0.6.0 - Production
Jos
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Hints]$
[oracle@edrsr33p1-orcl Hints]$ ./sh_hint_cleanup.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> Connected.
SQL> SQL>
User altered.
7:i
specify version as parameterฺm
r
e n tG
d gp Stud
Session altered.bia
@ his
j a e t
(
ia to u s
b
i oA
User dropped.
n
ntoold 1: CREATE USER sh IDENTIFIED BY &pass
e A
J o s new 1: CREATE USER sh IDENTIFIED BY sh
User created.
User altered.
User altered.
Grant succeeded.
...
Grant succeeded.
Connected.
Grant succeeded.
Directory created.
n s e
i ce
old 1: CREATE OR REPLACE DIRECTORY log_file_dir AS '&log_dir'
b l el
new 1: CREATE OR REPLACE DIRECTORY log_file_dir AS '/home/oracle/'
fer a
Directory created.
a n s
n -tr
o
Grant succeeded.
s an
) h a deฺ
r ฺ e s Gui
mi dent
Grant succeeded.
p ฺ
g Stu
d
Grant succeeded.
b i a@ this
Connected. (ja se
i a
baltered.to u
i o A
Session
nton
e A
J o s Session altered.
Table created.
...
Comment created.
Commit complete.
SQL>
SQL> grant dba to sh;
Grant succeeded.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Hints]$
--------------------------------------------------------------
cd /home/oracle/solutions/Hints
export ORACLE_SID=orcl
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
n s e
ice
set echo on
b l el
alter user sh identified by sh acccount unlock;
fe ra
a n s
grant dba to sh;
o n -tr
exit;
s an
) h a deฺ
20) From your terminal session, connect to rtheฺ e s Gsession
SQL*Plus ui as the SH user. After
ฺ mi scripts
you are connected, execute the following
p d e ntot further set up your environment
for this lab. Ensure that you d g connected
stay S tu to your session throughout this case.
b i a@ Hints]$
t h is sqlplus sh/sh
(ja use
[oracle@edrsr33p1-orcl
SQL> @drop_index_customers
SQL>
SQL> @dait
SQL>
SQL> drop index CUSTOMERS_YOB_BIX;
Index dropped.
Index dropped.
SQL>
SQL>
SQL> @create_cust_indexes
SQL> set echo on
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> CREATE INDEX CUST_CUST_GENDER_idx
2 ON CUSTOMERS(CUST_GENDER)
3 NOLOGGING COMPUTE STATISTICS;
Index created.
SQL>
SQL> CREATE INDEX CUST_CUST_POSTAL_CODE_idx
2 ON CUSTOMERS(CUST_POSTAL_CODE)
n s e
3 NOLOGGING COMPUTE STATISTICS;
i ce
b l el
Index created.
fer a
SQL>
a n s
SQL> CREATE INDEX CUST_CUST_CREDIT_LIMIT_idx
o n -tr
an
2 ON CUSTOMERS(CUST_CREDIT_LIMIT)
3 NOLOGGING COMPUTE STATISTICS;
h s
a deฺ
Index created.
e )
s Gui
r ฺ
SQL>
p ฺ mi dent
d g Stu
b i a@ this
--------------------------------------------------------------
REM drop (
a ja indexes
all
u seindexes
on CUSTOMERS table
REM b i
does not
to
touch associated with constraints
REM A==================================================
o n io
nt set termout off
e A
J o s store
save
set sqlplus_settings replace
buffer.sql replace
set heading off verify off autotrace off feedback off
spool dait.sql
spool off
@dait
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
set echo on
e A SQL>
Jos
SQL> SELECT
2 c.*
3 FROM customers c
4 WHERE cust_gender = 'M'
5 AND cust_postal_code = 40804
6 AND cust_credit_limit = 10000
7 /
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2008213504
--------------------------------------------------------------------
-----------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
--------------------------------------------------------------------
-----------
1 - filter(TO_NUMBER("CUST_POSTAL_CODE")=40804 AND
"CUST_CREDIT_LIMIT"=10000 AND "CUST_GENDER"='M')
Statistics
----------------------------------------------------------
n s e
1 recursive calls
i ce
0 db block gets
b l el
1460 consistent gets
0 physical reads
fe ra
0 redo size
a n s
2570 bytes sent via SQL*Net to client
o n -tr
an
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
h s
a deฺ
0 sorts (disk)
e )
s Gui
6 rows processed r ฺ
i ent
p ฺ m
SQL>
d g Stud
b i a@ this
--------------------------------------------------------------
i a (ja use
set echo
A b on
to
n i o
ntoSELECT
e A c.*
J o s FROM customers c
WHERE cust_gender = 'M'
AND cust_postal_code = 40804
AND cust_credit_limit = 10000
/
22) Try to get a better execution plan using the INDEX hint for the same query you
investigated in step 21. Which index is best suited?
a) The CUST_CUST_GENDER_IDX index is the best one for this query. Note that
using the INDEX hint without specifying any index leads the optimizer to use the
CUST_CUST_GENDER_IDX index.
SQL> @index_hint
SQL> set echo on
SQL>
SQL> SELECT /*+ INDEX (c &indexname) */
2 c.*
3 FROM customers c
4 WHERE cust_gender = 'M'
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1407552528
--------------------------------------------------------------------
--------------------------------------
n s e
| Id | Operation | Name |
i ce
Rows | Bytes | Cost (%CPU)| Time |
b l el
--------------------------------------------------------------------
--------------------------------------
fer a
| 0 | SELECT STATEMENT |
a n s |
6 | 1080 | 1074 (1)| 00:00:11 |
o n -tr
an
|* 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS |
6 | 1080 | 1074 (1)| 00:00:11 |
|* 2 | INDEX RANGE SCAN
h s
a deฺ
| CUST_CUST_CREDIT_LIMIT_IDX |
6938 | | 14 (0)| 00:00:01 |
e )
s Gui
r ฺ
mi dent
--------------------------------------------------------------------
p ฺ
--------------------------------------
g Stuby operation id):
d
Predicate Information
b i a@ this
(identified
---------------------------------------------------
i a (ja use
b to
1 - filter(TO_NUMBER("CUST_POSTAL_CODE")=40804
A
AND
o n io2 - access("CUST_CREDIT_LIMIT"=10000)
"CUST_GENDER"='M')
nt
e A
J o s Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1053 consistent gets
13 physical reads
0 redo size
2570 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
SQL>
SQL> @index_hint
SQL> set echo on
SQL>
SQL> SELECT /*+ INDEX (c &indexname) */
2 c.*
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3629874189
n s e
--------------------------------------------------------------------
i ce
--------------------------------
b l el
| Id | Operation
Bytes | Cost (%CPU)| Time |
| Name | Rows |
fer a
n s
--------------------------------------------------------------------
a
--------------------------------
o n -tr
an
| 0 | SELECT STATEMENT | | 6 |
1080 | 1164 (1)| 00:00:12 |
h s
a deฺ
|* 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS | 6 |
1080 | 1164 (1)| 00:00:12 |
e )
s Gui
r ฺ
mi dent
|* 2 | INDEX RANGE SCAN | CUST_CUST_GENDER_IDX | 27750 |
| 51 (0)| 00:00:01 |
p ฺ
g Stu
d
--------------------------------------------------------------------
b i a@ this
--------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1399 consistent gets
68 physical reads
0 redo size
2570 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
SQL>
SQL> @index_hint
SQL> set echo on
SQL>
7 /
Enter value for indexname: CUST_CUST_POSTAL_CODE_IDX
old 1: SELECT /*+ INDEX (c &indexname) */
new 1: SELECT /*+ INDEX (c CUST_CUST_POSTAL_CODE_IDX) */
6 rows selected.
Execution Plan
----------------------------------------------------------
n s e
Plan hash value: 1928091631
i ce
b l el
--------------------------------------------------------------------
-------------------------------------
fer a
| Id | Operation | Name
a n s |
Rows | Bytes | Cost (%CPU)| Time |
n - tr
o
an
--------------------------------------------------------------------
-------------------------------------
| 0 | SELECT STATEMENT |
h s
a deฺ |
6 | 1080 | 218 (1)| 00:00:03 |
e )
s Gui
r ฺ
mi dent
|* 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS |
6 | 1080 | 218 ฺ
(1)| 00:00:03 |
p
g Stu
|* 2 |
d
INDEX FULL SCAN | CUST_CUST_POSTAL_CODE_IDX |
89 | | 134
b i a@ this
(1)| 00:00:02 |
--------------------------------------------------------------------
i a (ja use
-------------------------------------
Ab to
o n io
Predicate Information (identified by operation id):
---------------------------------------------------
nt
e A
J o s 1 - filter("CUST_CREDIT_LIMIT"=10000 AND "CUST_GENDER"='M')
2 - filter(TO_NUMBER("CUST_POSTAL_CODE")=40804)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
251 consistent gets
132 physical reads
0 redo size
2570 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
SQL>
SQL> @index_hint
SQL> set echo on
6 rows selected.
Execution Plan
n s e
----------------------------------------------------------
i ce
Plan hash value: 1928091631
b l el
fer
-------------------------------------------------------------------- a
-------------------------------------
a n s
| Id | Operation | Name
n - tr |
o
an
Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
-------------------------------------
h s
a deฺ
| 0 | SELECT STATEMENT |
e )
s Gui |
r ฺ
mi dent
6 | 1080 | 218 (1)| 00:00:03 |
p ฺ
|* 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS
g Stu
|
6 | 1080 | 218
d
(1)| 00:00:03 |
|* 2 |
89 | | 134b a@ this
INDEX FULL SCAN
i(1)| 00:00:02 |
| CUST_CUST_POSTAL_CODE_IDX |
i a (ja use
--------------------------------------------------------------------
b to
-------------------------------------
A
o n io
Predicate Information (identified by operation id):
nt
e A ---------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
251 consistent gets
0 physical reads
0 redo size
2570 bytes sent via SQL*Net to client
420 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6 rows processed
SQL>
set echo on
FROM customers c
WHERE cust_gender = 'M'
AND cust_postal_code = 40804
AND cust_credit_limit = 10000
/
23) Investigate the same query, but this time using the AND_EQUAL hint. Can you find a
better execution plan with this hint?
n s e
a) Using the AND_EQUAL hint allows the optimizer to explicitly choose an
i ce
execution plan that uses an access path that merges the scans on several single-
b l el
column indexes. However, no combination is better than the
fe r a
CUST_CUST_GENDER_IDX index.
a n s
n - tr
SQL> @and_equal_hint
o
SQL> set echo on
s an
SQL>
) h a deฺ
s Gui
SQL> SELECT /*+ AND_EQUAL (c &index_name1, &index_name2) */
2 c.*
r ฺ e
3 FROM customers c
p ฺ mi dent
4 WHERE cust_gender
5 AND d g Stu
= 'M'
cust_postal_code = 40804
6 AND i a@ this
cust_credit_limit = 10000
b
7 /
i a (ja use
Enter value for index_name1: CUST_CUST_CREDIT_LIMIT_IDX
Ab to
Enter value for index_name2: CUST_CUST_GENDER_IDX
o n
oldio 1: SELECT /*+ AND_EQUAL (c &index_name1, &index_name2) */
nt new 1: SELECT /*+ AND_EQUAL (c CUST_CUST_CREDIT_LIMIT_IDX,
e A CUST_CUST_GENDER_IDX) */
J o s
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1121089724
--------------------------------------------------------------------
--------------------------------------
| Id | Operation | Name |
Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------
--------------------------------------
| 0 | SELECT STATEMENT | |
6 | 1080 | 1416 (1)| 00:00:15 |
|* 1 | TABLE ACCESS BY INDEX ROWID| CUSTOMERS |
6 | 1080 | 1416 (1)| 00:00:15 |
| 2 | AND-EQUAL | |
| | | |
1 - filter(TO_NUMBER("CUST_POSTAL_CODE")=40804 AND
"CUST_CREDIT_LIMIT"=10000 AND
"CUST_GENDER"='M')
3 - access("CUST_CREDIT_LIMIT"=10000)
4 - access("CUST_GENDER"='M')
n s e
i ce
Statistics
b l el
----------------------------------------------------------
1 recursive calls
fer a
0 db block gets
a n s
9160 consistent gets
o n -tr
an
0 physical reads
0 redo size
h
2570 bytes sent via SQL*Net to clients
a deฺ
)
s Gui
420 bytes received via SQL*Net from client
e
r ฺ
mi dent
2 SQL*Net roundtrips to/from client
0 sorts (memory)
p ฺ
g Stu
d
0 sorts (disk)
b i a@ this
6 rows processed
SQL>
i a (ja use
b echo onto
SQL> @and_equal_hint
A
i o
SQL> set
n
t oSQL>
n SQL> SELECT /*+ AND_EQUAL (c &index_name1, &index_name2) */
e A
Jos
2 c.*
3 FROM customers c
4 WHERE cust_gender = 'M'
5 AND cust_postal_code = 40804
6 AND cust_credit_limit = 10000
7 /
Enter value for index_name1: CUST_CUST_CREDIT_LIMIT_IDX
Enter value for index_name2: CUST_CUST_POSTAL_CODE_IDX
old 1: SELECT /*+ AND_EQUAL (c &index_name1, &index_name2) */
new 1: SELECT /*+ AND_EQUAL (c CUST_CUST_CREDIT_LIMIT_IDX,
CUST_CUST_POSTAL_CODE_IDX) */
6 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1928091631
--------------------------------------------------------------------
-------------------------------------
n s e
1 - filter("CUST_CREDIT_LIMIT"=10000 AND "CUST_GENDER"='M')
i ce
2 - filter(TO_NUMBER("CUST_POSTAL_CODE")=40804)
b l el
fer a
Statistics
a n s
-
----------------------------------------------------------
n tr
o
an
1 recursive calls
0 db block gets
251 consistent gets
h s
a deฺ
0 physical reads
e )
s Gui
r ฺ
mi dent
0 redo size
p ฺ
2570 bytes sent via SQL*Net to client
g Stu
d
420 bytes received via SQL*Net from client
b i a@ this
2 SQL*Net roundtrips to/from client
0 sorts (memory)
i a (ja use
0 sorts (disk)
Ab to
6 rows processed
o n io
SQL>
nt
e A
J o s --------------------------------------------------------------
set echo on
24) Exit from your SQL*Plus session and clean up your environment by executing the
sh_hint_cleanup.sh script.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> Connected.
SQL> SQL>
n s e
User altered.
i ce
b l el
SQL> SQL> revoke dba from sh
*
fer a
ERROR at line 1:
a n s
ORA-01951: ROLE 'DBA' not granted to 'SH'
o n -tr
s an
SQL> SQL> SQL> Rem
) h a deฺ cbauwens Exp $
r ฺ e s Gui
SQL> Rem $Header: sh_main.sql 06-mar-2008.15:00:45
SQL> Rem
SQL> Rem sh_main.sql ฺ m i ent
SQL> Rem
d g p t u d
...
a@ this S
SQL> Rem b i
SQL>
i a (jaOFF use
SQL> SET
A b ECHO
to
ni o
ntospecify password for SH as parameter 1:
e A
J o s specify default tablespace for SH as parameter 2:
Session altered.
User dropped.
User altered.
User altered.
Grant succeeded.
n s e
i ce
b l el
...
fer a
a n s
Grant succeeded.
o n -tr
PL/SQL procedure successfully completed.as
an
) h i d eฺ
Connected.
i r ฺes nt Gu
g p ฺm ude
Grant succeeded.
d S t
old 1: CREATE b OR
@ s
iaREPLACEthiDIRECTORY data_file_dir AS '&data_dir'
new (
1: CREATEj a OR se DIRECTORY data_file_dir AS
REPLACE
b i a to u
'/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/'
o A
ni
toDirectory created.
A n
o s e old 1: CREATE OR REPLACE DIRECTORY log_file_dir AS '&log_dir'
J new 1: CREATE OR REPLACE DIRECTORY log_file_dir AS '/home/oracle/'
Directory created.
Grant succeeded.
Grant succeeded.
Grant succeeded.
Connected.
Session altered.
Session altered.
...
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Comment created.
n s e
PL/SQL procedure successfully completed.
i ce
b l el
Commit complete.
fer a
a n s
o n -tr
an
gathering statistics ...
i oA
[oracle@edrsr33p1-orcl
n
Hints]$
nto--------------------------------------------------------------
e A
J o s #!/bin/bash
cd /home/oracle/solutions/SQL_Access_Advisor/sh
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
cp * $ORACLE_HOME/demo/schema/sales_history
SET ECHO ON
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 8000
CONNECT / AS SYSDBA
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
exit;
n s e
i ce
FIN!
b l el
ra
25) In the fifth case, you retrieve the first rows of your query as fast as possible. Connect
fe
n s
to the SQL*Plus session as the SYS user and ensure that you set the following
a
SQL*Plus environment variables:
o n -tr
timing on
s an
autotrace on
) h a deฺ
pagesize 200
r ฺ e s Gui
linesize 200
ฺ m i ent
d p
[oracle@edrsr33p1-orclgHints]$ d
tusqlplus / as sysdba
a@ S
is - Production on Tue Apr 29
b i t h
(ja use
SQL*Plus: Release 11.1.0.6.0
i
21:02:19 2008
b a to
i o A
t o n
Copyright (c) 1982, 2007, Oracle. All rights reserved.
A n
o s e
J Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data
Mining
and Real Application Testing options
26) From the same SQL*Plus session, execute the following query. Based on the fact that
you want to retrieve the first 10 rows as fast as possible, what do you observe?
SELECT employee_id, department_name
FROM hr.employees e, hr.departments d
WHERE e.department_id = d.department_id;
a) It takes a bit of time before the result starts to be printed on the screen. This is
because a merge join is used. It needs to sort all data before producing rows.
200 Administration
201 Marketing
202 Marketing
114 Purchasing
115 Purchasing
116 Purchasing
117 Purchasing
…
113 Finance n s e
i ce
el
205 Accounting
206 Accounting
a b l
fer
106 rows selected.
a n s
o n -tr
an
Elapsed: 00:00:00.09
Execution Plan h s
a deฺ
e )
s Gui
Plan hash value: 1343509718 i r ฺ
----------------------------------------------------------
p ฺ m dent
d g Stu
a@ this
--------------------------------------------------------------
b i
------------------------------
a
a (j (%CPU)|
| Id | Operation
Bytes |biCost u seTime | Name | Rows |
A to |
ni o
--------------------------------------------------------------
nto------------------------------
e A | 0 | SELECT STATEMENT | | 106 |
4 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
filter("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
19 consistent gets
0 physical reads
0 redo size
2435 bytes sent via SQL*Net to client
497 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
106 rows processed n s e
i ce
SQL>
b l el
fe r a
a n s
27) Using a hint, how can you ensure that the previous query starts fetching rows faster?
Test your solution.
o n -tr
a) Using the FIRST_ROWS(10) hint, a nested loop is chosen
a n by the optimizer. It is
faster to retrieve the first rows.
h a s eฺ
SQL> SELECT /*+ FIRST_ROWS(10) e*/ s u id department_name
)employee_id,
ฺ
ir entd G
FROM hr.employees e, hr.departments
=p ฺ m
WHERE e.department_id g
d tud
d.department_id;
S
2 3
b i a@ this
EMPLOYEE_ID DEPARTMENT_NAME
a se
-----------(j------------------------------
i a to u
b200 Administration
i o A 201 Marketing
nton 202 Marketing
e A 114 Purchasing
J o s 115 Purchasing
116 Purchasing
…
112 Finance
113 Finance
205 Accounting
206 Accounting
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 1021246405
--------------------------------------------------------------
------------------------------------
| 1 | NESTED LOOPS | |
| | | |
| 2 | NESTED LOOPS | |
10 | 230 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL | DEPARTMENTS |
25 | 400 | 2 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | EMP_DEPARTMENT_IX |
8 | | 0 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | n s e
i ce
el
3 | 21 | 1 (0)| 00:00:01 |
--------------------------------------------------------------
a b l
------------------------------------
fer
a n s
Predicate Information (identified by operation id):
o n -tr
an
---------------------------------------------------
h s
a deฺ
4 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
e )
s Gui
r ฺ
p ฺ mi dent
Statistics
d g Stu
----------------------------------------------------------
b i a@ th
0 recursive is
calls
0(ja
db block se gets
i a to
b 0 physical
40 u
consistent gets
io A reads
t o n 0 redo size
A n 2435 bytes sent via SQL*Net to client
o s e 497 bytes received via SQL*Net from client
J 9 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
106 rows processed
SQL>
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
n s e
Connected to:
i ce
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
b l el
Production
fe r a
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
a n s
o n -tr
an
SQL>
SQL> drop user trace cascade;
drop user trace cascade
h s
a deฺ
*
e )
s Gui
r ฺ
mi dent
ERROR at line 1:
p ฺ
ORA-01918: user 'TRACE' does not exist
g Stu
d
b i a@ this
SQL>
SQL> create (
a ja trace
user
u s eidentified by trace default tablespace users
i to temp;
b tablespace
temporary
o A
ni created.
toUser
A n
o s e SQL>
J SQL> grant connect, resource, dba to trace;
Grant succeeded.
SQL>
SQL>
SQL> drop tablespace tracetbs including contents and datafiles;
drop tablespace tracetbs including contents and datafiles
*
ERROR at line 1:
ORA-00959: tablespace 'TRACETBS' does not exist
SQL>
SQL> drop tablespace tracetbs3 including contents and datafiles;
drop tablespace tracetbs3 including contents and datafiles
*
ERROR at line 1:
ORA-00959: tablespace 'TRACETBS3' does not exist
Tablespace created.
SQL>
SQL> create tablespace tracetbs3
2 datafile '/u01/app/oracle/oradata/orcl/tracetbs3.dbf' size 100m
3 extent management local uniform size 10m;
Tablespace created.
SQL>
n s e
SQL>
i ce
SQL> connect trace/trace
b l el
Connected.
SQL>
fer a
SQL> drop table sales purge;
a n s
drop table sales purge
n -tr
o
an
*
ERROR at line 1:
ORA-00942: table or view does not exist
h s
a deฺ
e )
s Gui
r ฺ
i ent
SQL>
p ฺ m
d g select
SQL> create table sales as
S tu*dfrom sh.sales;
Table created. bia
@ his
j a e t
(
ia to u s
SQL>
SQL> A
b
o n io drop table sales2 purge;
SQL>
Ant drop table sales2 purge
e
Jos
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
SQL> create table sales2 tablespace tracetbs as select * from
sh.sales where 1=2;
Table created.
SQL>
SQL> drop table sales3 purge;
drop table sales3 purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
Table created.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Application_Tracing]$
--------------------------------------------------------------
#!/bin/bash
n s e
i ce
cd /home/oracle/solutions/Application_Tracing
b l el
export ORACLE_SID=orcl
fer a
a n s
o n -tr
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
s an
h a deฺ
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
)
r ฺ e s Gui
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
ฺ mi dent
sqlplus / as sysdba @at_setup.sql
p
d g Stu
b i a@ this
--------------------------------------------------------------
ntocreate
e A
J o s temporary tablespace temp;
connect trace/trace
exit;
n s e
ice
is available from the tnsnames.ora file you use to connect to your database. b l el
2) Before you can use a service in your applications, you have to make sure this service
fe r a
a n s
Modify this file to make sure it references a service called TRACESERV. You can use
the add_traceserv_tns.sh script to help you in this task.
TRACESERV = o n -tr
(DESCRIPTION =
s an
) h a deฺ
(ADDRESS = (PROTOCOL = TCP)(HOST = node)(PORT = 1521))
(CONNECT_DATA =
r ฺ e s Gui
mi dent
(SERVER = DEDICATED)
(SERVICE_NAME = TRACESERV)
p ฺ
g Stu
)
d
)
b i a@ this
( j a
[oracle@edrsr33p1-orcl
s eApplication_Tracing]$ ./add_traceserv_tns.sh
bia to
[oracle@edrsr33p1-orcl u Application_Tracing]$
io A
t o n
--------------------------------------------------------------
A n
o s e #!/bin/ksh
J y=`hostname`
DBNAME=orcl
sed 's/NODE/'$y'/'
/home/oracle/solutions/Application_Tracing/wrong_tnstraceserv.ora >
/home/oracle/solutions/Application_Tracing/tnstraceserv.ora
cp /u01/app/oracle/product/11.1.0/db_1/network/admin/tnsnames.ora
/u01/app/oracle/product/11.1.0/db_1/network/admin/tnsnames.ora.bak1
cat /home/oracle/solutions/Application_Tracing/tnstraceserv.ora >>
/u01/app/oracle/product/11.1.0/db_1/network/admin/tnsnames.ora
--------------------------------------------------------------
TRACESERV =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = NODE)(PORT = 1521))
(CONNECT_DATA =
3) You now need to declare the TRACESERV service in your database. So connect to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
n s e
Connected to:
i ce
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
b l el
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining fe r a
and Real Application Testing options
a n s
o n -tr
SQL>
a n
s eฺ with the same
a TRACESERV
4) In your SQL*Plus session, create a new service called
h
) i d
network name.
i r ฺes nt Gu
SQL> @add_traceserv_db
g p ฺm ude
SQL>
d S t
@ s
thi
SQL> select name from dba_services;
a b ia
j e
ia ( to us
NAME
b
----------------------------------------------------------------
i oA
SYS$BACKGROUND
n
toSYS$USERS
e An seeddataXDB
Jos
seeddata
orclXDB
orcl
6 rows selected.
SQL>
SQL> exec DBMS_SERVICE.CREATE_SERVICE('TRACESERV','TRACESERV');
SQL>
SQL> select name from dba_services;
NAME
----------------------------------------------------------------
SYS$BACKGROUND
SYS$USERS
seeddataXDB
seeddata
orclXDB
7 rows selected.
SQL>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
--------------------------------------------------------------
set echo on
exec DBMS_SERVICE.CREATE_SERVICE('TRACESERV','TRACESERV');
n s e
select name from dba_services;
i ce
b l el
5) From the same SQL*Plus session, start the TRACESERV service. fer a
a n s
SQL> @start_traceserv o n -tr
SQL> set echo on
s an
SQL>
) h a deฺ
SQL> show parameter service_names
r ฺ e s Gui
NAME
p ฺ mi deTYPE nt VALUE
d g
------------------------------------
S t u ----------- -------------------
a@ this
-----------
service_names
a b i string
SQL> ( j u s e
SQL> execia o
A b t
DBMS_SERVICE.START_SERVICE('TRACESERV');
i o
nton
PL/SQL procedure successfully completed.
e A
J o s SQL>
SQL> show parameter service_names
--------------------------------------------------------------
set echo on
exec DBMS_SERVICE.START_SERVICE('TRACESERV');
7) At this point, open a browser window and connect to Enterprise Manager Database
Control as the SYS user. Ensure that you navigate to the Top Services page.
a) Log in to Enterprise Manager as the SYS user.
b) On the Database Home page, click the Performance tab.
c) On the Performance page, click the Top Consumers link in the Additional n s e
Monitoring links section of the page. li ce
d) On the Top Consumers page, click the Top Services tab. This takes you tora b
the
l e
f e
Top Services page.
t r a ns
8) You now execute seven workload scripts that are traced. All workload
o n - scripts run
under the TRACESERV service. Your goal is to analyze thengenerated trace files to
interpret what happens in the seven cases. From your s a
terminalฺsession, execute the
) a degeneration of statistics
htrigger ithe
run_tracep0.sh script. This script is used s to
ฺeviewed u
G within Enterprise Manager.
for your TRACESERV service so it canirbe n tfrom
ฺ m e
p of theturun_tracep0.sh
As soon as you start the execution d script, move to the
d g S
next step of this lab.
b i a@ this
i a (ja useApplication_Tracing]$ ./run_tracep0.sh
[oracle@edrsr33p1-orcl
A
SQL*Plus: b Releaseto11.1.0.6.0 - Production on Fri Apr 4 20:28:40 2008
ni o
t o
e An Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL>
SQL> connect trace/trace@TRACESERV
Connected.
SQL>
SQL> alter session set tracefile_identifier='mytraceP0';
Session altered.
SQL>
SQL> set termout off
SQL>
SQL> exit;
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
n s e
export
i ce
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
b l el
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
fer a
sqlplus / as sysdba @run_tracep0.sql
a n s
n -tr
o
an
--------------------------------------------------------------
set echo on
h s
a deฺ
e )
s Gui
connect trace/trace@TRACESERV
r ฺ
p ฺ mi dent
alter session set tracefile_identifier='mytraceP0';
d g Stu
set termout off
b i a@ this
(ja from
select count(*)
i a u e
sdba_objects;
b
select count(*)
A o
count(*) tfrom dba_objects;
from dba_objects;
o
i count(*) from dba_objects;
select
n
ntoselect
e A select count(*) from dba_objects;
J o s select
select
count(*)
count(*)
from
from
dba_objects;
dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
select count(*) from dba_objects;
exec dbms_lock.sleep(60);
set termout on
exit;
b) On the Enable SQL Trace page, make sure Waits is set to TRUE, and Binds is set
to FALSE. Click OK.
c) Back to the Top Services page, you should see a confirmation message near the
top of the Top Consumers page.
10) When tracing for TRACESERV is enabled, execute the run_tracep1.sh script
from your terminal session. Observe your screen.
n s e
ice
el
[oracle@edrsr33p1-orcl Application_Tracing]$ ./run_tracep1.sh
b l
SQL*Plus: Release 11.1.0.6.0 - Production on Fri Apr 4 20:29:48
f e ra2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
t r a ns
o n -
s an
eฺ
a d11.1.0.6.0
Connected to:
Oracle Database 11g Enterprise Edition h
s ) Release
u i -
Production
m i rฺe Security,
n t G OLAP, Data Mining
ฺ
With the Partitioning, Oracle Label
gp options e
and Real Application Testing
d S tud
SQL>
b i a@ this
i a ( a use
SQL> connect jtrace/trace@TRACESERV
to
Connected.
SQL> Ab
o
ni alter session set workarea_size_policy=manual;
SQL>
n t o
e A Session altered.
Jos SQL>
SQL> alter session set sort_area_size=50000;
Session altered.
SQL>
SQL> alter session set hash_area_size=5000;
Session altered.
SQL>
SQL>
SQL> alter session set tracefile_identifier='mytraceP1';
Session altered.
SQL>
SQL>
SQL> set timing on
COUNT(*)
----------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
172878975
Elapsed: 00:01:19.25
SQL>
SQL>
SQL>
SQL> connect trace/trace@TRACESERV
Connected.
SQL>
SQL> alter session set tracefile_identifier='mytraceS1';
n s e
i ce
Session altered.
b l el
Elapsed: 00:00:00.00
fer a
SQL>
a n s
SQL> set timing on
o n -tr
an
SQL>
SQL> select /*+ ORDERED USE_HASH(s2) S1 */ count(*) from sales s1,
sales s2 where s1.cust_id=s2.cust_id;
h s
a deฺ
e )
s Gui
COUNT(*) r ฺ
i ent
----------
p ฺ m
172878975
d g Stud
b i
Elapsed: 00:00:40.19a@ this
SQL>
i a (ja use
b fromtoOracle Database 11g Enterprise Edition Release
SQL> exit;
A
i o
Disconnected
n
nto11.1.0.6.0 - Production
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
connect trace/trace@TRACESERV
set timing on
n s e
i ce
select /*+ ORDERED USE_HASH(s2) */ count(*) from sales s1, sales s2
b l el
where s1.cust_id=s2.cust_id;
fer a
a n s
o n -tr
an
connect trace/trace@TRACESERV
h s
a deฺ
alter session set tracefile_identifier='mytraceS1';
e )
s Gui
set timing on r ฺ
i ent
p ฺ m d*/ count(*) from sales s1, sales
d g
select /*+ ORDERED USE_HASH(s2)
S t
S1u
b i a@ this
s2 where s1.cust_id=s2.cust_id;
exit;
i a (ja use
A b to
11) o
ni the run_tracep2.sh script from your terminal session. Observe your
Execute
t o
e An screen.
Jos [oracle@edrsr33p1-orcl Application_Tracing]$ ./run_tracep2.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
SQL> connect trace/trace@TRACESERV
Connected.
SQL>
SQL> alter session set tracefile_identifier='mytraceP2';
Session altered.
3 oname varchar2(50);
4 ignore integer;
5 begin
6 for i in 1 .. 5000 loop
7 dbms_sql.parse(c,'select object_name from dba_objects where
object_id = '||i , dbms_sql.native); -- use literal
8 dbms_sql.define_column(c, 1, oname, 50);
9 ignore := dbms_sql.execute(c);
10 if dbms_sql.fetch_rows(c)>0 then
11 dbms_sql.column_value(c, 1, oname);
n s e
12 end if;
i ce
13 end loop;
b l el
14 dbms_sql.close_cursor(c);
15 end;
fer a
16 /
a n s
o n -tr
an
PL/SQL procedure successfully completed.
Elapsed: 00:00:49.36
h s
a deฺ
SQL>
e )
s Gui
SQL> r ฺ
i ent
SQL>
p ฺ m d
d g
SQL> connect trace/trace@TRACESERV
S t u
Connected.
SQL> b i a@ this
i a (ja usetsetracefile_identifier='mytraceS2';
SQL> alter session
A baltered.to
ni o
Session
ntoElapsed:
e A 00:00:00.00
J o s SQL>
SQL> declare
2 c number := dbms_sql.open_cursor;
3 oname varchar2(50);
4 ignore integer;
5 begin
6 dbms_sql.parse(c,'select object_name from dba_objects where
object_id = :y' , dbms_sql.native); -- use bind var
7 for i in 1 .. 5000 loop
8 dbms_sql.bind_variable(c,':y',i);
9 dbms_sql.define_column(c, 1, oname, 50);
10 ignore := dbms_sql.execute(c);
11 if dbms_sql.fetch_rows(c)>0 then
12 dbms_sql.column_value(c, 1, oname);
13 end if;
14 end loop;
15 dbms_sql.close_cursor(c);
16 end;
17 /
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
n s e
export ORACLE_SID=orcl
i ce
b l el
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
fer a
export
a n s
o n -tr
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
an
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
p ฺ m
set echo on
d g Stud
b i a@ this
connect trace/trace@TRACESERV
i a (jaset tracefile_identifier='mytraceP2';
u se
b
alter session
A to
o
ni timing on
ntoset
e A
J o s declare
c number := dbms_sql.open_cursor;
oname varchar2(50);
ignore integer;
begin
for i in 1 .. 5000 loop
dbms_sql.parse(c,'select object_name from dba_objects where
object_id = '||i , dbms_sql.native); -- use literal
dbms_sql.define_column(c, 1, oname, 50);
ignore := dbms_sql.execute(c);
if dbms_sql.fetch_rows(c)>0 then
dbms_sql.column_value(c, 1, oname);
end if;
end loop;
dbms_sql.close_cursor(c);
end;
/
connect trace/trace@TRACESERV
declare
c number := dbms_sql.open_cursor;
oname varchar2(50);
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
ignore integer;
begin
dbms_sql.parse(c,'select object_name from dba_objects where
object_id = :y' , dbms_sql.native); -- use bind var
for i in 1 .. 5000 loop
dbms_sql.bind_variable(c,':y',i);
dbms_sql.define_column(c, 1, oname, 50);
ignore := dbms_sql.execute(c);
if dbms_sql.fetch_rows(c)>0 then
dbms_sql.column_value(c, 1, oname);
n s e
end if;
i ce
end loop;
b l el
dbms_sql.close_cursor(c);
end;
fe r a
/
a n s
o n -tr
an
exit;
h s ฺ Observe your
aterminaldesession.
12) Execute the run_tracep3.sh script from )
your i
screen. i r ฺes nt Gu
g p ฺm ude
d t
[oracle@edrsr33p1-orcl Application_Tracing]$
S
./run_tracep3.sh
SQL>
SQL> connect trace/trace@TRACESERV
Connected.
SQL>
SQL> alter session set tracefile_identifier='mytraceP3';
Session altered.
SQL>
SQL> update sales set amount_sold=20000 where prod_id=13 and
cust_id=987;
2 rows updated.
SQL>
SQL> commit;
SQL>
SQL>
SQL> connect trace/trace
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Connected.
SQL>
SQL> create index sales_prod_cust_indx on sales(prod_id,cust_id);
Index created.
SQL>
SQL> connect trace/trace@TRACESERV
Connected.
SQL>
n s e
SQL> alter session set tracefile_identifier='mytraceS3';
i ce
b l el
Session altered.
fer a
SQL>
a n s
-tr
SQL> update sales set amount_sold=30000 where prod_id=13 and
n
o
an
cust_id=987;
2 rows updated.
h s
a deฺ
e )
s Gui
r ฺ
mi dent
SQL>
SQL> commit;
p ฺ
g Stu
d
Commit complete.
b i a@ this
SQL> a se
(jtrace/trace
b i
SQL> connecta to u
i o A
Connected.
n
toSQL>
A n SQL> drop index sales_prod_cust_indx;
o s e
J Index dropped.
SQL>
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Application_Tracing]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
--------------------------------------------------------------
set echo on
connect trace/trace@TRACESERV
connect trace/trace@TRACESERV
h s
a deฺ
e )
s Gui
r ฺ
i ent
alter session set tracefile_identifier='mytraceS3';
p ฺ m
d g Studwhere prod_id=13 and cust_id=987;
update sales set amount_sold=30000
commit; b i a@ this
ja e
ia ( to us
connect btrace/trace
i A
o index
to n
drop sales_prod_cust_indx;
A n
o s e
J exit;
13) Execute the run_tracep4.sh script from your terminal session. Observe your
screen.
[oracle@edrsr33p1-orcl Application_Tracing]$ ./run_tracep4.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
Session altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> set timing on
SQL>
SQL> DECLARE
2 TYPE SalesCurTyp IS REF CURSOR;
3 v_sales_cursor SalesCurTyp;
4 sales_record sh.sales%ROWTYPE;
5 v_stmt_str VARCHAR2(200);
6 BEGIN
n s e
7 -- Dynamic SQL statement with placeholder:
i ce
8 v_stmt_str := 'select * from sh.sales where amount_sold>0';
b l el
9
10 -- Open cursor and specify bind argument in USING clause:
fer a
11 OPEN v_sales_cursor FOR v_stmt_str;
a n s
12
n -tr
o
an
13 -- Fetch rows from result set one at a time:
14 LOOP
15
h s
a deฺ
FETCH v_sales_cursor INTO sales_record;
16 )
s Gui
EXIT WHEN v_sales_cursor%NOTFOUND;
e
17 END LOOP; r ฺ
i ent
18
-- Close cursor: g p ฺ m d
19
d S t u
20
21 END; b i a@ this
CLOSE v_sales_cursor;
22 /
i a (ja use
A b o
proceduret successfully completed.
i o
PL/SQL
n
t o
n Elapsed: 00:00:26.84
e A
Jos
SQL>
SQL>
SQL> connect trace/trace@TRACESERV
Connected.
SQL>
SQL> alter session set tracefile_identifier='mytraceS4';
Session altered.
Elapsed: 00:00:00.00
SQL>
SQL> set timing on
SQL>
SQL> DECLARE
2 TYPE SalesCurTyp IS REF CURSOR;
3 TYPE SalesList IS TABLE OF sh.sales%ROWTYPE;
4 v_sales_cursor SalesCurTyp;
5 sales_List SalesList;
6 v_stmt_str VARCHAR2(200);
7 BEGIN
8 -- Dynamic SQL statement with placeholder:
p ฺ
and Real Application Testing options
g Stu
d
[oracle@edrsr33p1-orcl Application_Tracing]$
b i a@ this
--------------------------------------------------------------
i a (ja use
b
#!/bin/bash
A to
o
ni /home/oracle/solutions/Application_Tracing
ntocd
e A
J o s export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
--------------------------------------------------------------
set echo on
connect trace/trace@TRACESERV
set timing on
DECLARE
TYPE SalesCurTyp IS REF CURSOR;
n s e
-- Close cursor:
i ce
CLOSE v_sales_cursor;
b l el
END;
/
fer a
a n s
n -tr
o
an
connect trace/trace@TRACESERV
h s
a deฺ
alter session set tracefile_identifier='mytraceS4';
e )
s Gui
set timing on r ฺ
i ent
p ฺ m d
DECLARE
TYPE SalesCurTyp @ d g S t u
a IS
TYPE SalesListbiIS TABLEth issh.sales%ROWTYPE;
REF CURSOR;
OF
(ja uSalesCurTyp;
v_sales_cursor
i a se
b
sales_List
A toVARCHAR2(200);
SalesList;
o
ni-- Dynamic SQL statement with placeholder:
v_stmt_str
ntoBEGIN
e A
J o s v_stmt_str := 'select /* S4 */ * from sh.sales where
amount_sold>0';
-- Open cursor:
OPEN v_sales_cursor FOR v_stmt_str;
-- Close cursor:
CLOSE v_sales_cursor;
END;
/
exit;
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
n s e
SQL>
i ce
SQL> connect trace/trace@TRACESERV
b l el
Connected.
fer a
SQL>
SQL> alter session set tracefile_identifier='mytraceP5';
a n s
o n -tr
an
Session altered.
SQL>
h s
a deฺ
e
SQL> insert into sales2 select * from )
s Gui union all select *
sh.sales
r ฺ
mi dent
from sales;
b i a to
A
Commit complete.
o
ni
toSQL>
A n SQL>
Session altered.
SQL>
SQL> insert into sales3 select * from sh.sales union all select *
from sales;
SQL> commit;
Commit complete.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
n s e
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
i ce
b l el
sqlplus / as sysdba @run_tracep5.sql
fer a
--------------------------------------------------------------
a n s
o n -tr
an
set echo on
connect trace/trace@TRACESERV
h s
a deฺ
e )
s Gui
r ฺ
i ent
alter session set tracefile_identifier='mytraceP5';
p ฺ m d
d
insert into sales2 selectg * from u
S t sh.sales union all select * from
sales;
commit; b i a@ this
i a (ja use
A to
btrace/trace@TRACESERV
o
ni session set tracefile_identifier='mytraceS5';
connect
ntoalter
e A
J o s insert into sales3 select * from sh.sales union all select * from
sales;
commit;
exit;
15) Execute the run_tracep6.sh script from your terminal session. Observe your
screen.
[oracle@edrsr33p1-orcl Application_Tracing]$ ./run_tracep6.sh
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
SQL>
n s e
SQL> connect trace/trace
i ce
SQL>
b l el
SQL> connect trace/trace@TRACESERV
Connected.
fer a
SQL>
a n s
SQL> update sales set amount_sold=amount_sold+1;
n -tr
o
an
Connected.
SQL>
h s
a deฺ
SQL> alter session set tracefile_identifier='mytraceP6';
e )
s Gui
Session altered. r ฺ
i ent
p ฺ m d
SQL>
d g S t u
b i a@ this
SQL> exec dbms_lock.sleep(30);
918843 rows (
a ja use
updated.
b i to
SQL> A
o
ni exec dbms_lock.sleep(60);
ntoSQL>
e A
J o s PL/SQL procedure successfully completed.
SQL>
SQL> set termout off
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Application_Tracing]$
PL/SQL procedure successfully completed.
SQL>
SQL> rollback;
Rollback complete.
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
[oracle@edrsr33p1-orcl Application_Tracing]$
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
n s e
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
i ce
b l el
sqlplus / as sysdba @run_tracep6a.sql &
fer a
sqlplus / as sysdba @run_tracep6b.sql
a n s
n -tr
o
an
--------------------------------------------------------------
h s
a deฺ
set echo on
e )
s Gui
r ฺ
connect trace/trace
p ฺ mi dent
d g Stu
b i a@ this
update sales set amount_sold=amount_sold+1;
i a (ja use
exec dbms_lock.sleep(60);
A b to
i o
rollback;
n
t o
n exit;
e A
Jos --------------------------------------------------------------
set echo on
connect trace/trace@TRACESERV
exec dbms_lock.sleep(30);
set tournout on
exit;
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
n s e
SQL>
i ce
SQL> connect trace/trace@TRACESERV
b l el
Connected.
fer a
SQL>
SQL> alter session set tracefile_identifier='mytraceP7';
a n s
o n -tr
an
Session altered.
SQL>
h s
a deฺ
SQL> declare
e )
s Gui
r ฺ
mi dent
2 c number := dbms_sql.open_cursor;
3 custid number;
amount number;dg p ฺ
4
S tu
5
a@ this
ignore integer;
b i
(ja use
6 begin
7
b i a
dbms_sql.parse(c,'select
o
t -- use bind var
cust_id, sum(amount_sold) from
i o A
sales where cust_id=2
dbms_sql.native);
group by cust_id order by cust_id' ,
J o s 10
11
ignore := dbms_sql.execute(c);
if dbms_sql.fetch_rows(c)>0 then
12 dbms_sql.column_value(c, 1, custid);
13 dbms_sql.column_value(c, 2, amount);
14 end if;
15 end;
16 /
SQL>
SQL> connect trace/trace
Connected.
SQL>
SQL> create index sales_cust_indx on sales(cust_id);
Index created.
SQL>
SQL> exit;
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
n s e
export
i ce
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
b l el
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
fer a
sqlplus / as sysdba @run_tracep7.sql
a n s
n - tr
o
an
--------------------------------------------------------------
set echo on
h s
a deฺ
connect trace/trace@TRACESERV rฺe
)
s Gui
ฺ m i ent
d p
g Stud
alter session set tracefile_identifier='mytraceP7';
declare b i a@ this
c number (
a jadbms_sql.open_cursor;
:=
u se
i to
b number;
custid number;
o A
ni ignore integer;
amount
ntobegin
e A
J o s dbms_sql.parse(c,'select cust_id, sum(amount_sold) from sales
where cust_id=2 group by cust_id order by cust_id' ,
dbms_sql.native); -- use bind var
dbms_sql.define_column(c, 1, custid);
dbms_sql.define_column(c, 2, amount);
ignore := dbms_sql.execute(c);
if dbms_sql.fetch_rows(c)>0 then
dbms_sql.column_value(c, 1, custid);
dbms_sql.column_value(c, 2, amount);
end if;
end;
/
connect trace/trace
exit;
18) Try to find out all the trace files that were generated to handle the previous seven
cases.
[oracle@edrsr33p1-orcl Application_Tracing]$ ./show_mytraces.sh
orcl_ora_19237_mytraceP0.trc
orcl_ora_19237_mytraceP0.trm
orcl_ora_19313_mytraceP1.trc
orcl_ora_19313_mytraceP1.trm
orcl_ora_19355_mytraceS1.trc
n s e
ce
orcl_ora_19355_mytraceS1.trm
orcl_ora_19382_mytraceP2.trc
eli
orcl_ora_19382_mytraceP2.trm
a b l
orcl_ora_19467_mytraceS2.trc
fe r
orcl_ora_19467_mytraceS2.trm
a n s
orcl_ora_19474_mytraceP3.trc
n - tr
orcl_ora_19474_mytraceP3.trm
o
orcl_ora_19503_mytraceS3.trc
s an
orcl_ora_19503_mytraceS3.trm
) h a deฺ
orcl_ora_19534_mytraceP4.trc
orcl_ora_19534_mytraceP4.trm
r ฺ e s Gui
orcl_ora_19549_mytraceS4.trc
p ฺ mi dent
g Stu
orcl_ora_19549_mytraceS4.trm
d
a@ this
orcl_ora_19558_mytraceP5.trc
b i
orcl_ora_19558_mytraceP5.trm
i a (ja use
orcl_ora_19568_mytraceS5.trc
b to
orcl_ora_19568_mytraceS5.trm
A
orcl_ora_19583_mytraceP6.trc
o n io
orcl_ora_19583_mytraceP6.trm
nt orcl_ora_19634_mytraceP7.trc
e A orcl_ora_19634_mytraceP7.trm
J o s [oracle@edrsr33p1-orcl Application_Tracing]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
19) After you identify the location of those trace files, merge their content into one file
called mytrace.trc located in your
$HOME/solutions/Application_Tracing directory.
[oracle@edrsr33p1-orcl Application_Tracing]$ ./merge_traces.sh
[oracle@edrsr33p1-orcl Application_Tracing]$
--------------------------------------------------------------
cd /home/oracle/solutions/Application_Tracing
export ORACLE_SID=orcl
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
n s e
20) Use tkprof over the mytrace.trc file to generate a compiled trace output called
i ce
myreport.txt located into your
b l el
$HOME/solutions/Application_Tracing directory.
f er a
an s
- t r
[oracle@edrsr33p1-orcl Application_Tracing]$ ./tkprof_traces.sh
i r ฺes nt Gu
p ฺm ude
[oracle@edrsr33p1-orcl Application_Tracing]$
g
[oracle@edrsr33p1-orcl d
S t
Application_Tracing]$
@ s
j a b ia
e thi
--------------------------------------------------------------
b ia ( to us
oA
#!/bin/bash
n i
ntocd /home/oracle/solutions/Application_Tracing
e A
J o s export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
21) In addition, run TKPROF over the trace file that was generated for case 7 (step 16)
with the EXPLAIN option set to your TRACE account.
[oracle@edrsr33p1-orcl Application_Tracing]$ tkprof
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/*mytraceP7.trc
myreport2.txt explain=trace/trace
[oracle@edrsr33p1-orcl Application_Tracing]$
[oracle@edrsr33p1-orcl Application_Tracing]$
22) After this is done, interpret the trace generated for case 1 (step 10). What do you
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
o n
call count cpu elapsed
s a n query current
disk
rows
)
------- ------ -------- ----------s----------
eฺ
ha id----------
r ฺ e G u ----------
mi0.00dent 0
----------
Parse 1 0.00
p
g Stuฺ 2 0
0 d
Execute 1
b i [email protected]
t h is 0.00 0 0 0
(j2a u78.23
se
0
Fetch
b i a o
79.16 806500 8874 0
1
i o A ------ t-------- ---------- ---------- ---------- ----------
-------
n
Anto----------
total 4 78.23 79.16 806500 8876 0
e
Jos
1
p ฺ
g elapsed
d S tu
call
rows
count
b i a@ this
cpu disk query current
i a (ja --------
------- ------
u se ---------- ---------- ---------- ----------
b 1 to 0.00
----------
Parse A
0ni
o 0.00 0 2 0
ntoExecute
e A 1 0.00 0.00 0 0 0
J o s 0
Fetch 2 40.02 40.14 10028 8874 0
1
------- ------ -------- ---------- ---------- ---------- ----------
----------
total 4 40.03 40.14 10028 8876 0
1
---------
SQL*Net message to client 2 0.00
0.00
direct path read 86 0.00
0.00
direct path write temp 166 0.00
0.00
direct path read temp 166 0.00
0.00
SQL*Net message from client 2 0.00
n s e
0.00
ice
********************************************************************
b l el
************
fe ra
a n s
23) Interpret the trace generated for case 2 (step 11). What do you observe, and what are
your conclusions?
o n -tr
a) For this case, the almost same statement was run 5000 a ntimes, but each time a
different literal was used to execute the query.a
h s eฺinefficient
This caused the system to parse
almost the same statement 5000 times, which )
s Gu is i d
extremely although the
r ฺ e
statement. However, another p ฺ mi dwaseinformation
time precision is too low to give accurate
statement
t
nalso about the parse time of each
d
time using a bind variable. S tu was parsed only 5000
gThe statement executed
once,
times, but this
and executed
i a @ i s
5000 times. This
j abbehavior
e thmuch more efficient than the previous one.
is
(
ia to u s
b
select object_name
from A
o n io
dba_objects where object_id = 1
nt
e A
J o s call count cpu elapsed disk query current
rows
------- ------ -------- ---------- ---------- ---------- ----------
----------
Parse 1 0.01 0.01 0 0 0
0
Execute 1 0.00 0.00 0 0 0
0
Fetch 1 0.00 0.00 0 3 0
0
------- ------ -------- ---------- ---------- ---------- ----------
----------
total 3 0.01 0.01 0 3 0
0
card=1)
0 NESTED LOOPS (cr=3 pr=0 pw=0 time=0 us cost=4 size=105
card=1)
0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=3 pr=0 pw=0
time=0 us cost=3 size=82 card=1)
1 INDEX RANGE SCAN I_OBJ1 (cr=2 pr=0 pw=0 time=0 us
cost=2 size=0 card=1)(object id 36)
0 INDEX RANGE SCAN I_USER2 (cr=0 pr=0 pw=0 time=0 us
cost=1 size=23 card=1)(object id 47)
0 INDEX RANGE SCAN I_USER2 (cr=0 pr=0 pw=0 time=0 us
n s e
cost=1 size=4 card=1)(object id 47)
i ce
0 TABLE ACCESS BY INDEX ROWID IND$ (cr=0 pr=0 pw=0 time=0
b l el
us cost=2 size=8 card=1)
0
fe
INDEX UNIQUE SCAN I_IND1 (cr=0 pr=0 pw=0 time=0 us r a
cost=1 size=0 card=1)(object id 41)
a n s
0 -tr
NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us cost=2 size=28
n
o
an
card=1)
0 INDEX FULL SCAN I_USER2 (cr=0 pr=0 pw=0 time=0 us
cost=1 size=20 card=1)(object id 47)
h s
a deฺ
0 )
s Gui
INDEX RANGE SCAN I_OBJ4 (cr=0 pr=0 pw=0 time=0 us
e
r ฺ
mi dent
cost=1 size=8 card=1)(object id 39)
0 ฺ
FILTER (cr=0 pr=0 pw=0 time=0 us)
p
g Stu
0
d
NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us cost=1 size=83
card=1)
0 b i a@ this
INDEX FULL SCAN I_LINK1 (cr=0 pr=0 pw=0 time=0 us
i a (ja use
cost=0 size=79 card=1)(object id 134)
0b to
INDEX RANGE SCAN I_USER2 (cr=0 pr=0 pw=0 time=0 us
n i oA
cost=1 size=4 card=1)(object id 47)
nto********************************************************************
e A
J o s ************
select object_name
from
dba_objects where object_id = 2
...
select object_name
from
dba_objects where object_id = 5000
a0 n
0
Fetch 1 0.00 0.00 5 0
1
h a s e ฺ
------- ------
s )
-------- ---------- ----------
u i d---------- ----------
---------- r ฺ
i0.00e tG 0
total 3 0.00
p ฺ m d e n 5 0
1
d g S t u
@ s
Misses in library
j a b e thi parse: 1
iacache during
ia (id:to182us (recursive depth: 1)
Optimizer mode: ALL_ROWS
Parsing buser
e A
J o s 1 VIEW DBA_OBJECTS (cr=5 pr=0 pw=0 time=0 us cost=5 size=158
card=2)
1 UNION-ALL (cr=5 pr=0 pw=0 time=0 us)
1 FILTER (cr=5 pr=0 pw=0 time=0 us)
1 NESTED LOOPS (cr=5 pr=0 pw=0 time=0 us cost=5 size=109
card=1)
1 NESTED LOOPS (cr=4 pr=0 pw=0 time=0 us cost=4 size=105
card=1)
1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=3 pr=0 pw=0
time=0 us cost=3 size=82 card=1)
1 INDEX RANGE SCAN I_OBJ1 (cr=2 pr=0 pw=0 time=0 us
cost=2 size=0 card=1)(object id 36)
1 INDEX RANGE SCAN I_USER2 (cr=1 pr=0 pw=0 time=0 us
cost=1 size=23 card=1)(object id 47)
1 INDEX RANGE SCAN I_USER2 (cr=1 pr=0 pw=0 time=0 us
cost=1 size=4 card=1)(object id 47)
0 TABLE ACCESS BY INDEX ROWID IND$ (cr=0 pr=0 pw=0 time=0
us cost=2 size=8 card=1)
0 INDEX UNIQUE SCAN I_IND1 (cr=0 pr=0 pw=0 time=0 us
cost=1 size=0 card=1)(object id 41)
********************************************************************
************
n s e
i ce
b l el
fer a
a n s
o n -tr
s an
select object_name
) h a deฺ
from
r ฺ e s Gui
mi dent
dba_objects where object_id = :y
p ฺ
g elapsed
d S tu
call
rows
count
b i a@ this
cpu disk query current
i a (ja --------
------- ------
u se ---------- ---------- ---------- ----------
b 1 to 0.00
----------
Parse A
0ni
o 0.00 0 0 0
ntoExecute 5000
e A 0.20 0.18 0 0 0
J o s 0
Fetch 5000 0.24 0.24 0 26837 0
4928
------- ------ -------- ---------- ---------- ---------- ----------
----------
total 10001 0.45 0.43 0 26837 0
4928
Jos
as it uses an index to speed up the retrieval of the rows that need to be updated.
update sales set amount_sold=20000
where
prod_id=13 and cust_id=987
------- ---------------------------------------------------
0 UPDATE SALES (cr=4441 pr=2442 pw=2442 time=0 us)
2 TABLE ACCESS FULL SALES (cr=4441 pr=2442 pw=2442 time=17
us cost=1366 size=4251 card=109)
p ฺ
g Stu
d
b i a@ this
a
(jset se
b i
update salesa to u
amount_sold=30000
where A
i o
nprod_id=13
n t o and cust_id=987
e A
Jos call
rows
count cpu elapsed disk query current
b i a@ this
call
a (ja uscpu
count
i
e elapsed disk query current
rows b o
A ------ t-------- ---------- ---------- ---------- ----------
i o
-------
n
nto----------
e A Parse 1 0.02 0.02 0 0 0
J o s 0
Execute 1 0.00 0.00 0 0 0
0
Fetch 918844 5.89 5.93 0 918944 0
918843
------- ------ -------- ---------- ---------- ---------- ----------
----------
total 918846 5.92 5.95 0 918944 0
918843
select /* S4 */ *
from
sh.sales where amount_sold>0
Rows a
Row(jSource se
a to uOperation
------- bi---------------------------------------------------
n i o A PARTITION
918843 RANGE ALL PARTITION: 1 28 (cr=1811 pr=0 pw=0
nto 918843 TABLE ACCESS FULL SALES PARTITION: 1 28 (cr=1811 pr=0 pw=0
time=21132 us cost=547 size=26646447 card=918843)
e A
Jos
time=8617 us cost=547 size=26646447 card=918843)
********************************************************************
************
26) Interpret the trace generated for case 5 (step 14). What do you observe, and what are
your conclusions?
a) Here, the first statement incurs too many recursive calls to allocate extents to the
table. This is because the tablespace in which it is stored is not correctly set up for
extent allocations. The alternate case is much better as you can see the number of
disk values going way down compared to the first case. Also the number of
recursive statements in the second case should be much lower than the first one.
insert into sales2 select * from sh.sales union all select * from
sales
p
g Stuฺ
time=6976 us cost=1369 size=94580484 card=1087132)
d
b i
Elapsed times includea@waiting
t h is on following events:
Event waited
i a (jaon use Times Max. Wait
b
Total Waited
A to
n i o
---------------------------------------- Waited ---------- ---
e A 51 0.00
J o s 0.03
log file switch completion 2 0.00
0.00
log buffer space 8 0.09
0.23
SQL*Net message to client 1 0.00
0.00
SQL*Net message from client 1 0.00
0.00
********************************************************************
************
select file#
from
file$ where ts#=:1
n s e
Rows Row Source Operation
i ce
------- ---------------------------------------------------
b l el
1 TABLE ACCESS FULL FILE$ (cr=4 pr=0 pw=0 time=0 us cost=2
size=6 card=1)
fer a
a n s
- tr
********************************************************************
n
o
an
************
h s
a deฺ
e )
s Gui
r ฺ
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
insert into sales3 select * from sh.sales union all select * from
sales
nt
e A
J o s call count cpu elapsed disk query current
rows
------- ------ -------- ---------- ---------- ---------- ----------
----------
Parse 1 0.00 0.00 0 1 0
0
Execute 1 3.64 5.13 1087 22471 77748
1837686
Fetch 0 0.00 0.00 0 0 0
0
------- ------ -------- ---------- ---------- ---------- ----------
----------
total 2 3.65 5.14 1087 22472 77748
1837686
p ฺ
log file switch (private strand flush incomplete)
g Stu
d 313 0.05
0.10
b i a@ this
SQL*Net message to client 1 0.00
0.00
i a (ja use
Ab to
SQL*Net message from client 1 0.00
o n io
0.00
********************************************************************
nt
e A ************
J o s 27) Interpret the trace generated for case 6 (step 15). What do you observe, and what are
your conclusions?
a) This case is more difficult to understand. Here, you select a table that is entirely
locked by another transaction. This forces the query to generate consistent read
blocks for almost the entire table causing undo segments to be accessed. This is
materialized by an important disk value, and almost no current blocks.
select cust_id, sum(amount_sold)
from
sales group by cust_id order by cust_id
o io
0.00
nSQL*Net message from client 472 0.00
nt
e A 0.02
J o s ********************************************************************
************
28) Interpret the trace generated for case 7 (step 16). What do you observe, and what are
your conclusions?
a) For case 7, you should compare the content in myreport.txt with the content
in myreport2.txt. You should see that an index was added after the first trace
was generated. This situation can cause confusion especially if the trace does not
contain an execution plan to begin with. This is what you can see from within
myreport.txt:
select cust_id, sum(amount_sold)
from
sales where cust_id=2 group by cust_id order by cust_id
h s
a deฺ
e )
s Gui
r ฺ
i ent
ฺ m
********************************************************************
p
************
d g Stud
i
b) This is what youbseea@ h is
from myreport2.txt:
t
a (ja use
SQL ID : i51xxq509gnbbc
selectA b
cust_id, o
tsum(amount_sold)
i o
tonsales where cust_id=2 group by cust_id order by cust_id
from
A n
o s e
J call count cpu elapsed disk query current
rows
------- ------ -------- ---------- ---------- ---------- ----------
----------
Parse 1 0.00 0.00 0 1 0
0
Execute 2 0.00 0.00 0 0 0
0
Fetch 1 0.05 0.05 0 4441 0
1
------- ------ -------- ---------- ---------- ---------- ----------
----------
total 4 0.06 0.06 0 4442 0
1
n s e
i ce
Elapsed times include waiting on following events:
b l el
Event waited on
Total Waited
Times Max. Wait
fer a
---------------------------------------- n s
Waited ---------- ---
a
---------
o n -tr
an
SQL*Net message to client 1 0.00
0.00
SQL*Net message from client
h s
a deฺ
1 0.00
0.00
e )
s Gui
r ฺ
mi dent
********************************************************************
************
p ฺ
g Stuby executing the at_cleanup.sh script
29) You can now clean up your d
environment
from your terminal b i a@ this
window.
i a (ja useApplication_Tracing]$ ./at_cleanup.sh
b to
[oracle@edrsr33p1-orcl
A
ni o
n t oSQL*Plus: Release 11.1.0.6.0 - Production on Fri Apr 4 20:45:24 2008
SQL>
SQL> drop user trace cascade;
User dropped.
SQL>
SQL> drop tablespace tracetbs including contents and datafiles;
Tablespace dropped.
SQL>
SQL> drop tablespace tracetbs3 including contents and datafiles;
SQL>
SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
[oracle@edrsr33p1-orcl Application_Tracing]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Application_Tracing
n s e
i ce
export ORACLE_SID=orcl
b l el
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
fer a
a n s
export
o n -tr
an
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
h s
a deฺ
)
s Gui
rm /u01/app/oracle/diag/rdbms/orcl/orcl/trace/*mytrace*.*
e
r ฺ
rm mytrace.trc
p ฺ mi dent
d g Stu
rm myreport.txt
b i a@ this
i a (ja use
rm myreport2.txt
A b to
o
ni $ORACLE_HOME/network/admin/tnsnames.ora.bak1
rm $ORACLE_HOME/network/admin/tnsnames.ora
ntomv
e A
J o s $ORACLE_HOME/network/admin/tnsnames.ora
--------------------------------------------------------------
set echo on
exit;
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
the View Data field is set to Real Time: 15 second Refresh. After this is done, open a
terminal emulator window connected as the oracle user. When this is done, change
your current directory to your lab directory: cd
$HOME/solutions/SQL_Tuning_Advisor. Then enter the following
command from the OS prompt: ./setup_dina.sh
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$ ./setup_dina.sh
n s e
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$ ./setup_dina.sh
ice
b l el
PL/SQL procedure successfully completed.
fe r a
a n s
Grant succeeded.
n - tr
o
s an
Session altered.
) h a deฺ
r ฺ e s Gui
ฺ i ent
mcompleted.
p
g Stud
PL/SQL procedure successfully
d
a@ this completed.
PL/SQL procedurebisuccessfully
i a (ja use
A b to
i
Usero altered.
nton
e A
J o s User altered.
Index dropped.
Index created.
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$
--------------------------------------------------------------
#!/bin/bash
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
set echo on
connect / as sysdba
n s e
i ce
exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT();
b l el
fer a
grant dba to SH;
a n s
n -tr
rem -- event to allow setting very short Flushing interval
o
s a n forever, level
alter session set events '13508 trace name context
1';
) h a deฺ
r ฺ e s Gui
p
rem -- change INTERVAL setting ฺ mito 2dminutes
e nt
g Sto
rem -- change RETENTIONdsetting tu 6 hours (total of 180 snapshots)
@ his
ia360);
execute dbms_workload_repository.modify_snapshot_settings(interval
=> 2,retentiona=>
j b e t
(
ia to u s
b
n i
rem o--Aplay with ADDM sensitiveness
ntoexec
e A dbms_advisor.set_default_task_parameter('ADDM','DB_ACTIVITY_MIN',30)
J o s ;
connect sh/sh
EOF
2) After this is executed, execute the start_dinas.sh script by using the following
command: ./start_dinas.sh
This script starts the workload used for this lab.
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/SQL_Tuning_Advisor
n s e
i ce
el
export ORACLE_SID=orcl
a b l
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
fer
a n s
export
n -tr
o
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
an
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
s
) h a deฺ
STREAM_NUM=0
r ฺ e s Gui
MAX_STREAM=6
p ฺ mi dent
PIDLST=""
d g Stu
while [ $STREAM_NUM
b i a@ h is
-lt $MAX_STREAM
t ]; do
i
# one morea (ja use
let A b to
STREAM_NUM="STREAM_NUM+1"
o
nt oni# start one more stream
eA sqlplus -S sh/sh @dina.sql &
done
#
# Save PID List
#
echo $PIDLST > /tmp/dina_pids
--------------------------------------------------------------
DECLARE
n number;
BEGIN
for i in 1..1000 loop
select /*+ ORDERED USE_NL(c) FULL(c) FULL(s)*/ count(*) into n
from sales s, customers c
to 100%. If they are not, ensure that what you see is the latest ADDM analysis.
d) Click the “Top SQL by DB Time” link.
e) On the “Performance Finding Details: Top SQL by DB Time” page, click Show
All Details link. You should see something similar to the following: Run SQL
Tuning Advisor on the SQL statement with SQL_ID "5mxdwvuf9j3vp". Next to
this recommendation, click the Run Advisor Now button.
f) Wait on the Processing: SQL Tuning Advisor Task SQL_TUNING_… page for a n s e
ice
while.
b l el
g) You are automatically directed to the Recommendations for SQL
fe r a
n
ID:5mxdwvuf9j3vp” page from where you should see two recommendations-one
a s
for a SQL Profile and one for an index creation.
o n -tr
h) You can investigate the consequence of implementing
s a nthe recommended profile
by comparing execution plans before and after
) h i eฺ
aprofiledimplementation. You can
do so by clicking the “Compare explain
SQL Profile row. Because the potential i r ฺesbenefit
n t of
u icon for the corresponding
plan” eyeglass
G using the proposed SQL profile
p ฺ m d e
g Costs),
is very high (see both computed
d S tu you implement the SQL profile.
i
i) On the Compare Explain
b a@ Planst h ispage, click the Recommendations for SQL
(ja ulocator
ID:5mxdwvuf9j3vp
i a se link.
j) Back A to
bto the Recommendations for SQL ID:5mxdwvuf9j3vp page, ensure that the
n i o
SQL Profile row is selected, and click Implement.
n t o
e A k) On Confirmation page, click Yes.
Jos l) On Recommendations for SQL ID:5mxdwvuf9j3vp page, you should see the
following message at its top: “Confirmation: The recommended SQL Profile has
been created successfully”.
m) Click Return.
n) On SQL Tuning Results:TASK, click the Database Instance: orcl locator link.
o) Back to the Database Home Page, click the Performance tab.
5) After following the SQL Tuning Advisor recommendation to implement a SQL
Profile, how can you quickly verify that the problem is solved?
a) On the Performance tabbed page, you expect to see a dramatic drop for the Other
wait class in the Average Active Sessions graph. However, when you view the
graph you see that not has changed.
6) How do you interpret the result you see, and how would you ensure that the new
profile is taken into account?
statements again, and the profile should be used automatically this time.
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$ ./stop_dinas.sh
Killing stream with pid=30486
DECLARE
*
ERROR at line 1:
ORA-00028: your session has been killed
n s e
Killing stream with pid=30485
ice
DECLARE
b l el
*
fe ra
ERROR at line 1:
ORA-00028: your session has been killed
a n s
n - tr
o
Killing stream with pid=30482
s an
DECLARE
) h a deฺ
*
r ฺ e s Gui
mi killed nt
ERROR at line 1:
ORA-00028: your session has ฺbeen e
d p
g Stu d
b i a@ t h is
(ja use
Killing stream with pid=30481
DECLARE
b i a to
*
o A
ni
ERROR at line 1:
e A
J o s Killing stream with pid=30480
DECLARE
*
ERROR at line 1:
ORA-00028: your session has been killed
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/SQL_Tuning_Advisor
export ORACLE_SID=orcl
n s e
i ce
el
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
a b l
export
fer
a n s
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
-tr
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
o n
PIDLST=`cat /tmp/dina_pids`
s an
) h a deฺ
#
r ฺ e s Gui
# Kill all these processes
# p ฺ mi dent
for PID in $PIDLST; do dg tu
S
b ia@@kill_dina.sql
echo "Killing stream
sqlplus / asasysdba
withis
t h pid=$PID"
sqlplus a ( u s e
j @/tmp/drop_dina.sql $PID >> /tmp/stop_dina.log 2>&1
oA
kill -9 2>&1
n i
done
nto
e A --------------------------------------------------------------
spool /tmp/drop_dina.sql;
spool off
exit;
7) How would you make sure that the SQL Profile was implemented?
a) On the Average Active Sessions graph, click the Other wait category in the
caption.
b) On the Active Sessions Waiting: Other page, you should see that your statement
waits for the latch free event. You can see that from the ACTIVITY(%) column.
c) Click the 5mxdwvuf9j3vp SQL Id link in the Top SQL table.
d) On the SQL Details: 5mxdwvuf9j3vp page, click the Plan Control tab in the n s e
i ce
Details section.
b l el
r
e) You should see that this statement is associated to a SQL Profile that was
fe a
n s
manually implemented. It is part of the DEFAULT category and is ENABLED.
a
n -tr
8) Clean up your environment by executing the following commands from your
o
command-line window:
s an
./stop_dians.sh
) h a deฺ
./cleanup_dina.sh
r ฺ e s Gui
p ฺ mi dent ./stop_dinas.sh
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$
d g Stu
Killing stream with pid=31740
DECLARE
b i a@ this
(ja1: use
*
b
ORA-00028:i a
ERROR at line
your o
tsession has been killed
A
io stream with pid=31735
t o n
Killing
A n DECLARE
o s e *
J ERROR at line 1:
ORA-00028: your session has been killed
[oracle@edrsr33p1-orcl SQL_Tuning_Advisor]$
Revoke succeeded.
n s e
i ce
el
specify password for SH as parameter 1:
a b l
specify default tablespace for SH as parameter 2:
fer
a n s
-tr
specify temporary tablespace for SH as parameter 3:
o n
specify password for SYS as parameter 4:
s an
specify directory path for the data files
) h i d eฺ 5:
a as parameter
i r es files
ฺlog t G u
ฺm uden
writeable directory path for the as parameter 6:
g p
d 7:St
specify version as parameter
i a @ h is
b t
i a (ja use
Session altered.
A b to
o
ni dropped.
ntoUser
e A
J o s old
new
1: CREATE USER sh IDENTIFIED BY &pass
1: CREATE USER sh IDENTIFIED BY sh
User created.
User altered.
User altered.
Grant succeeded.
...
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Grant succeeded.
Grant succeeded.
Connected.
n s e
i ce
Grant succeeded.
b l el
fer a
old
s
1: CREATE OR REPLACE DIRECTORY data_file_dir AS '&data_dir'
a n
-tr
new 1: CREATE OR REPLACE DIRECTORY data_file_dir AS
n
'/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/'
o
Directory created.
s an
) h a deฺ
old 1: CREATE OR REPLACE DIRECTORY
r ฺ e s Gui AS '&log_dir'
log_file_dir
new i elog_file_dir
1: CREATE OR REPLACE DIRECTORY
ฺ m n t AS '/home/oracle/'
Connected.
Session altered.
Session altered.
Table created.
Table created.
...
Table created.
Table altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
...
Table altered.
a b l
specify path for log files as parameter 3:
fer
a n s
-tr
specify version as parameter 4:
o n
an
Looking for indexes that could slow down load ...
s
no rows selected
) h a deฺ
r ฺ e s Gui
loading TIMES using: p ฺ mi dent
d g Stu
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/time_v
3.ctl
b i a@ this
3.dat
i a (ja use
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/time_v
A b to
/home/oracle/time_v3.log
ni o
ntoSQL*Loader: Release 11.1.0.6.0 - Production on Thu Mar 20 15:22:23
e A 2008
3.ctl
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/cust1v
3.dat
/home/oracle/cust1v3.log
o n
Load completed - logical record count 55500.
s an
) h a deฺ
loading PRODUCTS using:
r ฺ e s Gui
3.ctl p ฺ mi dent
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/prod_v
d g Stu
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/prod1v
3.dat
b i a@ this
i a (ja use
/home/oracle/prod1v3.log
A
SQL*Loader: to 11.1.0.6.0 - Production on Thu Mar 20 15:22:24
b Release
i o
ton
2008
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/chan_v
3.ctl
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/chan_v
3.dat
/home/oracle/chan_v3.log
h a deฺ
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/sale1v
)
3.dat
r ฺ e s Gui
/home/oracle/sale1v3.log
p ฺ mi dent
d g S-tuProduction on Thu Mar 20 15:22:25
SQL*Loader: Release 11.1.0.6.0
2008
b i a@ this
Copyright a
i (ja1982,u2007,
(c) se Oracle. All rights reserved.
A b o
treached
n i
Save o data point - logical record count 100000.
nt o...
Table created.
( j
b ia to u
oA
Commit complete.
o n i
nt
eA Enabling constraints ...
...
Table altered.
Index created.
...
Index created.
Dimension created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Commit complete.
no rows selected
Dimension created.
n s e
i ce
b l el
PL/SQL procedure successfully completed.
fer a
a n s
no rows selected n -tr
o
s an
Dimension created.
) h a deฺ
r ฺ e s Gui
ฺ i ent
mcompleted.
p
g Stud
PL/SQL procedure successfully
d
b i a@ this
i a (ja use
no rows selected
A b to
i o
ton
Dimension created.
A n
o s e PL/SQL procedure successfully completed.
J
no rows selected
Dimension created.
no rows selected
View created.
Table created.
Table created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Index created.
Index created.
Index created.
Index created.
n s e
i ce
Creating materialized views ...
b l el
fer a
a n s
Materialized view created.
n -tr
o
Materialized view created.
s an
) h a deฺ
r ฺ e s Gui
Creating comments ...
p ฺ mi dent
Comment created. d g Stu
b i a@ this
...
i a (ja use
A b to
ni o
ntoComment created.
e A
J o s Creating OLAP metadata ...
<<<<< CREATE CWMLite Metadata for the Sales History Schema >>>>>
-
<<<<< CREATE CATALOG sh_cat for Sales History >>>>>
Catalog Dropped
CWM Collect Garbage
-
<<<<< CREATE the Sales CUBE >>>>>
Sales amount, Sales quantity
<TIMES CHANNELS PRODUCTS CUSTOMERS PROMOTIONS >
Drop SALES_CUBE prior to recreation
Cube Dropped
Add dimensions -
to SALES_CUBE and map the foreign keys
Create measures -
for SALES_CUBE and map to columns in the fact table
Set default aggregation method -
to SUM for all measures over TIME
Add SALES_CUBE to the catalog
SALES_CUBE successfully added to sh_cat
Add dimensions -
to COST_CUBE and map the foreign keys
Create measures -
for COST_CUBE and map to columns in the fact table
Set default aggregation method -
to SUM for all measures over TIME
Add COST_CUBE to the catalog
COST_CUBE successfully added to sh_cat
-
<<<<< TIME DIMENSION >>>>>
n s e
i ce
el
Dimension - display name, description and plural name
Level - display name and description
a b l
Hierarchy - display name and description
fer
- default calculation hierarchy
a n s
- default display hierarchy
Level Attributes - name, display name, description n - tr
o
Drop dimension attributes prior to re-creation
s an
Create dimension attributes and add their level attributes
- Long Description created
) h a deฺ
- Short Description created
r ฺ e s Gui
p ฺ mi dent
- Period Number of Days created
- Period End Date created
d g Stu
Classify entity descriptor use
i a@ this
- Time dimension
b
i a (ja use
- Long description
- Day name
Ab to
- Calendar month description
J o s - Short Description
- Day name
- Calendar month description
- Calendar quarter description
- Fiscal month description
- Fiscal quarter description
- Time Span
- Days in calendar month
- Days in calendar quarter
- Days in calendar year
- Days in fiscal month
- Days in fiscal quarter
- Days in fiscal year
- End Date
- End of calendar month
- End of calendar quarter
- End of calendar year
- End of fiscal month
- End of fiscal quarter
- End of fiscal year
-
A b
PL/SQL procedure tosuccessfully completed.
i o
nton
e A PL/SQL procedure successfully completed.
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/SQL_Tuning_Advisor
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
#
# Cleanup ADDM snapshot settings
#
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
connect / as sysdba
d g Stu
EOF
b i a@ this
#
i a (ja use
# Cleanup
# io
to
Ab sql profile
n
tosqlplus -s /NOLOG <<EOF > /tmp/cleanup_dina.log 2>&1
A n
o s e connect / as sysdba
J
set head off
set timing off
set feedback off;
set pagesize 0
spool /tmp/drop_dyn.sql;
spool off
@/tmp/drop_dyn.sql
EOF
cp /home/oracle/solutions/SQL_Access_Advisor/sh/*
$ORACLE_HOME/demo/schema/sales_history
n s e
i ce
cd /home/oracle/solutions/SQL_Access_Advisor/sh
b l el
fer a
sqlplus -s /NOLOG <<EOF
a n s
set echo on
o n -tr
connect / as sysdba
s an
) h a deฺ
revoke dba from sh;
r ฺ e s Gui
p ฺ
@sh_main sh example temp oraclemi dent
d g Stu
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/
/home/oracle/ v3 a@ is
b i t h
EOF
i a (ja use
A b to
i o
nton
e A
J o s
a b l
Copyright (c) 1982, 2007, Oracle. All rights reserved.
fe r
a n s
Connected to:
o n -tr
an
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
s
Production
) h a deฺ
s Gui
With the Partitioning, Oracle Label Security, OLAP, Data Mining
ฺ
and Real Application Testing options
r
i ente
p ฺ mSQL>
SQL> SQL> d g StudSQL> SQL> SQL> SQL> Connected.
SQL> SQL> SQL> SQL> SQL> SQL>
SQL> SQL> SQL> SQL> SQL> SQL> SQL> DROP TABLE temp_table purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
Table created.
*
ERROR at line 1:
SQL> SQL>
Table created.
n s e
SQL> SQL> SQL> 2 3 4 5 6 7
i ce
PL/SQL procedure successfully completed.
b l el
SQL> SQL> drop table customersjfv purge
fer a
*
a n s
ERROR at line 1:
o n -tr
an
ORA-00942: table or view does not exist
h s
a deฺ
SQL>
e )
s Gui
Table created. r ฺ
i ent
p
3 g 4
ฺ m 5ud 6
SQL> SQL> SQL> 2
16 @ d S t 20 217 228 239 2410 11 12
13
27
14
28
15
29 b
30i
17 18
a 31 t32
h is 33 34 35 36 37 38
19 25
39
26
40
41 42 43(ja44 se 46 47
45 48 49
b i a
PL/SQL procedure
to u
successfully completed.
o A
t o niCOUNT(*)
SQL> SQL> SQL>
An
e
Jos
----------
5
1 row selected.
SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
LAST_ANAL
---------
18-MAR-08
18-MAR-08
18-MAR-08
18-MAR-08
18-MAR-08
18-MAR-08
18-MAR-08
18-MAR-08
14 rows selected.
n s e
SQL> SQL> SQL> SQL> Disconnected from Oracle Database 11g Enterprise
i ce
Edition Release 11.1.0.6.0 - Production
b l el
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
fer a
[oracle@edrsr33p1-orcl SQL_Access_Advisor]$
a n s
o n -tr
an
--------------------------------------------------------------
#!/bin/bash
h s
a deฺ
e )
s Gui
r ฺ
i ent
cd /home/oracle/solutions/SQL_Access_Advisor
p ฺ m
export ORACLE_SID=orcl g
d S tud
b i a@ this
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export bia
(ja use
A to
ni o
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
ntol/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
e A
J o s sqlplus / as sysdba <<FIN!
SET ECHO ON
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 8000
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 100
SET LONG 1000
CONNECT / AS SYSDBA
connect sh/sh
Rem Clean up
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
declare
name varchar2(30);
cursor name_cur1 is
select task_name from user_advisor_templates
where task_name like '%SQLACCESS%';
begin
----------------------------------------------------------------
-----------
-- Get rid of templates, tasks and workloads.
----------------------------------------------------------------
n s e
-----------
i ce
b l el
open name_cur1;
fer a
loop
a n s
fetch name_cur1 into name;
o n -tr
an
exit when name_cur1%NOTFOUND;
h s
a deฺ
)
s Gui
dbms_advisor.update_task_attributes(name,null,null,'FALSE','FALSE');
e
r ฺ
mi dent
dbms_advisor.delete_task(name);
end loop;
p
g Stuฺ
close name_cur1;@d
b i a t h is
end;
i a (ja use
/
A b to
i o
nton
e A
J o s Rem make a temp table
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
end loop;
commit;
end;
/
n s e
drop table customersjfv purge;
i ce
create table customersjfv as select * from customers;
b l el
fe r a
DECLARE
a n s
sql_stmt varchar2(2000);
o n -tr
an
sqlsetname VARCHAR2(30);
sqlsetcur dbms_sqltune.sqlset_cursor;
refid NUMBER;
h s
a deฺ
k NUMBER := 0;
e )
s Gui
r ฺ
mi dent
num_queries NUMBER := 500;
BEGIN
p ฺ
g S2tu*/ ch.channel_class, c.cust_city,
sql_stmt := 'SELECT @ /* d
b i
t.calendar_quarter_desc,a t h is
QueryJFV
SUM(s.amount_sold) sales_amount FROM
sh.sales s, ( j a
sh.times e
sAND s.cust_id = c.cust_id AND ch
t, sh.customers c, sh.channels WHERE
s.time_idb i a
= t.time_id u
toc.cust_state_province = ''CA'' AND ch.channel_desc
s.channel_id =
A
io(''Internet'',''Catalog'') AND t.calendar_quarter_desc IN
ch.channel_id AND
o n
in
t (''1999-01'',''1999-02'') GROUP BY ch.channel_class, c.cust_city,
A n
o s e t.calendar_quarter_desc';
J insert into temp_table values(1,1,NULL,0,'SH','Access
Advisor','Workload',0,0,0,0,1,100,2,to_date('02-FEB-
2007'),3,0,sql_stmt,1);
2007'),3,0,sql_stmt,1);
n s e
sql_stmt := 'SELECT /* QueryJFV 5 */ * FROM sh.customersjfv WHERE
i ce
cust_state_province = ''CA''';
b l el
insert into temp_table values(1,1,NULL,0,'SH','Access
fer a
Advisor','Workload',0,0,0,0,1,100,2,to_date('02-FEB-
a n s
2007'),3,0,sql_stmt,1);
o n -tr
s an
h
sqlsetname := 'SQLSET_MY_SQLACCESS_WORKLOAD';
) a deฺ
r ฺ e G ui
s 'Generated
m i
dbms_sqltune.create_sqlset(sqlsetname,
n t STS');
dbms_sqltune.load_sqlset(sqlsetname, sqlsetcur);
END;
/
EXECUTE DBMS_STATS.UNLOCK_SCHEMA_STATS('SH');
exit;
n s e
FIN!
ice
b l el
fe
2) Using Enterprise Manager, create a SQL Access Advisor tuning task based on the ra
captured workload held in the SH.SQLSET_MY_ACCESS_WORKLOAD SQL a n s
tuning set using the SQLACCESS_WAREHOUSE template.
o n -tr
n
a) Connect to Enterprise Manager Database Control asathe sh user (password: sh).
On the Home page, click the Advisor Centralhlink
s
a in the ฺ Links section.
eRelated
)
s Advisors i d
u link. Then on the SQL
b) On the Advisor Central page, clickithe r ฺeSQL t G
Advisors page, click the SQLpAccess
g ฺm uAdvisor
d en link.
d S t Options from a previously saved Task
c) On the Initial Options @ s
page, select Inherit
a selectththei SQLACCESS_WAREHOUSE template. After
ithen
or Template,ja b
and
i a
this is done, se
( click Continue.
u
OnA
d) io
b to
the Workload Source page, select Use an existing SQL Tuning Set and enter
n
Anto SH.SQLSET_MY_SQLACCESS_WORKLOAD in the SQL Tuning Set field.
(This SQL Tuning Set was generated earlier. It represents a warehouse workload
e
Jos that you want to analyze.) Click Next.
e) On the Recommendation Options page, ensure that all possible access structures
are selected, and that Comprehensive is selected. After this is done, click Next.
f) On the Schedule page, enter MY_SQLACCESS_TASK in the Task Name field.
Select the first Time Zone from the provided list (Click the torch icon.). After this
is done, click Next.
g) On the Review page, click Submit.
h) Back to the Advisor Central page, click Refresh until the Status of your task is
COMPLETED.
i) After this is done, click the MY_SQLACCESS_TASK link in the Results table.
3) After this is done, investigate the proposed recommendations:
a) Back to the Advisor Central page, click the MY_SQLACCESS_TASK link in the
Results table. The task should have COMPLETED as the status.
b ia to u
i o ADatabase
Connected
n
to:
e A Production
SQL> @implement
SQL>
SQL> Rem
SQL> Rem Creating new partitioned table
SQL> Rem
SQL> CREATE TABLE "SH"."CUSTOMERS1"
2 ( "CUST_ID" NUMBER,
3 "CUST_FIRST_NAME" VARCHAR2(20),
4 "CUST_LAST_NAME" VARCHAR2(40),
5 "CUST_GENDER" CHAR(1),
6 "CUST_YEAR_OF_BIRTH" NUMBER(4,0),
7 "CUST_MARITAL_STATUS" VARCHAR2(20),
8 "CUST_STREET_ADDRESS" VARCHAR2(40),
9 "CUST_POSTAL_CODE" VARCHAR2(10),
10 "CUST_CITY" VARCHAR2(30),
11 "CUST_CITY_ID" NUMBER,
12 "CUST_STATE_PROVINCE" VARCHAR2(40),
13 "CUST_STATE_PROVINCE_ID" NUMBER,
20 "CUST_TOTAL_ID" NUMBER,
21 "CUST_SRC_ID" NUMBER,
22 "CUST_EFF_FROM" DATE,
23 "CUST_EFF_TO" DATE,
24 "CUST_VALID" VARCHAR2(1)
25 ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS
NOLOGGING
26 TABLESPACE "EXAMPLE"
27 PARTITION BY RANGE ("CUST_ID") INTERVAL( 3000) ( PARTITION
VALUES LESS THAN (3000)
n s e
28 );
i ce
b l el
Table created.
fer a
SQL>
a n s
SQL> Rem
o n -tr
an
SQL> Rem Copying comments to new partitioned table
SQL> Rem
SQL>
h s
a deฺ
COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_ID" IS 'primary key';
e )
s Gui
Comment created. r ฺ
i ent
p ฺ m d
SQL>
d g S t u
b i a@ "SH"."CUSTOMERS1"."CUST_FIRST_NAME"
SQL> COMMENT ON COLUMN
name of the customer'; t h is IS 'first
ja e
ia ( to us
Comment bcreated.
n i oA
ntoSQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_LAST_NAME" IS 'last
SQL>
e A
J o s name of the customer';
Comment created.
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_GENDER" IS 'gender;
low cardinality attribute';
Comment created.
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_YEAR_OF_BIRTH" IS
'customer year of birth';
Comment created.
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_MARITAL_STATUS" IS
'customer marital status; low cardinality attribute';
Comment created.
Comment created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_POSTAL_CODE" IS
'postal code of the customer';
Comment created.
SQL>
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_CITY" IS 'city where
n s e
the customer lives';
i ce
b l el
Comment created.
fer a
SQL>
a n s
o n -tr
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_STATE_PROVINCE" IS
an
'customer geography: state or province';
Comment created.
h s
a deฺ
e )
s Gui
SQL> r ฺ
i ent
p ฺ m
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."COUNTRY_ID"
d IS 'foreign
d
key to the countries tableg t u
(snowflake)';
S
@ s
Comment created.bia
j a e thi
SQL> b ia ( to us
i o A mainONphone
SQL> COMMENT
n
COLUMN "SH"."CUSTOMERS1"."CUST_MAIN_PHONE_NUMBER" IS
nto'customer number';
e A
J o s Comment created.
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_INCOME_LEVEL" IS
'customer income level';
Comment created.
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_CREDIT_LIMIT" IS
'customer credit limit';
Comment created.
SQL>
SQL> COMMENT ON COLUMN "SH"."CUSTOMERS1"."CUST_EMAIL" IS 'customer
email id';
Comment created.
SQL>
Comment created.
SQL>
SQL> Rem
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Table altered.
n s e
SQL>
i ce
SQL> Rem
b l el
SQL> Rem Copying referential constraints to new partitioned table
SQL> Rem
fer a
SQL> ALTER TABLE "SH"."CUSTOMERS1" ADD CONSTRAINT
a n s
"CUSTOMERS_COUNTRY_FK1" FOREIGN KEY ("COUNTRY_ID")
o n -tr
an
2 REFERENCES "SH"."COUNTRIES" ("COUNTRY_ID") ENABLE
NOVALIDATE;
h s
a deฺ
Table altered.
e )
s Gui
r ฺ
i ent
SQL>
p ฺ m d
SQL> Rem
d g S t u
SQL> Rem b i a@ tto
SQL> Rem Copying indexes
h isnew partitioned table
SQL> CREATE (
a ja uINDEX
BITMAP se "SH"."CUSTOMERS_GENDER_BIX1" ON
i o
b 10 tINITRANS
"SH"."CUSTOMERS1" ("CUST_GENDER")
i o A
2 PCTFREE 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS
to n 3 TABLESPACE "EXAMPLE" LOCAL;
A n
o s e Index created.
J SQL>
SQL> Rem
SQL> Rem Copying object grants to new partitioned table
SQL> Rem
SQL> GRANT SELECT ON "SH"."CUSTOMERS1" TO "BI";
Grant succeeded.
SQL>
SQL> Rem
SQL> Rem Populating new partitioned table with data from original
table
SQL> Rem
SQL> INSERT /*+ APPEND */ INTO "SH"."CUSTOMERS1"
2 SELECT * FROM "SH"."CUSTOMERS";
SQL> COMMIT;
SQL>
SQL> begin
2 dbms_stats.gather_table_stats('"SH"', '"CUSTOMERS1"', NULL,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
dbms_stats.auto_sample_size);
3 end;
4 /
SQL>
SQL> Rem
SQL> Rem Renaming tables to give new partitioned table the original
table name
n s e
SQL> Rem
i ce
SQL> ALTER TABLE "SH"."CUSTOMERS" RENAME TO "CUSTOMERS11";
b l el
Table altered.
fer a
a n s
SQL> ALTER TABLE "SH"."CUSTOMERS1" RENAME TO "CUSTOMERS";
o n -tr
Table altered.
s an
) h a deฺ
SQL>
r ฺ e s Gui
SQL> Rem
ฺ
SQL> Rem Revalidating dimensionsm i for eusent with new partitioned table
SQL> Rem p
dg Stu d
SQL> ALTER DIMENSION@
b i a t h is
"SH"."CUSTOMERS_DIM" COMPILE;
i a (ja use
Dimension altered.
SQL> A
b to
n i o
ntoSQL>
e A SQL> CREATE MATERIALIZED VIEW LOG ON
J o s 2 "SH"."CUSTOMERS"
3 WITH ROWID,
SEQUENCE("CUST_ID","CUST_CITY","CUST_STATE_PROVINCE")
4 INCLUDING NEW VALUES;
SQL>
SQL> CREATE MATERIALIZED VIEW LOG ON
2 "SH"."CHANNELS"
3 WITH ROWID,
SEQUENCE("CHANNEL_ID","CHANNEL_DESC","CHANNEL_CLASS")
4 INCLUDING NEW VALUES;
SQL>
SQL> CREATE MATERIALIZED VIEW LOG ON
2 "SH"."TIMES"
3 WITH ROWID, SEQUENCE("TIME_ID","CALENDAR_QUARTER_DESC")
4 INCLUDING NEW VALUES;
SQL>
SQL> CREATE MATERIALIZED VIEW LOG ON
2 "SH"."SALES"
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
3 WITH ROWID,
SEQUENCE("CUST_ID","TIME_ID","CHANNEL_ID","AMOUNT_SOLD")
4 INCLUDING NEW VALUES;
SQL>
SQL> CREATE MATERIALIZED VIEW "SH"."MV_01DF0000"
2 REFRESH FAST WITH ROWID
3 ENABLE QUERY REWRITE
n s e
4 AS SELECT SH.CUSTOMERS.CUST_STATE_PROVINCE C1,
i ce
SH.CUSTOMERS.CUST_CITY C2, SH.CHANNELS.CHANNEL_CLASS
b l el
5 C3, SH.CHANNELS.CHANNEL_DESC C4, SH.TIMES.CALENDAR_QUARTER_DESC
C5, SUM("SH"."SALES"."AMOUNT_SOLD")
fer a
n
6 M1, COUNT("SH"."SALES"."AMOUNT_SOLD") M2, COUNT(*) M3 FROM
a s
SH.CUSTOMERS,
n -tr
o
an
7 SH.CHANNELS, SH.TIMES, SH.SALES WHERE SH.SALES.CHANNEL_ID =
SH.CHANNELS.CHANNEL_ID
h s
a deฺ
8 AND SH.SALES.TIME_ID = SH.TIMES.TIME_ID AND SH.SALES.CUST_ID =
SH.CUSTOMERS.CUST_ID
e )
s Gui
r ฺ
mi dent
9 AND (SH.TIMES.CALENDAR_QUARTER_DESC IN ('1999-04', '1999-03',
'1999-02'
p ฺ
g Stu
d
10 , '1999-01')) AND (SH.CHANNELS.CHANNEL_DESC IN ('Internet',
'Catalog'
b i a@ this
11 )) AND (SH.CUSTOMERS.CUST_STATE_PROVINCE = 'CA') GROUP BY
i a (ja use
SH.CUSTOMERS.CUST_STATE_PROVINCE,
b to
12 SH.CUSTOMERS.CUST_CITY, SH.CHANNELS.CHANNEL_CLASS,
A
o n io
SH.CHANNELS.CHANNEL_DESC,
13 SH.TIMES.CALENDAR_QUARTER_DESC;
nt
e A
J o s Materialized view created.
SQL>
SQL> begin
2
dbms_stats.gather_table_stats('"SH"','"MV_01DF0000"',NULL,dbms_stats
.auto_sample_size);
3 end;
4 /
SQL>
SQL> CREATE BITMAP INDEX "SH"."CUSTOMERSJFV_IDX_01DF0000"
2 ON "SH"."CUSTOMERSJFV"
3 ("CUST_STATE_PROVINCE")
4 COMPUTE STATISTICS;
Index created.
SQL>
Index created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
SQL>
SQL> CREATE INDEX "SH"."CUSTOMERS_IDX_01DF0002"
2 ON "SH"."CUSTOMERS"
3 ("COUNTRY_ID","CUST_CITY","CUST_LAST_NAME")
4 COMPUTE STATISTICS;
Index created.
SQL>
n s e
SQL> exit
ice
Disconnected from Oracle Database 11g Enterprise Edition Release
b l el
11.1.0.6.0 - Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
fe r a
and Real Application Testing options
a n s
[oracle@edrsr33p1-orcl SQL_Access_Advisor]$
o n -tr
i) Back to your Guided Workflow page, click the Execute a nicon corresponding to
step 3.
h s
a deฺ
e )
s Gui
j) On the Create Replay Trial page, enter
i r ฺ MY_SQL_REPLAY_AFTER
n t in the Replay
Trial Name field. Ensure that you
p m
ฺ ude
select the Trial environment established check
box, and click Submit. d g S t
@ s
k) Wait until step b
j a 3 is
e thi
iacompleted.
l) Backb toia
(
your Guided u s
Workflow Enterprise Manager page, click the Execute icon
A
corresponding
t o
to step 4.
n i o
Antom) On the Run Replay Trial Comparison page, ensure that you create a comparison
e between MY_SQL_REPLAY_BEFORE and MY_SQL_REPLAY_AFTER. Click
Jos Submit.
n) Wait until step 4 is completed.
o) Back to your Guided Workflow Enterprise Manager page, click the Execute icon
corresponding to step 5.
p) On the SQL Performance Analyzer Task Result page, you can clearly see that the
second trial is much faster than the original one. You should see that all five SQL
statements are improved in the second trial due a changed execution plan.
q) To get more details, analyze the differences in execution plan for all five
statements. You can do so directly from the SQL Performance Analyzer Task
Result page by clicking each SQL ID in the Top 10 table. Each time you click a
SQL ID, you can see in the SQL Details section all statistics differences between
the two trials as well as the differences in execution plans.
6) From a terminal session, execute the revert.sh script to return to the situation you
were in before you started the lab.
[oracle@edrsr33p1-orcl SQL_Access_Advisor]$ ./revert.sh
( j a b e
iaSQL>
SQL> SQL> Connected. u s
b
SQL> SQL> o
A 8 9t 10 11SQL>12SQL>13SQL>14SQL>15SQL>16 2 17 3 18 4 19 5
SQL> SQL>
6 io 7
n 21 22 23 24
to20
A n PL/SQL procedure successfully completed.
o s e
J SQL> SQL> SQL> SQL> SQL> SQL>
Table dropped.
SQL> SQL>
System altered.
SQL> SQL>
Table dropped.
SQL> SQL>
Table dropped.
SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
Materialized view log dropped.
SQL> SQL>
Materialized view log dropped.
SQL> SQL>
Materialized view log dropped.
n s e
SQL> SQL>
i ce
Materialized view dropped.
b l el
SQL> SQL>
fer a
Index dropped.
a n s
o n -tr
an
SQL> SQL>
Table dropped.
h s
a deฺ
SQL> SQL>
e )
s Gui
Table dropped. r ฺ
i ent
p ฺ m d
SQL> SQL> Connected.
d g S t u
SQL> SQL>
b
Revoke succeeded. i a@ this
i a (jaRem use
A b $Header:tosh_main.sql 06-mar-2008.15:00:45 cbauwens Exp $
SQL> SQL> SQL>
o
i Rem
SQL> Rem
n
ntoSQL>
e A SQL> Rem sh_main.sql
J o s SQL>
SQL>
Rem
Rem Copyright (c) 2001, 2008, Oracle. All rights reserved.
SQL> Rem
SQL> Rem NAME
SQL> Rem sh_main.sql - Main schema creation and load script
...
SQL> Rem
SQL>
SQL> SET ECHO OFF
Session altered.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
User dropped.
User created.
User altered.
h s
a deฺ
e )
s Gui
r ฺ
Grant succeeded.
p ฺ mi dent
d g Stu
Grant succeeded.bia
@ his
j a e t
(
ia to u s
... A
b
o n io
nt
e A
J o s Grant succeeded.
Grant succeeded.
Connected.
Grant succeeded.
Directory created.
Grant succeeded.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Grant succeeded.
Grant succeeded.
Connected.
Session altered.
n s e
Session altered.
i ce
b l el
Table created.
fer a
a n s
n -tr
o
an
Table created.
h s
a deฺ
...
e )
s Gui
r ฺ
i ent
p ฺ m
Table created.
d g Stud
b i a@ this
(ja us...
Creating constraints
i a
e
b
altered. t
Table A
o
i o
nton
e A
J o s ...
Table altered.
no rows selected
n s e
loading COUNTRIES using:
i ce
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/coun_v
b l el
3.ctl
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/coun_v
fer a
3.dat
a n s
/home/oracle/coun_v3.log
o n -tr
SQL*Loader: Release 11.1.0.6.0 - Production a on n Thu Mar 20 15:22:24
2008
h a s eฺ
) i d
Copyright (c) 1982, 2007, Oracle.
i r ฺesAllnrights
t Gu reserved.
g p ฺm ude
t
d recordScount
i a @
Load completed - logical
h i s 23.
b
ja use t
ia ( tousing:
loading bCUSTOMERS
i oA
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/cust_v
n
nto/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/cust1v
3.ctl
e A
J o s 3.dat
/home/oracle/cust1v3.log
e A
J o s /u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/chan_v
3.dat
/home/oracle/chan_v3.log
...
Save data point reached - logical record count 900000.
Table created.
n s e
i ce
b l el
82112 rows created.
fer a
a n s
loading additonal SALES using:
o n -tr
an
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/dmsal_
v3.ctl
h s
a deฺ
/u01/app/oracle/product/11.1.0/db_1/demo/schema/sales_history/dmsal_
v3.dat
e )
s Gui
/home/oracle/dmsal_v3.log r ฺ
i ent
p ฺ m d
d g
SQL*Loader: Release 11.1.0.6.0
S
- u
t Production on Thu Mar 20 15:22:38
2008
b i a@ this
Copyright (c)
i a (ja1982,u2007,
se Oracle. All rights reserved.
A o
b point treached
i o
Save data
n
- logical record count 100.
e A
J o s Load completed - logical record count 2804.
Commit complete.
Table altered.
...
Table altered.
n s e
Creating additional indexes ...
i ce
b l el
Index created.
fer a
a n s
...
n - tr
o
s an
Index created.
) h a deฺ
r ฺ e s Gui
Create dimensions ...
p ฺ mi dent
Dimension created. @d
g Stu
b i a t h is
i a (ja use
b
Commit complete.
A to
o
ni procedure successfully completed.
ntoPL/SQL
e A
J o s
no rows selected
Dimension created.
no rows selected
Dimension created.
no rows selected
Dimension created.
no rows selected
Dimension created.
n s e
i ce
no rows selected
b l el
Creating MVs as tables ...
fer a
a n s
n -tr
o
an
View created.
h s
a deฺ
Table created.
e )
s Gui
r ฺ
i ent
p ฺ m
Table created.
d g Stud
b i a@ this
Index created.
i a (ja use
A b to
o
ni created.
n t oIndex
e A
Jos Index created.
Index created.
Comment created.
...
Comment created.
<<<<< CREATE CWMLite Metadata for the Sales History Schema >>>>>
-
<<<<< CREATE CATALOG sh_cat for Sales History >>>>>
Catalog Dropped
CWM Collect Garbage
-
<<<<< CREATE the Sales CUBE >>>>>
Sales amount, Sales quantity
<TIMES CHANNELS PRODUCTS CUSTOMERS PROMOTIONS >
Drop SALES_CUBE prior to recreation
n s e
Cube Dropped
i ce
Add dimensions -
b l el
to SALES_CUBE and map the foreign keys
Create measures -
fer a
for SALES_CUBE and map to columns in the fact table
a n s
Set default aggregation method -
n - tr
o
an
to SUM for all measures over TIME
Add SALES_CUBE to the catalog
h s
a deฺ
SALES_CUBE successfully added to sh_cat
-
e )
s Gui
r ฺ
mi dent
<<<<< CREATE the Cost CUBE >>>>>
p ฺ
Unit Cost, Unit Price < TIMES PRODUCTS CHANNELS PROMOTIONS >
g Stu
d
Drop COST_CUBE prior to recreation
Cube Dropped
b i a@ this
Add dimensions -
i a (ja use
to COST_CUBE and map the foreign keys
b to
Create measures -
A
o n io for COST_CUBE and map to columns in the fact table
Set default aggregation method -
nt
e A to SUM for all measures over TIME
o s e No attribute to drop
J No attribute to drop
No attribute to drop
No attribute to drop
No attribute to drop
No attribute to drop
No attribute to drop
No attribute to drop
Create dimension attributes and add their level attributes
- Long Description created
- Short Description created
- Other Customer Information created
Classify entity descriptor use
- Long Description
- Short Description
-
<<<<< PRODUCTS DIMENSION >>>>>
Dimension - display name, description and plural name
Level - display name and description
Hierarchy - display name and description
- default calculation hierarchy
p ฺ
<<<<< CHANNELS DIMENSION >>>>>
g Stu
d
Dimension - display name, description and plural name
b i a@ this
Level - display name and description
Hierarchy - display name and description
i a (ja use
- default calculation hierarchy
b to
- default display hierarchy
A
o n io
Level Attributes - name, display name, description
Drop dimension attributes prior to re-creation
nt
e A No attribute to drop
Commit complete.
[oracle@edrsr33p1-orcl SQL_Access_Advisor]$
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/SQL_Access_Advisor/sh
export ORACLE_SID=orcl
n s e
i ce
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
b l el
export
fer a
n s
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
a
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin:/bin
n -tr
cp * $ORACLE_HOME/demo/schema/sales_history a n
o
h a s eฺ
sqlplus / as sysdba <<FIN!
e s ) u id
ฺ
ir ent G
SET ECHO ON ฺ m
p tud
SET FEEDBACK 1
d g
SET NUMWIDTH 10
i a @ his S
SET LINESIZE 8000
SET TRIMSPOOL ( j aONb se t
ia to u
SET TAB bOFF
i A
oLONG
SET PAGESIZE 100
to n
SET 1000
A n
o s e CONNECT / AS SYSDBA
J grant dba to sh;
connect sh/sh
Rem Clean up
declare
name varchar2(30);
cursor name_cur1 is
select task_name from user_advisor_templates
where task_name like '%SQLACCESS%';
open name_cur1;
loop
fetch name_cur1 into name;
exit when name_cur1%NOTFOUND;
dbms_advisor.update_task_attributes(name,null,null,'FALSE','FALSE');
dbms_advisor.delete_task(name);
n s e
end loop;
i ce
b l el
close name_cur1;
fer a
end;
a n s
/
n - tr
o
s an
Rem make a temp table
) h a deฺ
r ฺ e s Gui
DROP TABLE temp_table purge;ฺmi e nt
d p
g Stu d
b i a@ this
alter system flush shared_pool;
(ja upurge;
drop table tempjfv
i a se
A to
b customersjfv
i o
drop table
n
purge;
nto
e A
J o s execute dbms_advisor.delete_task('%');
execute dbms_advisor.delete_sqlwkld('%');
execute dbms_sqltune.drop_sqlset('SQLSET_MY_SQLACCESS_WORKLOAD');
EXECUTE DBMS_STATS.UNLOCK_SCHEMA_STATS('SH');
connect / as sysdba
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
exit;
FIN!
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
nt
e A
J o s
Enabled, and click Configure. Click the Configure button next to Automatic SQL
Tuning. Select Yes for “Automatic Implementation of SQL Profiles.” Then, click
Apply. Execute the ast_setup.sh script from a terminal window connected as the
oracle user. This script creates the AST user used throughout this practice, turns off
automatic maintenance tasks, and drops any existing profiles on queries executed by
the AST user.
n s e
$ cd /home/oracle/solutions/Automatic_SQL_Tuning
ice
b l el
$ ./ast_setup.sh
f er a
an s
[oracle@edrsr33p1-orcl Automatic_SQL_Tuning]$ ./ast_setup.sh
- t r
n 18 15:31:49
SQL*Plus: Release 11.1.0.6.0 - Production on Tue n oMar
2008
s a
Copyright (c) 1982, 2007, Oracle. s ) a eฺ
hrights idreserved.
i r ฺe nt Gu
All
g p ฺm ude
Connected to:
Oracle Database 11g @
d S t
b i a t h i
Enterprises Edition Release 11.1.0.6.0 -
SQL> SQL>
User created.
SQL> SQL>
Grant succeeded.
SQL> SQL>
System altered.
--------------------------------------------------------------
#!/bin/bash
cd /home/oracle/solutions/Automatic_SQL_Tuning
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
n s e
i ce
export
b l el
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
fer a
a n s
sqlplus / as sysdba <<FIN!
n -tr
o
set echo on
s an
) h a deฺ
drop user ast cascade;
r ฺ e s Gui
create user ast identified by ฺ i ent
mast;
d g p t u d
grant dba to ast; @
a is S
b i t h
a shared_pool;
alter system(jflush
i a u se
A b to
--
n o
i Turn off AUTOTASK
nto--
e A --
--
-- Clear out old executions of auto-sqltune
--
exec dbms_sqltune.reset_tuning_task('SYS_AUTO_SQL_TUNING_TASK');
--
-- Drop any profiles on AST queries
--
declare
cursor prof_names is
select name from dba_sql_profiles where sql_text like '%AST%';
begin
for prof_rec in prof_names loop
dbms_sqltune.drop_sql_profile(prof_rec.name);
end loop;
end;
FIN!
2) In preparation for the practice, you should execute a workload. Execute the
run_workload_stream.sh script. This script executes, multiple times, a query that
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
is not correctly optimized. The query in question uses hints that force the optimizer to
pick a suboptimal execution plan. The script execute for approximately 30 seconds.
./run_workload_stream.sh
[oracle@edrsr33p1-orcl Automatic_SQL_Tuning]$
./run_workload_stream.sh
Tue Mar 18 15:38:05 GMT-7 2008
n s e
ice
el
SQL*Plus: Release 11.1.0.6.0 - Production on Tue Mar 18 15:38:05
2008
a b l
fe r
Copyright (c) 1982, 2007, Oracle. All rights reserved.
a n s
o n -tr
Connected to:
s a n11.1.0.6.0 -
Oracle Database 11g Enterprise Edition Release
Production
)
With the Partitioning, Oracle LabelsSecurity,
eฺ Data Mining
ha idOLAP,
i r ฺe nt Gu
and Real Application Testing options
g p ฺm ude
SQL> SQL> SQL> SQL> d S t
no rows selected a@ s
j a b i
e thi
SQL>
ia ( to us
no rows bselected
n i oA
ntoSQL>
e A no rows selected
J o s ...
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
--------------------------------------------------------------
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
#!/bin/bash
cd /home/oracle/solutions/Automatic_SQL_Tuning
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
n s e
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
i ce
b l el
date
fer a
sqlplus ast/ast <<FIN!
a n s
o n -tr
set echo on
n
a c.cust_id,
select /*+ USE_NL(s c) FULL(s) FULL(c) AST
h s
a deฺ c where s.cust_id
*/
sum(s.quantity_sold) from sh.sales s,) sh.customers
r ฺ e G ui
sby c.cust_id;
= c.cust_id and c.cust_id < 2 group
ฺ m i ent
…
d p
g Stud
select /*+ USE_NL(sb i a@ t h is FULL(c) AST */ c.cust_id,
c) FULL(s)
ja usfrom
(and
sum(s.quantity_sold)
a
e sh.sales s, sh.customers c where s.cust_id
b i
= c.cust_id
to
c.cust_id < 2 group by c.cust_id;
io A
t o n
FIN!
A n
o s e date
J 3) Automatic SQL Tuning is implemented using an automated task that runs during
maintenance windows. However, you do not wait for the next maintenance window to
open. Instead, you force the opening of your next maintenance window now. This
automatically triggers the Automatic SQL Tuning task. Execute the run_ast.sh
script to open your next maintenance window now. The script’s execution takes a
couple of minutes.
./run_ast.sh
SQL> SQL>
WINDOW
--------------------------------------------------------------------
n s e
------------
i ce
TUESDAY_WINDOW
b l el
SQL> SQL> SQL> SQL> SQL> SQL> 2
fer a
System altered.
a n s
o n -tr
an
SQL> SQL> >
PL/SQL procedure successfully completed.
h s
a deฺ
SQL> SQL> >
e )
s Gui
r ฺ
i ent
PL/SQL procedure successfully completed.
p ฺ m d
SQL> SQL>
d g S t u
b i a@ this completed.
PL/SQL procedure successfully
n o
i SQL> 2 3 4 5 6 7 8 9 10
toSQL> 11 12 13
e An 14 15 16 17 18 19 20 21 22
Jos
PL/SQL procedure successfully completed.
SQL> SQL> 2
System altered.
--------------------------------------------------------------
#!/bin/bash
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
date
set echo on
n s e
i ce
exec dbms_workload_repository.create_snapshot;
b l el
variable window varchar2(20);
fer a
a n s
begin
o n -tr
an
select upper(to_char(sysdate,'fmday'))||'_WINDOW' into :window from
dual;
end;
h s
a deฺ
/
e )
s Gui
r ฺ
print window;
p ฺ mi dent
d g Stu
--
b i a@ thmaintenance
-- Open the corresponding is window, but with other clients
j a e
ia ( to us
disabled
-- b
n i o Asystem set "_enable_automatic_maintenance"=1
nto/
alter
e A
J o s exec dbms_auto_task_admin.disable( -
'auto optimizer stats collection', null, :window);
exec dbms_auto_task_admin.disable( -
'auto space advisor', null, :window);
--
-- Close the maintenance window when sqltune is done
--
exec dbms_lock.sleep(60);
declare
running number;
begin
loop
select count(*)
if (running = 0) then
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
exit;
end if;
dbms_lock.sleep(60);
end loop;
dbms_scheduler.close_window(:window);
end;
/
n s e
ice
alter system set "_enable_automatic_maintenance"=0
b l el
/
fe r a
--
a n s
-
-- Re-enable the other guys so they look like they are enabled in
n tr
o
an
EM.
-- Still they will be disabled because we have set the underscore.
--
h s
a deฺ
e )
s Gui
r ฺ
mi denull, nt :window);
exec dbms_auto_task_admin.enable( -
p ฺ
'auto optimizer stats collection',
g Stu-
d
b a@ null,
'auto space advisor', t h is :window);
exec dbms_auto_task_admin.enable(
i
i a (ja use
FIN! A
b to
i o
nton
e A date
./run_workload_stream.sh
[oracle@edrsr33p1-orcl Automatic_SQL_Tuning]$
./run_workload_stream.sh
Tue Mar 18 15:46:42 GMT-7 2008
Connected to:
no rows selected
SQL>
no rows selected
SQL>
no rows selected
...
n s e
SQL>
i ce
no rows selected
b l el
SQL>
fer a
no rows selected
a n s
o n -tr
an
SQL>
no rows selected
h s ฺ
a 11gdeEnterprise
)
s Gu
SQL> SQL> Disconnected from Oracle Database
Release 11.1.0.6.0 - Production rฺe
i Edition
ntocd
e A
J o s export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin
date
set echo on
FIN!
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
date
./create_snapshot.sh
n s e
ce
Copyright (c) 1982, 2007, Oracle. All rights reserved.
eli
a b l
Connected to:
fe r
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 -
a n s
Production
o n -tr
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
s an
) h a deฺ
SQL> SQL> SQL> SQL>
r
PL/SQL procedure successfully completed.ฺ e s Gui
p ฺ mi Database
Oracle d e nt 11g Enterprise Edition
SQL> SQL> Disconnected from
d g Stu
a@ Oracle
Release 11.1.0.6.0 - Production
b i
With the Partitioning,
t h is Label Security, OLAP, Data Mining
( j a
and Real Application
s eAutomatic_SQL_Tuning]$
Testing options
bia to
[oracle@edrsr33p1-orcl u
io A
t o n
--------------------------------------------------------------
A n
o s e #!/bin/bash
J cd /home/oracle/solutions/Automatic_SQL_Tuning
export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
set echo on
exec dbms_workload_repository.create_snapshot;
FIN!
You can also use the report_auto_tuning_task API to get reports that span
multiple executions of the task.
./get_task_report.sh
d g Stu
3a@4 is STATUS
EXECUTION_NAMEabi
SQL> SQL> 2
j e t h EXECUTION_START
(
a to u s
EXEC_1 bi
------------------------------ ----------- -------------------
SQL> SQL>
OBJ_ID
----------
3
--------------------------------------------------------------------
-----------
Object ID : 3
Schema Name: AST
SQL ID : by9m5m597zh19
n s e
SQL Text : select /*+ USE_NL(s c) FULL(s) FULL(c) AST */
i ce
c.cust_id,
b l el
where
sum(s.quantity_sold) from sh.sales s, sh.customers c
fe ra
n
s.cust_id = c.cust_id and c.cust_id < 2 group by
a s
c.cust_id
o n -tr
an
--------------------------------------------------------------------
s
-----------
) h a deฺ
FINDINGS SECTION (2 findings)
r ฺ e s Gui
mi dent
--------------------------------------------------------------------
-----------
p ฺ
g explain
d S tu plans section below)
1- SQL Profile Finding
b i a@ this
(see
--------------------------------------------------------
i a (ja"SYS_SQLPROF_01463043cc730000"
A potentially better
u seexecution plan was found for this statement.
A b
SQL profile
to was created
o statement.
ithis
automatically
n
for
nt o
e A
J o s Recommendation (estimated benefit: 98.62%)
------------------------------------------
- An automatically-created SQL profile is present on the system.
Name: SYS_SQLPROF_01463043cc730000
Status: ENABLED
Validation results
------------------
The SQL profile was tested by executing both its plan and the
original plan
and measuring their respective execution statistics. A plan may
have been
only partially executed if the other could be run to completion in
less time.
98.61%
Disk Reads: 0 0
Direct Writes: 0 0
Rows Processed: 0 0
Fetches: 0 0
Executions: 1 1
an
schema design
or creating the recommended index.
h s
a deฺ
create index SH.IDX$$_00010001 on SH.SALES("CUST_ID");
e )
s Gui
Rationale r ฺ
i ent
---------
p ฺ m d significantly improves the
d g
Creating the recommended
t u
indices
S
execution plan
b i a@ However,
of this statement. t h is it might be preferable to run
"Access Advisor"
a ja use
(representative
usingi
b This to
a SQL workload as opposed to a single
A
iowill allow to get comprehensive index recommendations which
statement.
o n
t takes into
A n
o s e account index maintenance overhead and additional space
J consumption.
--------------------------------------------------------------------
-----------
EXPLAIN PLANS SECTION
--------------------------------------------------------------------
-----------
--------------------------------------------------------------------
------------
-------------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time
| Pstart| Pstop |
--------------------------------------------------------------------
------------
1 | | |
| 2 | NESTED LOOPS | | 1 | 13 | 901
(2)| 00:00:1
1 | | |
|* 3 | TABLE ACCESS FULL | CUSTOMERS | 1 | 5 | 405
(1)| 00:00:0
5 | | |
| 4 | PARTITION RANGE ALL| | 1 | 8 | 495
(3)| 00:00:0
6 | 1 | 28 |
n s e
|* 5 | TABLE ACCESS FULL | SALES | 1 | 8 | 495
i ce
(3)| 00:00:0
b l el
6 | 1 | 28 |
fer a
--------------------------------------------------------------------
------------
a n s
-------------------
o n -tr
Predicate Information (identified by operation
s a nid):
h a deฺ
---------------------------------------------------
)
3 - filter("C"."CUST_ID"<2) rฺe
s Gui
5 - filter("S"."CUST_ID"<2 ฺ i "S"."CUST_ID"="C"."CUST_ID")
mAND e nt
p
g Stu d
2- Using SQL Profile@d
b i
-------------------- a t h is
i a (ja 3070788227
Plan hash value:
u se
A b to
i o
--------------------------------------------------------------------
n
nto------------
e A ---------------------------------------
J o s | Id | Operation
| Bytes |
| Name | Rows
n s e
6 - access("S"."CUST_ID"<2)
i ce
filter("S"."CUST_ID"<2)
b l el
7 - access("S"."CUST_ID"="C"."CUST_ID")
filter("C"."CUST_ID"<2)
fer a
a n s
3- Using New Indices
o n -tr
an
--------------------
Plan hash value: 1871796534
h s
a deฺ
)
s Gui
--------------------------------------------------------------------
e
------------ r ฺ
i ent
ฺ m
---------------------------------------
p d
| Id | Operation
d g S t u | Name | Rows
| Bytes |
Cost (%CPU)| Time b i a@| Pstart|
t h is Pstop |
i a (ja use
--------------------------------------------------------------------
b
------------
A to
i o
---------------------------------------
e A |
J o s |
5 (0)| 00:00:01 |
1 | SORT GROUP BY NOSORT
| |
| |
1 | 13 |
5 (0)| 00:00:01 | | |
| 2 | NESTED LOOPS | |
| |
| | | |
| 3 | NESTED LOOPS | |
1 | 13 |
5 (0)| 00:00:01 | | |
|* 4 | INDEX RANGE SCAN | CUSTOMERS_PK |
1 | 5 |
2 (0)| 00:00:01 | | |
|* 5 | INDEX RANGE SCAN | IDX$$_00010001 |
1 | |
2 (0)| 00:00:01 | | |
| 6 | TABLE ACCESS BY GLOBAL INDEX ROWID| SALES |
1 | 8 |
3 (0)| 00:00:01 | ROWID | ROWID |
--------------------------------------------------------------------
------------
4 - access("C"."CUST_ID"<2)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
5 - access("S"."CUST_ID"="C"."CUST_ID")
filter("S"."CUST_ID"<2)
--------------------------------------------------------------------
-----------
i a (ja use
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
A to <<FIN!
b/ as sysdba
o
ni echo on
sqlplus
ntoset
e A
J o s set long 1000000000
set longchunksize 1000
--
-- Check the execution names
--
alter session set nls_date_format = 'MM/DD/YYYY HH24:MI:SS';
begin
select max(execution_name) keep (dense_rank last order by
execution_start)
into :last_exec
from dba_advisor_executions
where task_name = 'SYS_AUTO_SQL_TUNING_TASK';
print :last_exec
--
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
begin
select object_id
into :obj_id
from dba_advisor_objects
where task_name = 'SYS_AUTO_SQL_TUNING_TASK' and
n s e
execution_name = :last_exec and
i ce
type = 'SQL' and
b l el
end;
attr1 = 'by9m5m597zh19';
fe r a
/
a n s
o n -tr
an
print :obj_id
--
h s eฺ
a onedquery
-- Get a text report to drill down on) this i
--
i r ฺ es t Gu
set pagesize 0
g p ฺm uden
d 'TEXT', t 'TYPICAL', 'ALL', :obj_id)
select dbms_sqltune.report_auto_tuning_task(
S
@ s
thi
:last_exec, :last_exec,
from dual;
a b ia
j e
FIN! b ia ( to us
n i o A how to configure Automatic SQL Tuning using Enterprise Manager.
8) Investigate
to
e An a) Back in EM, go to the Automated Maintenance Tasks page.
Jos b) The chart here shows times in the past when each client was executed, and times
in the future when they are scheduled to run again.
c) Modify the graph’s begin and end points with the widgets at the upper right.
d) Click the Configure button.
e) This brings you to the Automated Maintenance Tasks Configuration page.
f) From this page, you can disable individual clients and change which windows
they run in.
g) Disable the Automatic SQL Tuning client entirely, click Apply, and then click the
locator link to return to the last page.
h) Note that no light blue bars appear for Automatic SQL Tuning in the future.
i) Return to the configuration page, enable the task again, and click Apply to undo
your changes.
l) Note that there are more fine-grained controls here, such as one that allows the
task to run but not implement profiles, and one that allows you to control the
maximum number of profiles created per run.
9) Investigate how to configure Automatic SQL Tuning using PL/SQL. From your
terminal session, execute the manual_config.sh script. What does it do?
a) Note the first action. You changed the total time limit for the task. Instead of
running for an unlimited amount of time (still bound by the maintenance window
boundaries), it now runs for a maximum of one hour. The n s e
i ce
execute_tuning_task API call runs the task immediately, in the foreground.
Use this to run the task yourself whenever you want. b l el
fe r a
a n s
./manual_config.sh
o n -tr
an
--------------------------------------------------------------
s
) h a deฺ
#!/bin/bash
r ฺ e s Gui
p ฺ mi dent
cd /home/oracle/solutions/Automatic_SQL_Tuning
d g Stu
b i a@ this
export ORACLE_SID=orcl
i a (ja use
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
A b to
ni o
export
ntoPATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
e A l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
connect / as sysdba
set echo on
--
-- Configure the task to run for at most 30 minutes. The value of
the
-- TIME_LIMIT parameter determines the total time allowed for a task
execution.
--
select parameter_value
from dba_advisor_parameters
where task_name = 'SYS_AUTO_SQL_TUNING_TASK' and
parameter_name = 'TIME_LIMIT';
exec dbms_sqltune.set_tuning_task_parameter( -
'SYS_AUTO_SQL_TUNING_TASK', 'TIME_LIMIT', 1800);
--
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
exec dbms_sqltune.execute_tuning_task('SYS_AUTO_SQL_TUNING_TASK');
FIN!
10) Note: In your case, the task executes quickly because the workload to take into
account is really small. However, you could use the interrupt_task.sh script
from another session to stop the task, should it last too long. n s e
i ce
[oracle@edrsr33p1-orcl Automatic_SQL_Tuning]$ cat interrupt_task.sh
b l el
#!/bin/bash
fe r a
a n s
-tr
cd /home/oracle/solutions/Automatic_SQL_Tuning
o n
an
export ORACLE_SID=orcl
s
a deฺ
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
h
e )
s Gui
export
r ฺ
ฺ mi dent
PATH=/u01/app/oracle/product/11.1.0/db_1/bin:/bin:/usr/bin:/usr/loca
p
g Stu
l/bin:/usr/X11R6/bin:/usr/java/jdk1.5.0_11/bin
d
sqlplus / as sysdba
b i a@
<<FIN! is
th
a
connect / as(jsysdbause
A biona to
setoecho
ni
to--
A n
o s e -- Interrupt the task
J --
exec dbms_sqltune.interrupt_tuning_task('SYS_AUTO_SQL_TUNING_TASK');
FIN!
[oracle@edrsr33p1-orcl Automatic_SQL_Tuning]$
11) Ensure that you disable automatic implementation of SQL profiles to clean up your
environment.
o s e
n A
t o n
Aio
b i a
b i
to
(ja use
d p ฺ
a@ this
r ฺ
g Stu
e ) h
mi dent
s
s Gui
an
o
a deฺ
tr n -
a n s fe
r
a b l el
i
ce n s e
J
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
o s e
n A
t o n
Aio
b i a
b i
to
(ja use
d p ฺ
a@ this
r ฺ
g Stu
e ) h
mi dent
s
s Gui
an
o
a deฺ
tr n -
a n s fe
r
a b l
Index
i el
ce n s e
A
Access path 3-16, 3-17, 3-19, 3-23, 3-24, 3-28, 3-32, 4-2, 4-3,
4-4, 4-6, 4-8, 4-10, 4-14, 4-17, 4-29, 4-31, 4-33, 4-43, 4-47,
4-56, 4-71, 4-72, 5-49, 6-8, 6-14, 9-2, 9-9, 9-10, 9-11, 9-12,
9-13, 9-14, 9-17, 9-30, 11-5, 11-7, 11-10, 11-15
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2010, Oracle and/or its affiliatesฺ
Action 1-11, 1-12, 1-22, 1-23, 2-7, 2-9, 2-13, 2-14, 2-15, 2-17,
2-18, 2-19, 3-3, 3-12, 3-25, 3-30, 4-3, 4-6, 4-30, 4-70, 6-14,
7-20, 7-22, 7-32, 8-8, 10-4, 10-8, 10-9, 10-10, 10-13, 10-14, 11-3,
11-15, 11-21, 11-24, 11-25
Adaptive Cursor Sharing 8-2, 8-12, 8-13, 8-14, 8-15, 8-16, 8-17,
8-18, 8-19, 8-20, 8-21 n s e
i ce
ADDM 2-6, 2-8, 2-9, 2-10, 2-11, 2-14, 2-15, 5-27, 5-28, 11-4,
b l el
11-9, 11-12, 11-14, 11-26, 11-38 fer a
a n s
ADR 10-5, 10-14, 10-15
o n -tr
AGGREGATE 1-6, 1-17, 1-18, 2-19, 3-5, 3-20, 3-21, 3-29,n3-30,
4-20, 4-27, 4-30, 4-31, 4-48, 4-52, 4-53, 5-26, a s a5-47,
5-38, eฺ 6-10,
)h id
10-19, 10-25, 10-28, 10-29
i r ฺes nt Gu
ALL_ROWS 3-32, 3-33, 5-14, 9-4, 9-8,
g p ฺm9-10,ud10-26,
e 10-28, 10-29,
d t
11-7 @
ia
b 4-12, sS
hi
t4-20, 4-24, 4-27, 4-37, 4-38,
ALTER 1-8, 3-3, 3-11,
( j a3-28, s e
4-50, 5-11,b ia 5-44,
5-25, t o u7-8, 7-22, 7-26, 8-11, 8-12, 9-10, 10-12,
n
11-11 i oA
n to
A
eALTER SESSION 3-3, 5-44, 8-11, 8-12, 9-10, 10-12
Jos ALTER SYSTEM 3-3, 7-22, 8-11
AND-EQUAL 4-25
Anti Join 4-61, 4-65
APPEND 2-20, 4-68, 9-23
Architecture 1-1, 1-2, 1-3, 1-12, 1-19, 1-20, 8-14, 8-15
Ascending 4-10, 4-11, 4-15, 4-16, 4-17, 9-12, 9-14
ASH 1-14, 1-17, 1-19, 2-6, 2-8, 2-9, 3-27, 3-28, 3-30, 4-4,
4-5, 4-11, 4-24, 4-44, 4-45, 4-46, 4-47, 4-48, 4-51, 4-54, 4-58,
4-59, 4-62, 4-63, 4-64, 4-65, 4-67, 4-70, 5-11, 5-12, 5-14, 5-20,
5-21, 5-22, 5-23, 5-24, 5-25, 5-26, 5-27, 5-30, 5-32, 5-37, 5-44,
5-47, 5-49, 6-6, 6-12, 6-13, 6-16, 8-3, 9-11, 9-22, 9-29, 11-18,
11-26
5-24, 5-25, 5-26, 5-27, 5-35, 5-36, 5-37, 5-38, 5-39, 5-44, 5-45,
5-46, 6-7, 6-10, 6-14, 7-16, 7-19, 7-26, 7-33, 8-3, 8-8, 8-10,
9-3, 9-7, 9-10, 9-11, 9-14, 9-15, 9-20, 9-21, 9-22, 9-23, 9-24,
9-28, 9-30, 9-31, 10-17, 10-27, 11-3, 11-5, 11-7, 11-16, 11-17, 11-18,
11-27, 11-28, 11-29, 11-30, 11-31, 11-33, 11-37
AUDIT 3-3 n s e
lice
Automatic 1-8, 1-14, 1-15, 1-16, 1-17, 1-18, 1-24, 2-6, 2-7,
a b le
2-8, 2-10, 2-11, 2-12, 2-15, 2-20, 3-30, 3-33, 4-10, 5-7, 5-10, fer
s
5-15, 5-27, 5-28, 5-29, 5-30, 5-35, 6-7, 6-10, 7-3, 7-4, 7-13, tran
o n -
a n
7-15, 7-21, 7-24, 7-25, 7-26, 7-27, 7-34, 7-36, 8-12, 8-13, 8-16,
8-19, 10-6, 10-8, 11-2, 11-3, 11-4, 11-5, 11-6, a s eฺ 11-11,
11-7, 11-8,
)h id
i r ฺes 11-30,
11-12, 11-15, 11-26, 11-27, 11-28, 11-29,
t G u 11-32, 11-33, 11-34,
11-31,
11-35, 11-36, 11-37, 11-38
g p ฺm uden
St 11-30, 11-31, 11-32,
@d11-27,s 11-28,
Automatic SQL tuning 2-6, 11-2,
11-33, 11-34, 11-35,j
ia
ab11-36, e hi
t 11-38
11-37,
(
iaOptimizer s
u11-3, 11-5, 11-6, 11-7
Automatic Tuningb t o
n
AUTOTRACE i o A5-4, 5-6, 5-15, 5-16, 5-17, 5-18, 5-19, 9-15, 10-25
n to
A
eAWR 2-6, 2-8, 2-9, 2-12, 5-4, 5-6, 5-21, 5-27, 5-28, 5-29,
Jos 5-30, 5-31, 5-32, 5-33, 5-34, 11-12, 11-14, 11-27, 11-32
awrsqrpt 2-8, 5-34
B
B*tree 3-19, 4-10, 4-11, 4-12, 4-18, 4-26, 4-27, 4-30, 4-46, 7-4,
7-8
background process 1-2, 1-3, 1-4, 1-6, 1-8, 1-15, 1-18, 1-20,
1-25, 10-12
BIND 2-14, 2-16, 2-22, 2-23, 2-24, 2-25, 3-6, 3-7, 3-11, 3-12,
3-13, 4-23, 5-14, 5-15, 6-8, 8-1, 8-2, 8-4, 8-5, 8-6, 8-7,
8-8, 8-11, 8-12, 8-13, 8-14, 8-15, 8-16, 8-17, 8-18, 8-19, 8-20,
8-21, 9-24, 10-10, 10-11, 10-12, 10-15, 10-16, 10-17, 11-12
bind peeking 5-15, 8-2, 8-13, 8-14, 8-20, 8-21
g ฺm 9-27,
2-25, 3-3, 3-5, 3-21, 4-12, 5-10,p5-15,
u d en10-6, 10-7, 10-8,
t
10-20 @d s S
ia hi
j ab 2-14,
Connection 1-4, 1-5, (2-13, e t 2-25, 10-6, 10-7, 10-8
2-22,
ia 2-20, s
u3-20, 4-10, 4-14, 4-20, 4-27, 4-35,
Constraint 2-18,
A b 2-19, t o
n
4-39,i o4-40, 7-7, 11-3
n to
A file 1-15, 1-19
econtrol
Jos CONTROL_MANAGEMENT_PACK_ACCESS 5-35, 9-25
Cost 1-14, 2-3, 2-4, 3-16, 3-18, 3-19, 3-24, 3-26, 3-27, 3-28,
3-30, 3-32, 3-33, 3-34, 4-4, 4-5, 4-7, 4-8, 4-9, 4-11, 4-14,
4-15, 4-16, 4-17, 4-18, 4-19, 4-20, 4-23, 4-25, 4-26, 4-29, 4-31,
4-34, 4-39, 4-40, 4-45, 4-46, 4-47, 4-49, 4-50, 4-51, 4-52, 4-53,
4-54, 4-55, 4-58, 4-59, 4-60, 4-64, 5-3, 5-11, 5-12, 5-14, 5-25,
5-32, 5-38, 6-3, 6-7, 6-12, 6-14, 6-17, 7-3, 7-5, 7-6, 7-8,
7-9, 7-16, 7-20, 7-31, 7-32, 9-8, 9-10, 9-12, 9-15, 9-17, 9-19,
9-24, 9-25, 9-29, 10-17, 11-7, 11-16, 11-17, 11-21, 11-22, 11-25, 11-30
COUNT STOPKEY 4-52
CREATE 1-4, 1-5, 1-6, 1-8, 1-14, 1-21, 1-22, 1-24, 2-11, 2-19,
2-20, 2-24, 3-3, 3-5, 3-7, 3-8, 3-9, 3-11, 3-18, 3-21, 3-22,
3-30, 4-6, 4-10, 4-14, 4-15, 4-16, 4-17, 4-18, 4-19, 4-20, 4-23,
4-24, 4-26, 4-27, 4-28, 4-29, 4-35, 4-36, 4-38, 4-39, 4-40, 4-41,
4-44, 4-45, 4-46, 4-47, 4-51, 4-67, 5-7, 5-10, 5-15, 5-29, 5-33,
6-7, 6-14, 6-15, 6-18, 6-19, 6-20, 6-21, 7-4, 7-11, 7-13, 7-15, n s e
lice
7-16, 7-17, 7-18, 7-19, 7-21, 7-26, 7-29, 9-28, 10-7, 10-8, 10-10,
a b le
fer
10-20, 10-27, 10-29, 10-31, 11-5, 11-7, 11-8, 11-9, 11-10, 11-12, 11-14,
s
11-15, 11-16, 11-21, 11-25, 11-27, 11-28, 11-29, 11-36
- t r an
Cube 8-14, 8-15, 8-16 n on
s a3-12,
Cursor 1-14, 2-14, 2-16, 2-22, 2-23, 2-24, 2-25, 3-7,a3-8, eฺ
)h
es 5-24,
3-13, 3-29, 5-4, 5-6, 5-20, 5-21, 5-22, ฺ5-23,
id
u 5-26,
5-25,
i r t G
5-32, 5-44, 7-26, 8-2, 8-3, 8-4, p
g 8-8, en 8-11, 8-12,
ฺm8-9,ud8-10,
St 8-20, 8-21, 9-24, 10-16,
@d 8-18,s 8-19,
8-13, 8-14, 8-15, 8-16, 8-17,
10-17, 10-27, 11-12, j
ia
ab11-29 e thi
(
ia 2-25, s
u 8-2, 8-3, 8-4, 8-8, 8-9,
Cursor Sharing A b2-16, t o 3-29,
n
8-10, i o8-12, 8-13, 8-14, 8-15, 8-16, 8-17, 8-18, 8-19, 8-20, 8-21
n to
A
eCURSOR_SHARING 2-24, 3-29, 8-11, 8-12, 8-19, 8-21, 9-24, 11-29
Jos CURSOR_SHARING_EXACT 8-11, 9-24
D
Data block 1-7, 1-22, 1-23, 2-15, 4-4, 4-7, 4-12, 4-21, 4-44,
4-47, 4-49, 4-56, 5-18, 7-5, 7-6, 7-7, 7-28, 10-25, 10-29
Data dictionary cache 1-9, 3-5, 10-26
data file 1-7, 1-10, 1-11, 1-15, 1-19, 1-21, 1-23, 10-25
Database writer 1-7, 1-10, 1-15
DB_FILE_MULTIBLOCK_READ_COUNT 3-29, 4-5, 4-6, 4-20, 7-5
DBA_HIST_ACTIVE_SESS_HISTORY 5-31
DBA_HIST_BASELINE DBA_HIST_DATABASE_INSTANCE 5-31
DBA_HIST_SNAPSHOT 5-29, 5-30, 5-31
DBA_HIST_SQL_PLAN 5-4, 5-31
DBA_TABLES 3-25
DBMS_APPICATION_INFO 10-4
DBMS_MONITOR 5-4, 10-4, 10-10, 10-11, 10-12, 10-13, 10-15
DBMS_SERVICE 10-4
DBMS_SESSION 10-4, 10-8, 10-10, 10-12, 10-15
DBMS_SQLTUNE 5-35, 5-37, 11-7, 11-30 n s e
i ce
DBMS_STATS 2-15, 7-3, 7-13, 7-15, 7-17, 7-18, 7-19, 7-20, 7-22,
b l el
7-23, 7-24, 7-25, 7-26, 7-28, 7-29, 7-30, 7-34, 11-6 fe ra
n s
DBMS_WORKLOAD_REPOSITORY 5-28, 5-29, 5-30, 5-33, 11-32
n - tra
DBMS_XPLAN 5-6, 5-11, 5-12, 5-14, 5-25, 5-32, 5-33, 5-34,
a no5-44,
9-29
h a s eฺ
DECLARE 3-3, 4-26, 7-16 e s ) u id
ฺ
ir 3-26, n G
t3-34,
DEFINE 1-19, 3-3, 3-6, 3-7, 3-10, 3-12, ฺ m3-22, e 4-10,
d gp Stud
4-18, 4-27, 4-29, 4-44, 4-54,
b i a@ 4-55,
t h is 6-2, 6-22, 7-5, 7-19, 7-20,
i a (ja 10-5,
8-5, 8-6, 9-24, 9-26,
u se10-7, 10-9, 10-10, 11-20, 11-31, 11-32
DELETE 1-8,A 1-19, to 3-12, 4-5, 4-18, 5-3, 5-15, 5-36,
b 3-3, 3-11,
o
ni 7-26, 7-28, 7-33, 7-34, 8-15, 9-5, 9-6, 9-28, 10-20, 10-25,
7-25,
t o
e An10-29
J os Descending 4-10, 4-11, 4-13, 4-15, 4-16, 4-17, 9-12, 9-13, 10-19
DESCRIBE 1-2, 1-25, 2-2, 2-26, 3-2, 3-3, 3-6, 3-7, 3-10,
3-35, 3-36, 4-16, 6-10, 6-11, 7-3, 7-26, 7-27, 9-21, 10-5, 11-19
DIAGNOSTIC_DEST 10-5
Dimension 2-12, 4-61, 6-3, 6-4, 6-6, 6-7, 6-8, 6-9, 6-10,
6-11, 6-12, 6-13, 6-14, 6-15, 6-16, 6-17, 6-18, 6-20, 6-21, 10-6,
11-17, 11-21
Dispatcher 1-4, 1-5
Domain 4-10, 4-11, 9-12, 9-14
DRIVING_SITE 9-22
DROP 1-8, 3-3, 4-10, 4-27, 4-37, 4-38, 4-39, 4-40, 5-10, 5-29,
5-30, 10-20, 10-27, 11-16, 11-17
9-25
E
Equi 1-7, 1-16, 1-17, 2-2, 2-5, 2-6, 2-7, 2-8, 2-14, 2-15,
2-17, 2-18, 2-19, 2-20, 2-23, 2-25, 3-7, 3-10, 3-18, 3-19, 3-20,
3-21, 3-22, 3-23, 4-7, 4-10, 4-28, 4-30, 4-35, 4-36, 4-39, 4-40,
n s e
4-48, 4-56, 4-58, 4-59, 4-61, 4-62, 4-65, 5-3, 5-15, 5-18, 5-19,
lice
5-24, 5-34, 6-2, 6-4, 6-7, 6-19, 6-20, 6-22, 7-5, 7-6, 7-11,
a b le
7-17, 7-25, 7-27, 9-13, 9-24, 9-26, 10-20, 10-25, 10-28, 10-29, 11-4, s f er
11-8, 11-11, 11-16, 11-22, 11-27, 11-29 - t r an
Estimator 3-24, 3-25, 3-26, 3-27, 7-11 n on
s a
EXECUTE 1-10, 2-14, 2-15, 2-23, 2-25, 3-3, 3-4, h 3-6, 3-7, eฺ
a
e s ) u id
3-8, 3-9, 3-12, 3-13, 3-14, 3-19, 3-20, i r ฺ
3-24,
n t G
3-27, 4-11, 4-18,
4-50, 4-51, 4-58, 4-69, 4-70, g 5-4,
m
pฺ 5-7,t5-9, de5-10, 5-11, 5-18,
d u
S 5-41, 5-42, 5-43, 5-45,
5-20, 5-25, 5-26, 5-32, i a @ 5-38,
5-35, i s 5-40,
j ab 7-23, e th
5-46, 5-47, 5-48,( 7-22,
ia 9-11, u s 7-32, 8-4, 8-7, 8-8, 8-9, 8-10,
A
8-11, 8-14,b8-15, t o 9-22, 9-24, 9-26, 10-10, 10-16, 10-17, 10-24,
i o
ton 10-26, 10-27, 10-28, 10-29, 11-7, 11-30, 11-32, 11-36
10-25,
e An plan 2-3, 2-10, 2-11, 2-13, 2-15, 2-20, 2-21, 2-22,
Execution
J os 3-16, 3-17, 3-18, 3-19, 3-20, 3-24, 3-26, 3-28, 3-32, 3-33, 4-2,
4-14, 4-16, 4-50, 4-55, 4-56, 4-59, 4-70, 5-1, 5-2, 5-3, 5-4,
5-5, 5-6, 5-7, 5-8, 5-9, 5-10, 5-11, 5-14, 5-15, 5-16, 5-17,
5-20, 5-24, 5-25, 5-31, 5-32, 5-33, 5-38, 5-39, 5-40, 5-41, 5-42,
5-43, 5-44, 5-45, 5-46, 5-47, 5-48, 5-49, 5-50, 5-51, 5-52, 6-3,
6-6, 6-14, 7-3, 7-31, 7-35, 8-3, 8-4, 8-9, 8-10, 8-13, 8-14,
8-15, 8-18, 9-3, 9-7, 9-8, 9-10, 9-14, 9-15, 9-16, 9-20, 9-22,
9-24, 9-26, 9-29, 9-30, 9-32, 10-16, 10-17, 10-20, 10-23, 10-26, 10-27,
10-30, 11-3, 11-4, 11-6, 11-26, 11-29, 11-30
Expansion 3-18, 3-19, 4-68, 9-17
4-67, 4-69, 4-70, 5-11, 5-12, 5-14, 5-25, 5-28, 5-30, 5-32, 5-33,
5-38, 5-39, 5-42, 5-44, 5-47, 5-49, 6-6, 6-13, 6-14, 6-16, 7-6,
7-8, 7-34, 8-5, 8-8, 8-10, 8-18, 9-7, 9-11, 9-12, 9-14, 9-19,
9-22, 9-24, 9-27, 9-29, 9-30, 10-17, 10-27, 10-28, 11-10, 11-18, 11-25,
11-27
Full Table Scan 2-14, 2-15, 3-17, 3-19, 3-29, 3-30, 3-32, 4-4, n s e
lice
4-5, 4-6, 4-9, 4-20, 4-45, 5-42, 5-44, 5-49, 6-14, 7-6, 7-8,
a b le
8-8, 8-18, 9-11, 9-12, 9-14, 9-22, 9-24, 9-29, 10-28, 11-10 fer
s
Function based 2-4, 4-10, 4-41
- t r an
no Function-based 4-6, 4-11, 4-17, 4-18, 7-19, 9-14
n
a
s eฺ
G h a
e s ) u id
ฺ
ir ent G
Gather 2-11, 4-11, 5-2, 5-3, 5-10, 5-22, 5-26, 5-51, 6-7, 7-2,
ฺ m
gp 7-15,
7-3, 7-4, 7-5, 7-6, 7-9, 7-11, 7-13,
d S tud7-17, 7-19, 7-20,
7-21, 7-22, 7-23, 7-24,i @ 7-26,
a7-25, h is 7-27, 7-28, 7-29, 7-30, 7-31,
b
a 11-28, t
7-34, 7-36, 11-5,
i a (j11-6, u se 11-29
A
Generator 3-24,b3-28 to
o
ni 1-6, 1-14, 1-22, 5-7, 5-10, 5-37, 7-25, 7-26, 9-28,
Global
t o1-3,
e An10-10, 10-11, 11-10, 11-18, 11-30
Jos GRANT 2-25, 3-3, 3-34, 5-15, 5-29
GROUP BY 2-4, 3-21, 3-25, 3-26, 4-15, 4-48, 4-51, 4-67, 4-70,
6-5, 6-6, 6-13, 6-16, 9-18, 9-22, 9-30
H
Hard parse 2-23, 3-14, 3-18, 8-7, 8-13, 8-14, 8-15, 10-23
HASH 1-14, 1-17, 3-27, 3-28, 3-30, 4-4, 4-5, 4-24, 4-44, 4-45,
4-46, 4-47, 4-48, 4-51, 4-54, 4-58, 4-59, 4-62, 4-63, 4-64, 4-65,
4-67, 4-70, 5-11, 5-12, 5-14, 5-20, 5-21, 5-22, 5-23, 5-24, 5-25,
5-26, 5-32, 5-37, 5-44, 5-47, 5-49, 6-6, 6-12, 6-13, 6-16, 8-3,
9-11, 9-22, 9-29, 11-18
Hash Cluster 4-4, 4-44, 4-45, 4-46, 4-47
7-8, 7-24
Library cache 1-9, 1-10, 1-11, 3-5, 3-9, 3-14, 5-4, 5-20,
5-23, 5-24, 8-3, 8-4, 10-16, 10-23, 10-26, 10-28, 10-29
Listener 1-4, 1-5, 10-6
Literal 2-4, 2-5, 2-23, 2-25, 3-29, 8-3, 8-4, 8-7, 8-9,
8-11, 8-12, 8-13, 8-18, 8-19, 9-24 n s e
i ce
Lock 1-6, 1-7, 1-9, 1-10, 1-21, 1-22, 1-23, 2-9, 2-13, 2-15,
b l el
3-12, 3-15, 3-18, 3-21, 3-22, 3-24, 3-27, 3-28, 3-29, 3-30, 3-32, fer a
a n s
4-4, 4-5, 4-6, 4-7, 4-8, 4-9, 4-11, 4-12, 4-13, 4-19, 4-20,
o n -tr
n 4-52,
4-21, 4-22, 4-28, 4-30, 4-44, 4-45, 4-46, 4-47, 4-49, 4-51,
a
as7-6, 7-7,
4-56, 4-57, 5-3, 5-12, 5-18, 5-19, 5-48, 7-4, 7-5,
)h eฺ
es 7-34,
7-8, 7-9, 7-24, 7-25, 7-28, 7-30, 7-32, ฺ7-33,
id
u 9-5,
9-4,
i r t G
9-6, 9-10, 9-17, 9-18, 9-24, 9-26,
g p ฺm
9-27, 9-28,
u d en9-29, 10-4, 10-25,
t
10-29 @d s S
Locking Statistics 7-34j abia
e thi
( us
Lookup table A bia9-24 to
6-3,
nio
M
n t o
e A
Materialized view 2-3, 2-10, 2-19, 9-17, 11-16, 11-17, 11-18
Jo s
Measures 3-24, 6-3
MERGE 1-14, 3-3, 3-11, 3-21, 3-22, 3-28, 3-30, 3-34, 4-25, 4-34,
4-48, 4-49, 4-51, 4-52, 4-54, 4-58, 4-60, 4-64, 4-65, 4-69, 5-25,
6-8, 6-10, 6-11, 6-13, 6-16, 7-33, 8-14, 8-15, 9-5, 9-6, 9-12,
9-14, 9-16, 9-17, 9-18, 9-21, 9-22, 9-24, 9-26, 9-27, 9-30, 10-13
Min/Max 4-13, 4-53
MINUS 4-32, 4-34, 4-48, 4-66, 4-69, 9-5, 9-27
MMAN 1-15, 1-18, 4-12, 5-4, 5-6, 5-7, 5-8, 5-9, 5-11, 5-12,
5-16, 5-44, 7-22, 8-5, 8-11, 8-12, 10-2, 10-8, 10-10, 10-18, 10-19,
10-23, 10-24, 10-25, 10-26, 10-27, 10-29, 10-30, 11-4, 11-8, 11-16
MONITOR 1-3, 1-15, 2-6, 2-7, 2-8, 2-9, 2-10, 2-11, 5-4,
5-15, 5-19, 5-29, 5-35, 5-36, 5-37, 5-38, 5-39, 5-50, 5-52, 7-29,
8-17, 9-25, 10-4, 10-5, 10-8, 10-10, 10-11, 10-12, 10-13, 10-15, 10-29,
11-4, 11-26
Multicolumn Statistics 7-17, 7-18
n s e
N
lice
N-ary 4-3
a b le
Nested Loops 3-26, 3-32, 4-47, 4-54, 4-55, 4-56, 4-57, 4-62, 4-63, s f er
4-64, 4-65, 4-67, 5-3, 5-42, 5-43, 5-44, 5-45, 5-46, 7-5, 9-20,
- t r an
9-21 n on
s a
NO_EXPAND 9-17
) h a
i d eฺ
NO_FACT 6-17, 9-19 i r ฺes nt Gu
NO_INDEX 9-12, 9-14 g p ฺm ude
d S t
NO_MERGE 4-51, 4-52, 9-18 a @ i s
NO_MONITOR 5-35,(j9-25 abi se th
b ia to u
i o A
NO_QUERY_TRANSFORMATION 9-17
ton
NO_RESULT_CACHE 4-70, 9-25
e An
NO_USE_HASH 9-22
J os NO_USE_MERGE 9-22
NO_USE_NL 9-21
NOAPPEND 9-23
NOAUDIT 3-3
Non-equi 4-61, 4-62
NULL 3-13, 4-15, 4-19, 4-20, 4-24, 4-26, 4-27, 4-29, 4-30, 4-39,
4-41, 4-42, 4-63, 4-65, 4-68, 5-11, 5-12, 5-14, 5-25, 5-30, 5-32,
5-44, 7-4, 7-10, 7-17, 7-26, 7-27, 7-30, 7-34, 9-29
O
OPEN 1-19, 1-24, 2-14, 2-23, 3-3, 3-6, 3-8, 3-13, 4-63, 10-12,
11-15
OPT_PARAM 9-25
9-25
OPTIMIZER_FEATURES_ENABLED 3-32, 3-35
OPTIMIZER_INDEX_CACHING 3-32, 9-25
OPTIMIZER_INDEX_COST_ADJ 3-32, 9-25
OPTIMIZER_MODE 3-32, 3-33, 9-10
OPTIMIZER_USE_INVISIBLE_INDEXES 3-32, 3-34, 4-37, 4-38 n s e
i ce
OPTIMIZER_USE_PENDING_STATISTICS 3-32, 3-34
b l el
OPTIMIZER_USE_SQL_PLAN_BASELINES 3-32, 3-33 fer a
ORDER BY 4-15, 4-16, 4-17, 4-18, 4-19, 4-46, 4-48, 7-13, 7-15, tr a n s
o n -
9-30, 10-19
a n
s eฺ
ORDERED 3-12, 4-19, 4-20, 4-21, 4-23, 4-46, 4-48,a5-41, 5-47,
)h id
7-6, 9-20, 9-21, 9-23, 9-24, 11-21, 11-25
i r ฺes nt G u
ORDERED_PREDICATES 9-23, 9-24
g p ฺm ude
t
OS block 1-21 @d s S
Outer Join 4-61, 4-63(jab
ia
e thi
ia u s
P A b t o
i o
ton 1-3, 4-6, 7-26, 7-29, 7-30
parallelism
e An
PARALLELIZE 3-6, 3-7, 3-11, 4-40, 7-26
J os Parent 2-21, 3-20, 4-65, 5-3, 5-10, 5-23, 5-24, 5-40, 5-41, 5-43,
5-45, 5-46, 5-48, 9-5, 11-8
PARSE 1-10, 2-14, 2-23, 2-25, 3-5, 3-6, 3-7, 3-9, 3-13, 3-14,
3-15, 3-18, 5-23, 7-20, 8-4, 8-7, 8-8, 8-13, 8-14, 8-15, 10-16,
10-17, 10-18, 10-23, 10-24, 10-25, 10-26, 10-27, 10-28, 10-29
Partition 1-22, 2-3, 2-10, 2-19, 3-11, 4-3, 4-4, 5-3, 5-12,
6-8, 6-13, 7-26, 7-28, 7-30, 9-12, 9-13, 9-14, 11-16, 11-17, 11-18
Peeking 5-15, 8-2, 8-7, 8-8, 8-13, 8-14, 8-20, 8-21
PGA 1-6, 1-14, 1-15, 1-17, 1-18, 3-5, 3-29, 3-30, 4-49, 5-26,
6-10
PGA_AGGREGATE_TARGET 1-17, 3-29, 3-30, 5-26, 6-10
4-11, 4-14, 4-15, 4-16, 4-17, 4-18, 4-19, 4-20, 4-23, 4-24, 4-25,
4-26, 4-29, 4-30, 4-31, 4-32, 4-33, 4-34, 4-41, 4-49, 4-50, 4-51,
4-52, 4-53, 4-54, 4-55, 4-58, 4-59, 4-60, 4-61, 4-64, 4-67, 4-68,
5-11, 5-12, 5-14, 5-25, 5-42, 5-49, 6-6, 6-10, 6-14, 6-16, 7-3,
7-6, 7-10, 7-14, 7-16, 7-17, 7-18, 7-19, 7-24, 7-31, 7-32, 8-14,
8-15, 8-16, 9-15, 9-21, 9-23, 9-24, 9-26, 11-7, 11-11, 11-18 n s e
i ce
Preference 7-2, 7-25, 7-26, 7-35
b l el
PREPARE 3-3 fer a
Primary key 2-20, 3-15, 3-20, 4-11, 4-14, 4-27, 4-28, 4-29, 4-35, tra n s
o n -
4-40, 5-37, 5-46, 6-3, 6-9, 6-18, 7-7, 8-9
a n
h Private SQL area 3-4, 3-8, 3-14 a s eฺ
e s ) u id PUSH_PRED 9-24
ฺ
ir ent G
ฺ m PUSH_SUBQ 9-24
d gp Stud
Q
b i a@ this
(ja3-22,us3-24,
Query block 3-18, 3-21,
i a
e 3-28, 4-51, 5-12, 9-4, 9-17,
A
9-18, 9-26, to 9-29
b9-27, 9-28,
ni o
R n t o
e A
Jos
Range 3-25, 3-30, 3-32, 4-4, 4-5, 4-6, 4-8, 4-10, 4-13, 4-15,
4-16, 4-17, 4-18, 4-25, 4-26, 4-28, 4-31, 4-34, 4-36, 4-39, 4-49,
4-50, 4-53, 4-56, 4-57, 4-63, 4-65, 4-67, 4-68, 5-29, 5-30, 5-42,
5-44, 5-45, 6-13, 6-16, 7-8, 7-9, 7-10, 7-12, 7-14, 7-26, 8-8,
8-9, 8-10, 8-16, 8-18, 9-8, 9-12, 9-13, 9-14, 9-16, 9-29, 10-26,
10-29, 11-14, 11-18
Redo log buffer 1-6, 1-8, 1-10, 1-11
redo log file 1-8, 1-11, 1-15, 1-19, 2-15
RENAME 3-3, 5-10
Result cache 1-9, 1-15, 3-5, 3-30, 3-31, 4-70, 4-72, 9-25
Result Set 2-5, 4-54, 4-70, 5-44, 5-47, 6-7, 6-9, 6-11, 6-12,
6-14
RESULT_CACHE 3-29, 3-30, 3-31, 4-70, 9-25
4-29, 4-31, 4-32, 4-33, 4-36, 4-38, 4-39, 4-41, 4-47, 4-48, 4-49,
4-50, 4-51, 4-52, 4-53, 4-54, 4-55, 4-56, 4-57, 4-58, 4-59, 4-60,
4-62, 4-63, 4-64, 4-65, 4-67, 4-68, 4-70, 5-3, 5-6, 5-9, 5-10,
5-11, 5-12, 5-14, 5-15, 5-18, 5-25, 5-32, 5-33, 5-34, 5-37, 5-38,
5-42, 5-44, 5-45, 5-47, 5-48, 5-49, 6-5, 6-6, 6-9, 6-12, 6-14,
6-16, 6-18, 6-19, 6-20, 6-21, 7-3, 7-6, 7-8, 7-10, 7-11, 7-13, n s e
i ce
7-14, 7-15, 7-16, 7-17, 7-18, 7-19, 7-24, 7-31, 7-32, 7-34, 8-3,
b l el
8-4, 8-5, 8-7, 8-8, 8-9, 8-10, 8-12, 8-14, 8-15, 8-16, 8-18, fe r a
a
9-3, 9-5, 9-6, 9-8, 9-10, 9-11, 9-12, 9-13, 9-14, 9-15, 9-16, tr n s
o n -
a n
9-18, 9-20, 9-21, 9-22, 9-23, 9-24, 9-27, 9-28, 9-29, 9-30, 10-7,
10-12, 10-13, 10-15, 10-17, 10-20, 10-25, 10-28, s
a 10-29,eฺ11-7, 11-8, 11-12,
)h id
11-13, 11-14, 11-15, 11-19, 11-20, 11-24,
i r ฺes 11-25,
t G u 11-34, 11-36
11-33,
n 6-14,
Selectivity 2-3, 2-11, 3-24, 3-25, 3-26,
g p ฺm
4-3, 4-6,
u d e4-36,
d 7-17, t
7-3, 7-8, 7-10, 7-11, 7-14,
ia @7-16,
hi
t 11-7 s S 7-19, 7-24, 7-31, 7-32,
j ab 8-18,
8-8, 8-14, 8-15, (8-16, s e9-24,
Semi join 4-61, b ia to u
4-64
n io A1-4, 1-5, 1-6, 1-7, 1-8, 1-9, 1-10, 1-11,
serveroprocess
t
n1-12,
e A 3-11, 3-30, 10-3
Jos Service 1-4, 1-20, 2-8, 2-9, 5-31, 10-3, 10-4, 10-6, 10-7,
10-8, 10-9, 10-10, 10-13, 10-14, 10-31
SERVICE_NAME 10-7, 10-8, 10-14
SERVICE_NAMES 10-8
Session 1-4, 1-5, 1-6, 1-12, 1-13, 1-14, 1-17, 2-8, 2-9,
3-3, 3-30, 3-33, 4-37, 5-20, 5-21, 5-25, 5-27, 5-30, 5-31, 5-35,
5-36, 5-37, 5-38, 5-39, 5-44, 7-33, 8-5, 8-11, 8-12, 9-6, 9-10,
9-27, 10-2, 10-3, 10-4, 10-6, 10-8, 10-10, 10-11, 10-12, 10-13, 10-14,
10-15, 10-17, 10-18, 10-20, 10-30, 11-19, 11-20
SESSION_ID 10-8, 10-11, 10-14
SET ROLE 3-3
SET TRANSACTION 3-3
SQL tuning set 2-10, 5-4, 5-6, 11-12, 11-14, 11-17, 11-21, 11-32
Stale 2-3, 3-31, 7-3, 7-5, 7-6, 7-25, 7-26, 7-27, 11-5, 11-6,
11-28, 11-29
Star Join 4-61
star query 6-2, 6-3, 6-5, 6-7, 6-12, 6-14, 6-16, 6-17, 6-22
star schema 6-2, 6-3, 6-4, 6-6, 6-22 n s e
i ce
Star Transformation 3-18, 4-35, 6-1, 6-2, 6-5, 6-6, 6-7,
b l el
6-8, 6-9, 6-12, 6-13, 6-14, 6-15, 6-16, 6-17, 6-22, 6-23, 9-17, fer a
a n s
9-19
o n -tr
n 9-25
STAR_TRANSFORMATION 3-29, 3-30, 6-7, 6-17, 9-4, 9-19,
a
STAR_TRANSFORMATION_ENABLED 3-29, 3-30,a6-7, s 9-25eฺ
Statistics 1-16, 1-18, 2-3, 2-6, 2-7, 2-8, 2-9,ฺe
)h
s 2-15,
2-11,
id
u
i r t G
2-25, 3-16, 3-17, 3-18, 3-24, 3-25,
g p en 3-33, 3-34, 4-11,
ฺm3-26,ud3-32,
@d5-16,s5-17,
4-41, 4-42, 5-4, 5-13, 5-15, St 5-18, 5-19, 5-20, 5-22,
5-23, 5-24, 5-26, j
ia
ab 5-28,
5-27, e hi
t 5-31, 5-35, 5-37, 5-44, 5-48,
5-29,
( s
u 7-6, 7-7, 7-8, 7-9, 7-10,
6-7, 7-1,A bia7-3, 7-4,
7-2, to 7-5,
n
7-11,
o io7-12, 7-13, 7-15, 7-17, 7-18, 7-19, 7-20, 7-21, 7-22, 7-23,
t
e An7-24, 7-25, 7-26, 7-27, 7-28, 7-29, 7-30, 7-31, 7-34, 7-35, 7-36,
Jos 8-10, 8-11, 8-14, 8-15, 8-17, 8-18, 9-3, 9-10, 9-24, 10-2, 10-10,
10-16, 10-17, 10-18, 10-20, 10-23, 10-24, 10-25, 10-26, 10-28, 10-30, 11-5,
11-6, 11-7, 11-8, 11-9, 11-12, 11-14, 11-15, 11-24, 11-26, 11-28, 11-29,
11-32, 11-33
STATISTICS_LEVEL 1-16, 1-18, 5-22, 5-26, 5-35, 5-44, 7-27, 10-16,
11-32
STATS$SQL_PLAN 5-4
Streams pool 1-6, 1-13, 1-16, 1-18, 3-5
Suboptimal 2-3, 2-21, 7-11, 7-19, 8-8, 11-6
Subquery 2-4, 3-11, 3-18, 3-20, 4-61, 4-64, 4-65, 5-42, 6-8,
7-33, 9-5, 9-17, 9-18, 9-24, 9-27
SYSAUX 1-24, 5-5
4-49, 4-52, 4-57, 4-59, 4-63, 5-10, 5-17, 5-18, 5-27, 5-28, 5-31,
5-44, 5-46, 5-47, 6-9, 6-14, 7-2, 7-3, 7-4, 7-11, 7-13, 7-15,
7-20, 7-21, 7-22, 7-23, 7-24, 7-26, 7-27, 7-28, 7-29, 7-33, 7-35,
7-36, 8-8, 8-11, 8-12, 8-14, 8-15, 8-19, 9-3, 9-22, 9-24, 9-29,
10-6, 10-8, 10-9, 10-16, 10-20, 11-3, 11-6, 11-8, 11-9, 11-14, 11-17,
11-26, 11-34, 11-36 n s e
lice
System statistics 2-11, 7-2, 7-4, 7-20, 7-21, 7-22, 7-23, 7-27,
a b le
7-28, 7-35, 7-36, 9-24 fer s
T - t r an
n
no
Table 1-9, 1-21, 1-22, 1-23, 1-24, 2-3, 2-5, 2-14, 2-15, 2-16, a
2-17, 2-18, 2-19, 2-20, 2-21, 2-25, 3-10, 3-11, h a s eฺ 3-17,
3-12, 3-16,
e s ) u id
3-18, 3-19, 3-20, 3-21, 3-22, 3-25, 3-26,
i r ฺ 3-28,
n t G 3-30, 3-31,
3-29,
m
ฺ 4-7,ud4-8, e 4-9, 4-10,
3-32, 3-33, 3-35, 4-3, 4-4, 4-5,
d gp4-6, t
S 4-18, 4-19, 4-20, 4-21,
4-11, 4-12, 4-13, 4-14,i a @ 4-16,
4-15, i s 4-17,
j ab 4-27, e th
(
4-23, 4-24, 4-25, 4-26,
ia 4-37, u s 4-28, 4-29, 4-30, 4-31, 4-32, 4-33,
A b
4-34, 4-35, 4-36, t o 4-39, 4-40, 4-44, 4-45, 4-46, 4-47, 4-49,
i o
n ton 4-51, 4-52, 4-54, 4-55, 4-56, 4-57, 4-58, 4-59, 4-60, 4-61,
4-50,
e A 4-62, 4-63, 4-64, 4-65, 4-67, 4-68, 4-70, 5-3, 5-4, 5-5, 5-6,
J o s
5-7, 5-8, 5-9, 5-10, 5-11, 5-12, 5-13, 5-14, 5-15, 5-18, 5-20,
5-21, 5-25, 5-31, 5-32, 5-33, 5-34, 5-38, 5-39, 5-40, 5-42, 5-44,
5-45, 5-46, 5-47, 5-48, 5-49, 6-3, 6-4, 6-5, 6-6, 6-7, 6-8,
6-9, 6-10, 6-11, 6-12, 6-13, 6-14, 6-15, 6-16, 6-17, 6-18, 6-20,
6-21, 7-4, 7-5, 7-6, 7-7, 7-8, 7-9, 7-13, 7-15, 7-17, 7-18,
7-19, 7-20, 7-21, 7-22, 7-24, 7-25, 7-26, 7-27, 7-28, 7-29, 7-30,
7-31, 7-32, 7-33, 7-34, 8-4, 8-8, 8-9, 8-10, 8-11, 8-18, 9-3,
9-4, 9-5, 9-6, 9-8, 9-9, 9-10, 9-11, 9-12, 9-13, 9-14, 9-16,
9-19, 9-20, 9-21, 9-22, 9-23, 9-24, 9-26, 9-27, 9-28, 9-29, 9-30,
10-5, 10-17, 10-18, 10-19, 10-20, 10-21, 10-22, 10-25, 10-26, 10-28, 10-29,
11-5, 11-6, 11-8, 11-9, 11-10, 11-17, 11-18, 11-21, 11-25, 11-36
10-20, 10-21, 10-22, 10-23, 10-24, 10-25, 10-26, 10-27, 10-28, 10-29, 10-30,
10-31
trace file 1-19, 1-20, 2-6, 2-9, 3-28, 3-37, 5-4, 5-5, 5-14,
5-40, 5-47, 5-48, 7-35, 10-2, 10-3, 10-5, 10-8, 10-10, 10-12, 10-13,
10-14, 10-15, 10-16, 10-17, 10-18, 10-19, 10-20, 10-27, 10-30
Transformer 3-18, 3-19, 3-20, 3-21, 3-22, 3-23 n s e
lice
Transitivity 3-18, 3-23
a b le
trcsess 2-8, 10-2, 10-4, 10-13, 10-14, 10-15, 10-18, 10-30, 10-31
sfer
TRUNCATE 3-3
- t r an
no Tuning mode 11-3
n
a
s eฺ
U h a
e s ) u id
UGA 4-49 ฺ
ir ent G
ฺ m
d gp 4-50,
UNION 2-3, 2-4, 2-5, 3-19, 3-22, 4-48,
S
d 4-68, 4-69,
tu4-66,
5-48, 9-5, 9-17, 9-27,ia @ 11-11
9-28,
h is
b
ja 4-50, t
UNION ALL 2-3, 2-5,(3-19,
i a u se4-66, 4-68, 4-69, 5-48, 9-17,
A
9-27, 11-11b to
o
i 2-5, 2-20, 3-8, 3-20, 4-4, 4-10, 4-11, 4-13, 4-14,
n1-11,
UNIQUE
t o
e An4-15, 4-27, 4-29, 4-39, 4-40, 4-48, 4-50, 4-55, 4-56, 4-60, 4-69,
Jos 5-21, 5-24, 5-37, 5-42, 5-44, 5-45, 5-46, 7-7, 7-9, 7-16, 8-11,
9-8, 10-4
Unique 1-11, 2-5, 2-20, 3-8, 3-20, 4-4, 4-10, 4-11, 4-13, 4-14,
4-15, 4-27, 4-29, 4-39, 4-40, 4-48, 4-50, 4-55, 4-56, 4-60, 4-69,
5-21, 5-24, 5-37, 5-42, 5-44, 5-45, 5-46, 7-7, 7-9, 7-16, 8-11,
9-8, 10-4
Unique key 2-20, 3-20, 4-40
UNNEST 3-18, 3-20, 3-34, 4-64, 9-4, 9-17
UPDATE 1-8, 3-3, 3-11, 3-12, 4-7, 4-37, 5-3, 5-15, 5-23, 7-3,
7-20, 7-21, 7-22, 7-33, 9-5, 9-6, 9-8, 9-28, 10-4, 10-25, 10-29
USE_CONCAT 9-17
USE_HASH 5-47, 9-22
V
V$ACTIVE_SESSION_HISTORY 5-31, 5-35, 5-36, 5-38
V$DIAG_INFO 10-5
V$SESSION 5-21, 5-25, 5-35, 5-36, 5-39, 10-8, 10-11, 10-14
V$SESSION_LONGOPS 5-35, 5-36, 5-39
n s e
V$SQL 5-4, 5-13, 5-14, 5-20, 5-21, 5-22, 5-23, 5-24, 5-25, 5-26,
lice
5-32, 5-35, 5-36, 5-37, 5-38, 5-40, 5-44, 5-48, 8-3, 8-14, 8-16,
a b le
8-17, 11-17 s f er
V$SQL_CS_HISTOGRAM 8-16 - t r an
V$SQL_CS_SELECTIVITY 8-16 n on
s a
V$SQL_CS_STATISTICS 8-17
) h a
i d eฺ
V$SQL_MONITOR 5-4, 5-35, 5-36, 5-37 irฺe
s Gu
V$SQL_PLAN 5-4, 5-13, 5-14, 5-20, p ฺ m 5-22,
5-21, d e nt 5-24, 5-25,
5-23,
d g Stu
5-26, 5-35, 5-36, 5-38,
i @ 5-44,
a5-40, h is 5-48
b t
V$SQL_PLAN_MONITOR
i a (ja 5-4, u se5-35, 5-36, 5-38
A b
V$SQL_PLAN_STATISTICS to 5-13, 5-20, 5-22, 5-23, 5-24, 5-48
i o
ton
V$SQL_PLAN_STATISTICS_ALL 5-13, 5-20, 5-22, 5-23, 5-24
e An
V$SQL_WORKAREA 5-20, 5-22, 5-23, 5-24
J os V$SQLAREA 5-21, 5-23, 5-24, 5-25
View 1-2, 1-3, 1-6, 1-20, 1-22, 1-26, 2-3, 2-6, 2-8, 2-9,
2-10, 2-11, 2-16, 2-19, 2-21, 2-25, 2-27, 3-6, 3-14, 3-15, 3-18,
3-21, 3-22, 3-25, 3-26, 3-32, 3-34, 3-37, 4-8, 4-10, 4-24, 4-35,
4-37, 4-38, 4-43, 4-50, 4-51, 4-52, 4-54, 4-72, 5-4, 5-6, 5-13,
5-15, 5-20, 5-21, 5-22, 5-23, 5-24, 5-27, 5-29, 5-30, 5-31, 5-32,
5-35, 5-36, 5-38, 5-39, 5-49, 5-52, 6-6, 6-8, 6-15, 6-18, 6-23,
7-4, 7-9, 7-11, 7-13, 7-15, 7-17, 7-18, 7-19, 7-25, 7-26, 7-28,
7-31, 7-33, 7-34, 7-35, 7-36, 8-13, 8-14, 8-16, 8-17, 8-21, 9-3,
9-4, 9-17, 9-18, 9-24, 9-25, 9-26, 9-27, 9-28, 9-29, 9-31, 9-32,
10-6, 10-9, 10-12, 10-14, 10-18, 10-30, 10-31, 11-5, 11-8, 11-15, 11-16,
11-17, 11-18, 11-19, 11-20, 11-23, 11-24, 11-25, 11-28, 11-33, 11-34, 11-38
n s e
i ce
b l el
fer a
a n s
n - tr
o
s an
) h a deฺ
r ฺ e s Gui
p ฺ mi dent
d g Stu
b i a@ this
i a (ja use
Ab to
o n io
n t
e A
J o s