Oracle - Maximizing Sort Efficiency
Oracle - Maximizing Sort Efficiency
com
Overview
Sort Operations: Causes
Index Creation
ORDER BY or GROUP BY clause usage
DISTINCT keyword usage
UNION, INTERSECTION and MINUS Operations
Sort-Merge Operations:Example
Sort-Merge Operations
ANALYZE Command
SORT_AREA_SIZE
Sort Process: Sequence
Sort space requirement > SORT_AREA_SIZE
SORT_MULTIBLOCK_READ_COUNT parameter
Sort Areas: Setting Parameters
Setting Parameters and Sort Areas
Multithreaded Server Connection
Dedicated Server Connection
SORT_AREA_SIZE: Setting
SORT_AREA_SIZE: Altering
ALTER SESSION with SORT_AREA_SIZE syntax
ALTER SESSION with SORT_AREA_RETAINED_SIZE Syntax
Summary
Quick Quiz
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Purpose
The various operations that require a sort are discussed in the following
pages. Excessive sorting operations decrease server performance.
The operations that require a sort are shown below:
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Index Creation
The server process uses a sort to arrange the indexed values before
building the B-tree. Server processes also use a sort in cases where the
index is created in parallel.
This watermark does not appear in the registered version - http://www.clicktoconvert.com
ORDER BY or GROUP BY
Clause Usage
DEPTNO DEPTNO
---------- ----------
20 20
30 30
30 30
20 20
30 30
.. ..
.. ..
14 rows selected.
Execution Plan
----------------------------------------------------
0 SELECT STATEMENT
Optimizer=CHOOSE (Cost=1 Card=14 Bytes=70)
1 0 NESTED LOOPS (Cost=1 Card=14 Bytes=70)
2 1 TABLE ACCESS (FULL) OF 'EMP'
(Cost=1 Card=14 Bytes=42)
3 1 INDEX (UNIQUE SCAN) OF 'PK_DEPT' (UNIQUE)
Sort-Merge Operations
The equijoin request merges the sorted sources together, combining each
row from one source with each matching row of the other source. This is the
merge aspect in a sort-merge operation.
This watermark does not appear in the registered version - http://www.clicktoconvert.com
UNION
PRODUCT
SELECTION
Correct!
Incorrect. A SELECTION does not require a sorting operation. Please try
again
This watermark does not appear in the registered version - http://www.clicktoconvert.com
ANALYZE Command
SORT_AREA_SIZE
The server process first creates the sort runs and then writes the pieces to
temporary segments on the disk. These segments hold intermediate sort run
data while the server works on another sort run.
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Finally, the server process merges the sorted pieces to produce the result of
the sort.
This watermark does not appear in the registered version - http://www.clicktoconvert.com
If SORT_AREA_SIZE is not large enough to merge all the runs at once, the
server process uses a number of merge passes to merge the subsets of the
runs.
SORT_MULTIBLOCK_READ_COUNT Parameter
You have learned about the steps in the sort process when
the work space exceeds SORT_AREA_SIZE. The
sequence of steps that takes place in a sort process are:
In this topic you learn how to set the SORT_AREA_SIZE parameter by using
the ALTER SESSION command. You use the SORT_AREA_SIZE
parameter to specify the maximum amount of memory that is used for a sort.
Depending on the size of the operation, you may require a larger
SORT_AREA_SIZE.
The sort space is part of the Program Global Area (PGA). The location of the
PGA, and therefore the sort space, is determined by the type of server
connection being used, either dedicated or multithreaded.
When using a dedicated server connection, the UGA and sort space are
stored in the PGA.
SORT_AREA_SIZE: Setting
You set the sort space size with the INIT.ORA parameter,
SORT_AREA_SIZE. The default value of this parameter is operating system
(OS) dependent and adequate for most online transaction processing
(OLTP) operations. You might want to adjust the value for decision support
This watermark does not appear in the registered version - http://www.clicktoconvert.com
SORT_AREA_SIZE: Altering
When a sort is finished, the sort space still contains sorted rows to be
fetched. You can shrink the sort area to the size specified in the
SORT_AREA_RETAINED_SIZE parameter. This parameter can also be set
dynamically by using the ALTER SESSION or ALTER SYSTEM DEFERRED
command.
ALTER SESSION
This watermark does not appear in the registered version - http://www.clicktoconvert.com