Professional Documents
Culture Documents
Oracle Optimizer
Oracle Optimizer
----------------
Rowid- it records the physical location where row is stored.
Different operations
--------------------
1) Table Access Full-this is used when there is no where clause.
2) Table Access By Rowid-Oracle uses indexes to correlate data values
with rowid.
Related Hints
-------------
Can specify hints that direct CBO in processing of query.
Immediately after select, enter /*+
Then hint such as FULL(worker)
Close hint with */
Two type of hints- FULL,ROWID
Types of Indexes
----------------
1) Unique indexes
2) Non Unique indexes
Selectivity of Index
--------------------
The index is very much selective for eg. 80% distinct values or can be less
selective.
If you are using CBO then optimiser chooses whether to use index or not.
If more selective then more chances of using indexes.
The rowid's returned by both are scanned. Rowid's returned from comparision are
used for
Table Access by rowid.
In query like 'where Manager in('Thom','Ken');'. The optimizer uses index unique
scan for both
differently then concatenates the result of two and then performs Table Access by
Rowid.
Related Hints
-------------
1) Index hint e.g. select /*+ INDEX(lodging) */ lodging from lodging where
manager='KEN';
you can specify a list also as /*+ INDEX(lodging manager) */
Other Index related hints- INDEX_ASC, INDEX_DESC
Ordering Rows-Three oracle operations sort rows without grouping the rows.
a) SORT ORDER BY (As in order by)
b) SORT UNIQUE (As is distinct)
c) SORT JOIN
Grouping Rows-Two oracle opertions sort rows while grouping like records together.
a) SORT AGGREGATE e.g. select max(age) from worker; here age is not indexed.
B) SORT GROUP e.g. select count(*) from worker group by lodging;
Table Access full ---> Sort Group by ---> Filter ---> View
Merge Join
----------
e.g. select worker.name, Lodging.Manager from Worker,Lodging where
worker.lodging=lodging.lodging;
To resolve the query, the optimizer may choose to perform the MERGE JOIN.
Each table is read individually by a Table Access Full operation.The set of rows
returned from
the table scan are sorted by SORT JOIN opertion separately.The data from the SORT
JOIN operations
is then merged via a MERGE JOIN operation.
Table Access Full of Lodging ----> Sort Join
Merge Join
Table Access Full of Worker ----> Sort Join
This is most efficient when tables are of same size.This is used when no indexes
are available.
When index is available then other join operations are used.
Nested Loops
------------
In which type of operation, the primary requirement is that index must be
available on atleast
one column which are joined. To execute a NESTED LOOPS join, the optimizer must
first select a
driving table for the join. The driving table is the table that will be read
first. For each
record in the driving table, the second table in the join will be queried.
Tables worker,lodging
there is a index on lodging and no index on worker.
Worker is selected as driving table.
These are mostly used for online users.If u are using CBO then driving table will
be selected
based on statistics and selectivity. If this RBO then generally the last table in
select statement
will be used as driving table. These are useful when tables are of different
size.Using smaller
table as driving table.
Hash Join
---------
During a hash join, the first table is scanned via a Table Access Full and the
database applies
'hashing' functions to the data to prepare the table for the join. The values from
the second table
are then read and the hashing function is used to compare the second table with
first table. The
rows that result in match are returned to the user.
The optimizer may choose to perform hash joins even if indexes are available.
As Full scans are performed, so this most useful when parallel query option is
used.
The opertions involved in hash join return records quickly to the users.
Related Hints
-------------
Hints can be used to override the optimizer's selection of a join method.
Hints can be used for two purposes-Type of join method,goal of the join.
Hints discussed earlier can also be used in addition to these.
Filtering of rows
-----------------
When index is available FILTER operation is not listed explicitly in a query's
execution plan.
It will be performed as part of the Table Access by Rowid operation.
When a FILTER operation is listed explicitly in exection plan, it usually
indicates that no index is
available for limiting condition.