Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Why Statistics doesn't match reponse time?
Hi
I test the following two queries in my 9.2.0.3 database. The response
time
is consistent.
select /*+ index(cl Total_contributionlog_idx) */ jackpotpool_id,
max(contributionlog_id) as contributionlog_id, max(cl.datecreated) as datecreated, max(jackpotPoolCurrentTotal) as jackpotPoolCurrentTotalfrom contributionlog cl, pool p
select jackpotpool_id,
max(contributionlog_id) as contributionlog_id, max(cl.datecreated) as datecreated, max(jackpotPoolCurrentTotal) as jackpotPoolCurrentTotalfrom contributionlog cl, pool p
8 rows selected.
Elapsed: 00:00:02.09
When I turn on the autotrace, this is the result.
Hint:
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2477 Card=1789 Bytes=25046)
1 0 SORT (GROUP BY) (Cost=2477 Card=1789 Bytes=25046)
2 1 NESTED LOOPS (Cost=2461 Card=8351 Bytes=116914) 3 2 INDEX (FULL SCAN) OF 'PK_POOL' (UNIQUE) (Cost=1 Card=8 Bytes=32) 4 2 TABLE ACCESS (BY INDEX ROWID) OF 'CONTRIBUTIONLOG' (Cost=308 Card=1044 Bytes=10440) 5 4 INDEX (RANGE SCAN) OF 'TOTAL_CONTRIBUTIONLOG_IDX'(NON-UNIQUE) (Cost=1 Card=1044)
Statistics
0 recursive calls 0 db block gets 137605 consistent gets 0 physical reads 0 redo size 590 bytes sent via SQL*Net to client 504 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 8 rows processed
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1505 Card=8 Bytes=112)
1 0 SORT (GROUP BY) (Cost=1505 Card=8 Bytes=112)
2 1 NESTED LOOPS (Cost=1489 Card=8351 Bytes=116914) 3 2 TABLE ACCESS (FULL) OF 'CONTRIBUTIONLOG' (Cost=1487 Card=1867580 Bytes=18675800) 4 2 INDEX (UNIQUE SCAN) OF 'PK_POOL' (UNIQUE)
Statistics
0 recursive calls 0 db block gets 15462 consistent gets 0 physical reads 0 redo size 590 bytes sent via SQL*Net to client 504 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 1 sorts (memory) 0 sorts (disk) 8 rows processed
>From Execution Plan and response time, I believe the first query is
better.
select count(*)
from (select distinct jackpotpool_id from contributionlog);
COUNT(*)
1789
select count(*) from pool;
COUNT(*)
9
However, I have two questions.
1. Why CBO cannot find the better one, provided that both tables have
been analyzed?
2. Why statistics of query 2 looks better than query 1?
query 1 with hint: 137605 consistent gets query 2 withiout hint: 15462 consistent gets
Kind Regards,
Bin
Received on Thu Sep 08 2005 - 18:54:41 CDT