Suppose I have two tables job
and batch
:
CREATE TABLE batch
(
batch_id NUMBER(20) PRIMARY KEY,
batch_type NUMBER(20),
[some other values] ...
);
CREATE TABLE job
(
job_id NUMBER(20) PRIMARY KEY,
job_batch_id NUMBER(20),
job_usr_id NUMBER(20),
job_date DATE,
[some other values] ...
CONSTRAINT fk_job_batch
FOREIGN KEY (job_batch_id) REFERENCES batch(batch_id),
CONSTRAINT fk_job_usr
FOREIGN KEY (job_usr_id) REFERENCES client(usr_id)
);
And suppose they each contain a considerable amount of data (many millions of rows). What I want to do is create a Materialized View to reflect, for each usr_id
, what the first and last jobs were run for a particular type of batch. For example:
CREATE MATERIALIZED VIEW client_first_last_job
(usr_id, first_job_date, last_job_date)
AS
(
SELECT
job_usr_id AS usr_id,
MIN(job_date) AS first_job_date,
MAX(job_date) AS last_job_date
FROM job, batch
WHERE job_batch_id=batch_id
AND batch_type IN (1,3,5,9)
GROUP BY job_usr_id
);
This is all well and good, but because there are so many records it takes a very long time to build this materialized view (far longer than is acceptable to deal with each time it needs to refresh). My immediate thought would be to use Materialized View Logs to have incremental updates. These are easy enough to create. But when I try to build the MV to use REFRESH FAST ON DEMAND
, that gets me a ORA-12015: cannot create a fast refresh materialized view from a complex query
error, which from some Googling I am guessing is due to the coexistence of a join and aggregate functions.
Is there another way to do this? Note that de-normalization or other alterations to the parent tables are not feasible.