PreLoad Stored Procedure
This database stored procedure deals with all the DB maintenance before loading the fact table. So for an initial load, it disables all objects that might slow down the load, for delta load it optionally disables indexes based on the $G_REBUILD_INDEXES global variable.
PreLoad Stored Procedure for Oracle
For Oracle, fact tables do have Bitmap Indexes and Materialized Views together with Materialized View Logs. For an initial load, all the Bitmap Indexes should be disabled - but since there is no way to do that without drawback we drop them and remember the index settings in a table called LOOKUP_INDEXES - and the Materialized View Logs dropped.
Preprocessing_fact_table source code:
create or replace procedure preprocessing_fact_table(
pLoadType in varchar2,
pDropCreateIndex in varchar2,
pFactTable in varchar2) is
cursor cMViews(pTableName varchar2) is
select mview_name
from USER_MVIEW_DETAIL_RELATIONS
where DETAILOBJ_NAME = pTableName and DETAILOBJ_TYPE = 'TABLE';
begin
if pLoadType = 'FIRST' then
drop_mview_logs(pFactTable);
end if;
if pDropCreateIndex = 'Y' or pLoadType = 'FIRST' then
drop_indexes(pFactTable);
for rMViews in cMViews(pFactTable) loop
drop_indexes(rMViews.mview_name);
end loop;
end if;
end preprocessing_fact_table;
/
create or replace procedure Drop_Mview_Logs(
pFactTable IN VARCHAR2) IS
CURSOR cMViews IS
SELECT mview_name
FROM user_mviews
WHERE compile_state = 'NEEDS_COMPILE';
CURSOR cMViewTables(pTableName VARCHAR2) IS
SELECT DISTINCT a.DETAILOBJ_NAME table_name
FROM USER_MVIEW_DETAIL_RELATIONS a, USER_MVIEW_DETAIL_RELATIONS b, user_snapshot_logs c
WHERE a.mview_name = b.mview_name AND
a.DETAILOBJ_NAME = c.master AND
b.DETAILOBJ_NAME = pTableName AND
b.DETAILOBJ_TYPE = 'TABLE';
vCursor INTEGER;
vReturn INTEGER;
BEGIN
FOR rMViews IN cMViews LOOP
EXECUTE IMMEDIATE 'alter materialized view ' || rMViews.mview_name || ' compile';
END LOOP;
FOR rMViewTables IN cMViewTables(pFactTable) LOOP
EXECUTE IMMEDIATE 'DROP materialized VIEW LOG ON ' || rMViewTables.table_name;
END LOOP;
END Drop_Mview_Logs;
/
create or replace procedure drop_indexes(
pFactTable in varchar2) is
cursor cDropIndex(pTableName in varchar2) is
select distinct i.index_name index_name,
'tablespace ' || nvl(i.tablespace_name,
p.tablespace_name) ||
decode(i.partitioned, 'YES', ' LOCAL ', ' ') ||
decode(i.degree, 'DEFAULT', 'PARALLEL ', '') additional_text
from user_indexes i, user_ind_partitions p
where i.index_type = 'BITMAP' and
i.table_name = pTableName and
i.index_name = p.index_name(+);
cursor cIndexColumns(pIndexName in varchar2) is
select column_name, column_position
from user_ind_columns
where index_name = pIndexName
order by column_position;
vCursor integer;
vReturn integer;
vColumn_Name1 varchar2(32);
vColumn_Name2 varchar2(32);
vColumn_Name3 varchar2(32);
begin
for rDropIndex in cDropIndex(pFactTable) loop
vColumn_Name1 := null;
vColumn_Name2 := null;
vColumn_Name3 := null;
for rIndexColumns in cIndexColumns(rDropIndex.index_name) loop
if rIndexColumns.column_position = 1 then
vColumn_Name1 := rIndexColumns.column_name;
elsif rIndexColumns.column_position = 2 then
vColumn_Name2 := rIndexColumns.column_name;
elsif rIndexColumns.column_position = 3 then
vColumn_Name3 := rIndexColumns.column_name;
end if;
end loop;
delete lookup_indexes where index_name = rDropIndex.index_name;
insert into lookup_indexes(index_name, table_name,
column_name1, column_name2, column_name3, additional_text)
values (rDropIndex.index_name, pFactTable,
vColumn_Name1, vColumn_Name2, vColumn_Name3, rDropIndex.additional_text);
execute immediate 'drop index ' || rDropIndex.index_name;
commit;
end loop;
end drop_indexes;
/
CREATE TABLE LOOKUP_INDEXES (
INDEX_NAME VARCHAR2 (64),
TABLE_NAME VARCHAR2 (64),
COLUMN_NAME1 VARCHAR2 (64),
COLUMN_NAME2 VARCHAR2 (64),
COLUMN_NAME3 VARCHAR2 (64),
ADDITIONAL_TEXT VARCHAR2 (64) );