Hi Sy
Are you sure that analyze locks the table?
I know that if you are doing DDL you can't make queries or DML – but same rule for analyze. But Analyze do not set a exclusive lock on the table.
I have tried the following in 9i R2 (pacth 4).
In Schema Scott I created a BIG_TABLE with more than 1 million rows as select from dba_objects repeated times.
I then open a session and locked the table in exclusive mode with:
LOCK TABLE BIG_TABLE IN EXCLUSIVE MODE;
I then looked in v$locked_object and saw the exclusive lock.
I then deleted all rows with:
DELETE FROM BIG_TABLE;
In another session I then wrote:
Analyze table BIG_TABLE compute statistics for table for all indexes for all columns;
And the analyze just started – and after analyze ended I then viewed the DBA_TABLES and saw
Code:
TABLE_NAME NUM_ROWS BLOCKS TO_CHAR(LAST_ANAL
------------------------------ ---------- ---------- -----------------
BIG_TABLE 1423968 19401 28-01-04 13:26:06
So it’s still possible to make analyze even if the table is exclusive locked and all rows deleted (not committed).
Now if I am right – then the session making analyze must use RBS because ALL rows are deleted (not committed). We can see it with trace files.
Code:
analyze /* Table still deleted completly without commit */ table big_table
compute statistics for table for all indexes for all indexed columns
Code:
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.11 0.09 0 0 0 0
Execute 1 65.25 130.01 59624
Code:
2 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 65.36 130.11 59624 1482175 2 0
And now I rollback deleted rows (in the first session) - so lock and RBS are gone.
Code:
analyze /* Table now rolled back now all rows in table */ table big_table
compute statistics for table for all indexes for all indexed columns
Code:
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 12.66 15.91 19366
Code:
2 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 12.66 15.92 19366 19405 2 0
So the conclusion is – that analyze doesn’t make an exclusive lock – and analyze doesn’t “see” any DML statements from other sessions – (like deleting all rows).
DBMS_STAT makes the same as analyze with the above test. But still I would also use DBMS_STAT because Oracle wants us to use DBMS_STAT rather than analyze, because under the cover – it make more and more than just the analyze command.
Now if you are using R2 of 9i – then you also may want to take a look on
OPTIMIZER_DYNAMIC_SAMPLING and
OPTIMIZER_FEATURES_ENABLED. These are new in R2 and helps if using global temporary tables because the CBO never knows the contents.
Regards
Allan
Icq: 346225948