Documente Academic
Documente Profesional
Documente Cultură
More Memory
Faster or additional Processors
Faster Disk IO (possibly via RAID)
More Network Bandwidth
Software Solution
Database/Instance Tuning(Location of files, block size, db buffer cache
size, etc)
Object Tuning (Index creation, table reorganization, etc)
SQL Tuning (application tuning)
Name
Street
Zip
Dept
Salary
Conway
1 Main St.
24142
Finc
$ 50,000
Harrington
12 Elm Ave.
24142
IT
$ 45,000
Lytle
11 Southern St.
24060
Finc
$ 33,000
Johnson
12 Elm Ave.
24142
IT
$ 81,000
Bosworth
3 Main St.
24060
Actg
$ 50,000
Fulton
18 Oak Rd.
24142
Actg
$ 44,000
Adams
14 Pine Ct.
24142
Finc
$ 50,000
Truman
11 Pine Ct.
24142
Finc
$ 45,000
Waters
18 Main St.
24142
Actg
$ 33,000
10
Rhineman
23 Main St.
24142
IT
$ 81,000
11
Matthews
31 Elm Ave.
24060
Finc
$ 50,000
12
Smith
2 Oak Rd.
24060
Actg
$ 44,000
13
Darlington
8 Ridge Rd.
24060
Actg
$ 81,000
14
Potter
5 Elm Ave.
24142
IT
$ 50,000
15
Varner
1 Elm Ave.
24142
Actg
$ 44,000
Binary Tree
Lytle
Darlington
Bosworth
Adams
Conway
Smith
Harrington
Fulton
Johnson
Potter
Matthews
Rhineman
Varner
Truman
Waters
Nodes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
3
7
15
31
63
127
255
511
1,023
2,047
4,095
8,191
16,383
32,767
65,535
131,071
262,143
524,287
1,048,575
Worse Case
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Sequential Search
Average Case
1.00
1.75
2.55
3.38
4.26
5.18
6.11
7.07
8.04
9.03
10.01
11.01
12.01
13.00
14.00
15.00
16.00
17.00
18.00
19.00
Worse Case
1
3
7
15
31
63
127
255
511
1,023
2,047
4,095
8,191
16,383
32,767
65,535
131,071
262,143
524,287
1,048,575
Average Case
1.00
1.50
3.50
7.50
16.50
31.50
63.50
127.50
255.50
511.50
1,023.50
2,047.50
4,095.50
8,191.50
16,383.50
32,767.50
65,535.50
131,071.50
262,143.50
524,287.50
Conway
N N
Harrington
Lytle
13 12
Johnson
N N
Bosworth
Fulton
N N
Adams
N N
Truman
N N
Waters
N N
10
Rhineman
N N
11
Matthews
N N
12
Smith
14 15
13
Darlington
14
Potter
11 10
15
Varner
EOF
Lytle
4
Smith
Darlington
2
9
Bosworth
Varner
Harrington
Adams
Potter
Conway
Truman
Fulton
Johnson
Matthews
Rhineman
Waters
Cluster Index
RowID
Name
Street
Zip
Dept
Salary
Conway
1 Main St.
24142
Finc
$ 50,000
N N
Harrington
12 Elm Ave.
24142
IT
$ 45,000
Lytle
11 Southern St.
24060
Finc
$ 33,000
13 12
Johnson
12 Elm Ave.
24142
IT
$ 81,000
N N
Bosworth
3 Main St.
24060
Actg
$ 50,000
Fulton
18 Oak Rd.
24142
Actg
$ 44,000
N N
Adams
14 Pine Ct.
24142
Finc
$ 50,000
N N
Truman
11 Pine Ct.
24142
Finc
$ 45,000
N N
Waters
18 Main St.
24142
Actg
$ 33,000
N N
10
Rhineman
23 Main St.
24142
IT
$ 81,000
N N
11
Matthews
31 Elm Ave.
24060
Finc
$ 50,000
N N
12
Smith
2 Oak Rd.
24060
Actg
$ 44,000
14 15
13
Darlington
8 Ridge Rd.
24060
Actg
$ 81,000
14
Potter
5 Elm Ave.
24142
IT
$ 50,000
11 10
15
Varner
1 Elm Ave.
24142
Actg
$ 44,000
2
9
1 Main St.
24142
Finc
COBOL
Excellent
Conway
JAVA
Good
Conway
VB
Excellent
Conway
C#
Novice
$ 50,000
The structure of an SQL query can effect the execution plan of that
query. In oracle this is particularly true when the rule based
optimizer is being used.
Oracle Optimizers
An optimizer determines the best way to execute
the SQL query. Oracle has two optimizers.
The Oracle rules based optimizer follows a strict set of rules
when determining how to execute the query. For example,
one rule is that all available indexes should be used.
The Oracle cost based optimizer looks at statistics, such as
the number of rows in a table or the variance of values in a
column, to determine the best way to execute the SQL
statement. For example, the cost based optimizer may
choose to ignore an index if it sees that the table is very small
and will be completely pulled into memory with a single
block (page) read anyway.
Analyzing Tables
Generally, the cost based optimizer provides better performance. For
the cost based optimizer to run statistics on tables must be
periodically gathered. This can be done with either:
Or
For Query:
Select
Select
Select
Select
Select
Select
Neither EXPLAIN PLAN or autotrace will work unless you first create a table
in your schema to hold the execution plan steps. To create the plan_table table
run \\neelix\dropbox\itec\itec340\_instructorFiles\scripts\utlxplan.sql
Sample Query
select drivername, nickname, phone
from drivers, performance
where race='Daytona 500'
and drivers.drivername=performance.driver
intersect
select drivername, nickname, phone
from drivers, performance
where race='Brickyard 400'
and drivers.drivername=performance.driver
* Retrieves driver info for those who drove in both races
The second column shows the parent process of any subprocess. Execution order is generally from The
HIGHEST number is in the second column to the lowest number with some exceptions such as nested loops. For
nested loops the table access order is from top to bottomFULL table access indicates a sequential read of the
entire table. A scan indicates the use of an index. Access by ROWID is direct access to a table row after an index
has been consulted to obtain the ROWID.
HINTS
OPTIMIZER MODE
USE OF INDEX
TYPE OF JOIN and DRIVING TABLE
ORDER OF JOINS
INDEX DECISION
Should the Index Be used?
- what is table size
- what is column(s) selectivity
(if you are selecting >20%
dont bother with the index)
Is the optimizer making the correct decision?
JOIN ORDER
Small tables or Tables with High Selectivity
should be joined before large tables or
tables with low selectivity.
Under RULE optimization tables are joined
left to right as they appear in the FROM
clause.
Exercise 1
Request: A list of all movie titles in alphabetic order by title
Query 1
Select title
from movies
order by title;
Examine the execution plan for the above query.
What is interesting about this query of the MOVIES table?
Exercise 2
Request: Title and Rating of every movie that Tom Hanks has starred in.
Query 1
Select title, rating
from movies
where title in (select movie
from starred_in
where actor='Tom Hanks');
Query 2
Select title, rating
from movies, starred_in
where movies.title = starred_in.movie
and actor='Tom Hanks';
Which query is more efficient? Can you tune the other?
Exercise 3
Request: A list of Actors that are also Directors
Query 1
Select name from actors
intersect
Select name from directors;
Query 2
Select actors.name
from actors, directors
where actors.name = directors.name;
Which query is more efficient?
Which requires less DISK I/O?
Which do you think requires less Memory?
Which has the fastest clock time?
Exercise 4
Request: A non-repeating list of the genres of movies that Tom Hanks has starred in.
select distinct genre
from movie_genres, movies, starred_in
where movie_genres.movie = movies.title
and starred_in.movie = movies.title
and actor='Tom Hanks';
Tune the above query. Hint: I had success with hints, indexing, and restructuring
Exercise 5
Query:
Select * from movies where upper(title) = 'ALIENS';