PostLoad Stored Procedure
This stored procedure should recreate all objects required for the data warehouse to perform efficiently, create index that have been dropped before, refresh aggregate tables, rebuild the indexes on the aggregate tables if they have been disabled before, etc. The procedure will return an integer value with the number of problems found, but will never raise an error so that the load can continue.
PostLoad Stored Procedure for Oracle
Here, the opposite will be done to before. Create all Bitmap Indexes that haven't been created yet; on all Fact Tables that have [Materialized Views] based on them, create the Materialized View Logs and finally refresh the [Materialized Views] to have the most current information there. It is important to write this procedure as error save as possible, e.g. this procedure might execute only partially and will be re-executed again. Therefore, if a task has been performed already, it should be skipped.
Postprocessing_fact_table source code:
create or replace procedure postprocessing_fact_table(
pLoadType in varchar2,
pDropCreateIndex in varchar2,
pFactTable in varchar2,
pMView_Failures out binary_integer) is
cursor cMViews(pTableName varchar2) is
select mview_name
from USER_MVIEW_DETAIL_RELATIONS
where DETAILOBJ_NAME = pTableName and
DETAILOBJ_TYPE = 'TABLE';
owner varchar2(30);
begin
create_indexes(pFactTable);
create_mview_logs(pFactTable);
dbms_mview.refresh_dependent(pMView_Failures, pFactTable, '?', NULL, true, true);
for rMViews in cMViews(pFactTable) loop
create_indexes(rMViews.mview_name);
end loop;
end postprocessing_fact_table;
/
create or replace procedure create_indexes(
pFactTable in varchar2) is
cursor cCreateIndex(pTableName in varchar2) is
select index_name, table_name,
column_name1, column_name2, column_name3,
additional_text
from lookup_indexes
where table_name = pTableName and
index_name not in (select index_name from user_indexes);
vCursor integer;
vReturn integer;
vColumnList varchar2(4000);
begin
for rCreateIndex in cCreateIndex(pFactTable) loop
if (rCreateIndex.column_name1 is not null) then
vColumnList := rCreateIndex.column_name1;
if (rCreateIndex.column_name2 is not null) then
vColumnList := vColumnList || ', ' ||
rCreateIndex.column_name2;
if (rCreateIndex.column_name3 is not null) then
vColumnList := vColumnList || ', ' ||
rCreateIndex.column_name3;
end if;
end if;
execute immediate 'create bitmap index ' ||
rCreateIndex.index_name || ' on ' || pFactTable ||
'(' || vColumnList || ') ' ||
rCreateIndex.additional_text;
end if;
end loop;
end create_indexes;
/
create or replace procedure Create_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_mviews c
WHERE a.mview_name = b.mview_name AND
a.mview_name = c.mview_name AND
b.DETAILOBJ_NAME = pTableName AND
b.DETAILOBJ_TYPE = 'TABLE' AND
c.FAST_REFRESHABLE IN ('DML', 'DIRLOAD_DML') AND
refresh_method = 'FORCE'
MINUS
SELECT master FROM user_snapshot_logs;
CURSOR cColumns(pTableName VARCHAR2) IS
SELECT column_name
FROM user_tab_columns
WHERE table_name = pTableName;
vCursor INTEGER;
vReturn INTEGER;
vColumnList VARCHAR2(4000);
BEGIN
FOR rMViews IN cMViews LOOP
EXECUTE IMMEDIATE 'alter materialized view ' ||
rMViews.mview_name || ' compile';
END LOOP;
FOR rMViewTables IN cMViewTables(pFactTable) LOOP
vColumnList := NULL;
FOR rColumns IN cColumns(rMViewTables.table_name) LOOP
IF vColumnList IS NULL THEN
vColumnList := '"' || rColumns.column_name || '"';
ELSE
vColumnList := vColumnList || ', "' || rColumns.column_name || '"';
END IF;
END LOOP;
EXECUTE IMMEDIATE 'CREATE materialized VIEW LOG ON ' ||
rMViewTables.table_name || ' WITH SEQUENCE, ROWID (' ||
vColumnList || ') INCLUDING NEW VALUES';
END LOOP;
END Create_Mview_Logs;
/