QUESTION POSED ON: 13 October 2005
I have a question regarding query performace and the query rewrite feature. I hope you can help me (or perhaps direct me to a solution).
We have the following situation: I have three tables and one dummy table:
create table cdr_type1 (a number, b number, c number);
insert into cdr_type1 values (1,2,3);
insert into cdr_type1 values (6,7,8);
create table cdr_type2 (a number, c number, d number);
insert into cdr_type2 values (34,35,67);
insert into cdr_type2 values (39,31,32);
create table cdr_type3 (a number, c number, e number);
insert into cdr_type3 values (900,900,900);
and a big table:
create table dummy_union (n number primary key, a number, b number,
c number, d number, e number, type varchar2(10) );
I register the table as a materialized view:
CREATE MATERIALIZED VIEW cdr_type1
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
ENABLE QUERY REWRITE
as select a,b,c from dummy_union where type='type1';
CREATE MATERIALIZED VIEW cdr_type2
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
ENABLE QUERY REWRITE
as select a,c,d from dummy_union where type='type2';
CREATE MATERIALIZED VIEW cdr_type3
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
ENABLE QUERY REWRITE
as select a,c,e from dummy_union where type='type3';
Now I want to use the query rewrite feature; I set the proper
parameters:
alter system set query_rewrite_enabled=true;
alter session set optimizer_goal = first_rows;
alter session set query_rewrite_integrity = trusted;
This is fine :
SQL> select a, d from dummY_union where type='type2';
A D
---------- ----------
34 67
39 32
And this is fine as well:
SQL> select a from dummy_union where type='type3';
A
----------
900
HOWEVER:
SQL> select a from dummy_union where type='type3' or type='type2';
no rows selected
I would expect that the query rewrite will use a union on "CDr_type2" and
"CDR_type3." Is it possible to have a union used in query rewrite?
If so, how, and if not, can you offer a different solution? Partitioning is
not an option, since in the real world there are many different fields
between the tables, and making it one table with partitions is not an
option.
|