SORT AGGREGATE做为sort的option之一比较特殊,他并不做sort
SORT AGGREGATE作用于所有的data set上,用于aggregate function,例如sum, count, avg, min, max
SQL>
select max(x)
from test;
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1 Bytes=5)
1 0 SORT (AGGREGATE)
2 1 INDEX (FULL SCAN (MIN/MAX)) OF 'TEST_IDX' (NON-UNIQUE) (
Cost=3 Card=7140 Bytes=35700)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
491 bytes sent via SQL*Net to client
650 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory) -- no sort here
0 sorts (disk)
1 rows processed
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1 Bytes=5)
1 0 SORT (AGGREGATE)
2 1 INDEX (FULL SCAN (MIN/MAX)) OF 'TEST_IDX' (NON-UNIQUE) (
Cost=3 Card=7140 Bytes=35700)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
491 bytes sent via SQL*Net to client
650 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory) -- no sort here
0 sorts (disk)
1 rows processed
如果aggregate function不是作用于与所有的data set上,还是作用于不同的group上,那么操作类型将会变为SORT (GROUP BY),这时会有sort发生
SQL>
select x,count(*)
from test
group by
x;
7138 rows selected.
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=20 Card=7137 Bytes=3
5685)
1 0 SORT (GROUP BY) (Cost=20 Card=7137 Bytes=35685)
2 1 TABLE ACCESS (FULL) OF 'TEST' (Cost=3 Card=7140 Bytes=35
700)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
19 consistent gets
0 physical reads
0 redo size
151790 bytes sent via SQL*Net to client
5875 bytes received via SQL*Net from client
477 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
7138 rows processed
7138 rows selected.
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=20 Card=7137 Bytes=3
5685)
1 0 SORT (GROUP BY) (Cost=20 Card=7137 Bytes=35685)
2 1 TABLE ACCESS (FULL) OF 'TEST' (Cost=3 Card=7140 Bytes=35
700)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
19 consistent gets
0 physical reads
0 redo size
151790 bytes sent via SQL*Net to client
5875 bytes received via SQL*Net from client
477 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
7138 rows processed