SORT (UNIQUE STOPKEY)

Description

Removes duplicates from sorted list of rows. Number of rows returned is restricted using the ROWNUM pseudo-column

Versions

This operation is implemented in the following versions

7.3.4
8.0.4
8.0.5
8.0.6
8.1.5
8.1.6
8.1.7
9.0.1
9.2.0
10.1.0
10.2.0

Example

This example was developed using Oracle 9.2.0.1 on Windows 2000

This example requires the following table definition

    CREATE TABLE t1 (c1 NUMBER);

The table does not need to be analysed

The statement

    SELECT * FROM 
    (
      SELECT DISTINCT c1 FROM t1
    )
    WHERE ROWNUM < 10;

generates the following execution plan

0     SELECT STATEMENT Optimizer=CHOOSE
1   0   COUNT (STOPKEY)
2   1     VIEW
3   2       SORT (UNIQUE STOPKEY)
4   3         TABLE ACCESS (FULL) OF 'T1'

In Oracle 10.2 this statement generates the following execution plan

0     SELECT STATEMENT Optimizer=CHOOSE
1   0   COUNT (STOPKEY)
2   1     VIEW
3   2       SORT (GROUP BY STOPKEY)
4   3         TABLE ACCESS (FULL) OF 'T1'

However, if the "_gby_hash_aggregation_enabled" parameter is set to FALSE (default TRUE) as follows

    ALTER SESSION SET "_gby_hash_aggregation_enabled" = FALSE;

then the following execution plan is generated:

0     SELECT STATEMENT Optimizer=CHOOSE
1   0   COUNT (STOPKEY)
2   1     VIEW
3   2       SORT (UNIQUE STOPKEY)
4   3         TABLE ACCESS (FULL) OF 'T1'