Index-Organized Table Truncate vs Lock/Stage/Drop/Recreate
884401Apr 23 2013 — edited Apr 24 2013I ran into an issue in a project where a function is recreating an index-organized table by doing:
Table Structure:
CREATE TABLE table_iot(
...)
ORGANIZATION INDEX
OVERFLOW ...;
Recreate Steps:
1) Populate global temporary staging table (gtt) with data
-- where gtt is staging for target index-organized table (iot)
2) Lock the target index-organized table (iot)
3) Copy old iot data to gtt
-- gtt now contains old and new data
4) Create new index-organized table (iot2) from gtt
-- iot2 now contains old and new data
Along lines of
create table iot2 (
...
) organization index overflow parallel as
select
...
from gtt order by <primary_key_list>
);
5) Drop old iot table
6) Rename iot2 to iot
7) Recompile invalidated views and package (bodies)
One of the problems with this approach is the invalidation of dependent views and packages, etc
I am wondering if one can simply truncate the table instead of dropping it and recreating
and what are the considerations
The question becomes what is the best way to recreate an index-organized table?
Can one lock, copy to gtt, truncate, move back from gtt and ALTER TABLE table_iot MOVE? or can one just ALTER TABLE table_iot MOVE?
I note this url
http://docs.oracle.com/cd/B28359_01/server.111/b28310/tables012.htm
And this section
Moving (Rebuilding) Index-Organized Tables
Because index-organized tables are primarily stored in a B-tree index, you can encounter fragmentation as a consequence of incremental updates. However, you can use the ALTER TABLE...MOVE statement to rebuild the index and reduce this fragmentation.
The following statement rebuilds the index-organized table admin_docindex:
ALTER TABLE admin_docindex MOVE;
You can rebuild index-organized tables online using the ONLINE keyword. The overflow data segment, if present, is rebuilt when the OVERFLOW keyword is specified.
Edited by: 881398 on Apr 24, 2013 10:47 AM