1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
ConnectÚ Ó :
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
mni@DIANA> create table tmp as
2 select rownum as id,
3 object_name as some_text,
4 object_type as some_type,
5 case
6 when mod(rownum,10) = 0 Then Null
7 Else trunc(dbms_random.value(1,10))
8 end As n
9 from all_objects
10 Where rownum <= 70000
11 /
Table crÚÚe.
mni@DIANA>
mni@DIANA> CREATE INDEX tmp_ind ON tmp(some_type,n,1)
2 /
Index crÚÚ.
mni@DIANA>
mni@DIANA> exec dbms_stats.gather_table_stats(user,'TMP')
ProcÚdure PL/SQL terminÚe avec succÞs.
mni@DIANA>
mni@DIANA> set autotrace on
mni@DIANA>
mni@DIANA> SELECT case count(*)
2 when count(n)
3 then sum(n)
4 end AS res
5 FROM tmp
6 where some_type = 'TABLE'
7 /
RES
----------
--Plan d'exécution
----------------------------------------------------------
Plan hash value: 444391475
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 12 | 8 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 12 | | |
|* 2 | INDEX RANGE SCAN| TMP_IND | 1842 | 22104 | 8 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("SOME_TYPE"='TABLE')
Statistiques
----------------------------------------------------------
0 recursive calls
0 db block gets
11 consistent gets
0 physical reads
0 redo size
423 bytes sent via SQL*Net to client
416 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
mni@DIANA>
mni@DIANA> SELECT Sum(n)
2 FROM tmp t
3 where some_type = 'TABLE'
4 and 1 not in (Select 1 from tmp t1 where t1.some_type = t.some_type and n is null And rownum = 1)
5 /
SUM(N)
----------
--Plan d'exécution
----------------------------------------------------------
Plan hash value: 2092370764
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 12 | 10 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 12 | | |
|* 2 | INDEX RANGE SCAN | TMP_IND | 92 | 1104 | 8 (0)| 00:00:01 |
|* 3 | FILTER | | | | | |
|* 4 | COUNT STOPKEY | | | | | |
|* 5 | INDEX RANGE SCAN| TMP_IND | 2 | 24 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("SOME_TYPE"='TABLE')
filter( NOT EXISTS (<not feasible>)
3 - filter(1=1)
4 - filter(ROWNUM=1)
5 - access("T1"."SOME_TYPE"=:B1 AND "N" IS NULL)
Statistiques
----------------------------------------------------------
0 recursive calls
0 db block gets
13 consistent gets
0 physical reads
0 redo size
426 bytes sent via SQL*Net to client
416 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed |