Академический Документы
Профессиональный Документы
Культура Документы
==========================
Dumping the data in to our test schema:
conn ptuser/oracle
autotrace on
explain plan..
COUNT(*)
----------
19671
no rows selected
PTUSER@orcl>
System altered.
PTUSER@orcl>
->
check stats on table level.
Though creating index is not helping to avoid full table scan. Now let us update
table statistics.
begin
dbms_stats.gather_table_stats(
ownname => 'PTUSER',
tabname => 'TAB1',
estimate_percent => 100,
method_opt => 'for all columns size auto',
degree => 3,
cascade => TRUE);
end;
/
-> Still the same with updated stats, Let us try using hint on this query and get
explain plan.
select sql_id,child_number,sql_text from v$sql where sql_Text like '%TAB1%';
Still the same performance. Now let us change the value in the filter and check
execution plan
SQL> select table_name,tablespace_name,status from tab1 b where b.num_rows>10000;
corrected query:-
----------------
alter system flush shared_pool;
alter system flush buffer_cache;
We are using hint to force optimizer to go for index scan. but, optimizer always
will go for better execution plan even though you have index created on it.
it will not use indexes for sometimes because without index also having the better
execution plan ( i mean, by usin full table scan)
6. Delete some rows from MY_SALES_2, resulting in a table with about 1/100 rows
of the original SALES table:
DELETE FROM sh.MY_SALES_2 WHERE MOD(ID,100) <> 0;
COMMIT;
9. Select some rows from the MY_SALES_ALL table, showing the execution plan
with statistics:
SET LINESIZE 120
SET AUTOT TRACE EXP STAT
SELECT * FROM sh.MY_SALES_ALL WHERE TIME_ID > TO_DATE('20011220', 'YYYYMMDD');
11. Select some rows using the same query from MY_SALES_2 table, showing the
execution plan with statistics:
CONNECT sh/oracle
SET LINESIZE 120
SET AUTOT TRACE EXP STAT
SELECT * FROM sh.MY_SALES_2
WHERE TIME_ID > TO_DATE('20011220', 'YYYYMMDD');
SET AUTOT OFF
13. Count the used database blocks by MY_SALES_ALL and MY_SALES_2 tables after
space shrinking:
SELECT BLOCKS FROM DBA_TABLES WHERE TABLE_NAME IN ('MY_SALES_ALL', 'MY_SALES_2');