I cannot get a select statement (very last line in the script below) to query rewrite to use a materialized view. Unfortunately, I don't have a REWRITE_TABLE, so I cannot use dbms_view.explain_rewrite. I am using the execution plan to confirm that it is not being rewritten to use the materialized view. All parameters (paramaters are shown near the end of the below script) and clauses seem to be in place. Even when the REWRITE hint is used, it is still not rewriting. What am I missing? Thank you in advance.
drop table A;
create table A
(
x number not null
, y char(1 byte) not null
)
;
insert into A (x, y) select level, chr(mod(level-1,10) + ascii('A'))
from dual connect by level <= 1000
;
create unique index IU_A_x ON A (x);
create index IX_A_y ON A (y);
alter table A
add (
constraint PK_A primary key ( x )
rely
using index IU_A_x
enable validate
)
;
--analyze table statistics for A
drop table B;
create table B
(
x number not null
, z char(1 byte) not null
)
;
insert into B (x, z) select mod(level,1000)+1, chr(mod(level-1,26) + ascii('A'))
from dual connect by level <= 1000000
;
create index IX_B_x ON B (x);
create index IX_B_z ON B (z);
alter table B
add (
constraint R_B_x foreign key ( x )
references A (x)
rely
enable validate
)
;
--analyze table statistics for B
drop materialized view MV;
create materialized view MV
(
y
, z
)
build immediate
refresh force on demand
with primary key
using trusted constraints
enable query rewrite
as
select
A.y, B.z from A join B on A.x = B.x
;
create index IX_MV_y ON MV (y);
create index IX_MV_z ON MV (z);
--analyze table statistics for MV
set serveroutput on;
show parameters optimizer_mode; --all_rows
show parameters query_rewrite_enabled; -- true
show parameters query_rewrite_integrity; --enforced
select /*+ rewrite */ A.y, B.z from A join B on A.x = B.x where y = 'A' and z = 'Z';