Constraint in Materialized View misbehave

Enviroment
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
s.o : windows 7. on laptop Intel core i7.
create table product_type
( product_type_id varchar2(3) constraint product_type_pk primary key,
product_type_name varchar2(100) constraint product_type_name_nn not null,
move_inv varchar2(1) default 'Y' constraint product_type_move_inv_nn not null,
generate_abc varchar2(1) default 'N' constraint product_type_generate_abc_nn not null,
constraint product_type_move_inv_check check (move_inv in ('Y','N')),
constraint product_type_gen_abc_check check (generate_abc in ('Y','N'))
create table product_class
( product_type_id varchar2(3) constraint product_class_type_id_nn not null,
product_class_id varchar2(3) constraint product_class_id_nn not null,
product_class_name varchar2(50) constraint product_class_name_nn not null,
inv_negative varchar2(1) default 'N' constraint product_class_inv_negative_nn not null,
constraint product_class_pk primary key (product_type_id,product_class_id),
constraint product_class_by_product_type foreign key (product_type_id) references product_type(product_type_id),
constraint product_class_inv_negative_chk check (inv_negative in ('Y','N'))
create materialized view log on product_type with rowid, primary key , sequence (move_inv) including new values;
create materialized view log on product_class with rowid, primary key , sequence (inv_negative) including new values;
create materialized view prd_type_val_prd_class
refresh fast on commit as
select count(*) tot_rows
from product_type pt
join product_class pc
on ( pt.product_type_id = pc.product_type_id )
where pt.move_inv = 'N' and pc.inv_negative = 'Y';
alter table prd_type_val_prd_class add constraint rows_in_prd_type_val_prd_class check( tot_rows < 1 );
-- sentence 1, expected to works
insert into product_type values('SAR','FARMA','N','N');
commit; --- WORKS fine.
-- sentence 2, expected to works
insert into product_class values('SAR','LIQ','LIQUID' ,'N');
commit; --- WORKS fine
-- sentence 3, expected to fail due materialized view constraint
insert into product_class values('SAR','CAP','CAPSULES','Y');
commit; ---> SHOW the materialized view constraint Error FINE!!!!!!
update product_type set move_inv = 'Y'; -- Update product type to allow sentence 3 to be ok
commit; ---> works fine
--- Re execute sentence 3 ----> success FINE!
---sentence 4, WORKS unexpected. --- it suppose to show the error, due materialized view constraint as did in sentence 3 (first try)
update product_type set move_inv = 'N';
commit; --- WORKS :( since this point ON the materialized view constraint error is show no More.... :(
insert into product_class values('SAR','TAB','TABLETS','Y');
commit;
insert into product_class values('SAR','ABC','ABCZXY','Y');
commit;
select count(*) tot_rows
from product_type pt
join product_class pc
on ( pt.product_type_id = pc.product_type_id )
where pt.move_inv = 'N' and pc.inv_negative = 'Y';
tot_rows
3
Any Idea why is this not working as expected??? maybe I'm missing something or is this a glitch???? hope is not.
thank you

luis,
I don't understand why your mv failed, but I tried it in a way I would do it, using an empty MV rather than one with a single rwos with 0 in it. i.e.:
create materialized view prd_type_val_prd_class
refresh fast on commit
as
select pt.product_type_id
      ,pc.product_type_id pc_bc_product_type_id
      ,pc.product_class_id
      ,pc.rowid pc_row_id
      ,pt.rowid pt_row_id
from product_type pt
   , product_class pc
where pt.bc_product_type_id = pc.bc_product_type_id
AND  pt.move_inv = 'N' and pc.inv_negative = 'Y';and changed the constraint to keep it empty:
alter table prd_type_val_prd_class add constraint rows_in_prd_type_val_prd_class check(1=0);Is it seemed to pass all your tests

Similar Messages

  • Materialized View - does not contain a primary key constraint

    I am trying to create materialized view. I gone through the MV wizard creation. Added 2 columns (foo_column, foo_pk) of the table and have a simple select statement (Select foo_column from foo_dim). Also created a primary key contrainst and refencing the primary key (FOO_PK) of the dimension.
    I am getting the following error:
    ORA-12014: table 'FOO_DIM' does not contain a primary key constraint

    It was solved. The table that I am querying has to have a primary key defined before creating a materialized view.

  • Can I create constraints "Primary key - Foreign key" on materialized views?

    Hello!
    Can I create constraints "Primary key - Foreign key" on materialized views like on tables?
    My purpose - is to make DB schema "COPY" with set of materialized views or tables, which take data from time to time from other tables situated.into another schema "ORIGINAL".
    Also - I want to use reporting tool, like Crystal Reports, to make nice reports from schema "COPY". To make nice reports, I need primary-foreign relationships between materialized views or tables in schema "COPY".
    Is it possible to use materialized views?
    Or I should use only tables to get such result?
    Thank you in advance.
    Edited by: kogotok1 on Dec 3, 2010 5:01 PM

    What happens when you try it? Or search the manuals.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_6002.htm#i2105365
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10706/repmview.htm#REPLN360

  • A bug when refreshing a materialized view?

    I am getting "ORA-00603: ORACLE server session terminated by fatal error" upon refresh of a materialized view. I've put together a test case to demonstrate the problem. Is it a bug?
    SQL*Plus: Release 10.1.0.3.0 - Production on Fri Jul 29 13:43:45 2005
    Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    [email protected]> create table t (
      2  id int primary key,
      3  t_name varchar2(10),
      4  t_date date
      5  );
    Table created.
    [email protected]> create materialized view log on t
      2    with rowid (t_name, id, t_date) including new values;
    Materialized view log created.
    [email protected]> create materialized view t_mv
      2   build immediate
      3   refresh fast
      4   on commit
      5  as
      6   select t_name, max(id) id, max(t_date) t_date, count(*)
      7     from t
      8    GROUP BY t_name;
    Materialized view created.
    [email protected]> create materialized view log on t_mv
      2    with rowid (id) including new values;
    Materialized view log created.
    [email protected]> create table v (
      2  id int primary key,
      3  t_id int references t(id) on delete cascade,
      4  v_name varchar2(10)
      5  );
    Table created.
    [email protected]> create materialized view log on v
      2    with rowid (v_name, t_id) including new values;
    Materialized view log created.
    [email protected]> create materialized view v_mv
      2   build immediate
      3   refresh fast
      4   on commit
      5  as
      6  select v.rowid rowid1, t_mv.rowid rowid2, v.v_name, v.t_id
      7  from v, t_mv
      8  where v.t_id = t_mv.id;
    Materialized view created.
    [email protected]> alter table v_mv
      2  add constraint v_mv_uk1 unique
      3  (
      4  v_name
      5  )
      6   enable
      7  ;
    Table altered.
    [email protected]> insert into t (id, t_name, t_date) values (1, 'A', sysdate);
    1 row created.
    [email protected]> insert into t (id, t_name, t_date) values (2, 'B', sysdate);
    1 row created.
    [email protected]> insert into t (id, t_name, t_date) values (3, 'A', sysdate);
    1 row created.
    [email protected]> insert into t (id, t_name, t_date) values (4, 'A', sysdate);
    1 row created.
    [email protected]> insert into t (id, t_name, t_date) values (5, 'B', sysdate);
    1 row created.
    [email protected]> insert into v (id, t_id, v_name) values (1, 1, 'V_A_1');
    1 row created.
    [email protected]> insert into v (id, t_id, v_name) values (2, 2, 'V_B_1');
    1 row created.
    [email protected]> insert into v (id, t_id, v_name) values (3, 3, 'V_A_2');
    1 row created.
    [email protected]> insert into v (id, t_id, v_name) values (4, 4, 'V_A_3');
    1 row created.
    [email protected]> insert into v (id, t_id, v_name) values (5, 5, 'V_B_2');
    1 row created.
    [email protected]> commit;
    Commit complete.
    [email protected]> insert into t (id, t_name, t_date) values (6, 'A', sysdate);
    1 row created.
    [email protected]> insert into v (id, t_id, v_name) values (6, 6, 'V_B_2');
    1 row created.
    [email protected]> commit;
    commit
    ERROR at line 1:
    ORA-12008: error in materialized view refresh path
    ORA-00001: unique constraint (FESA.V_MV_UK1) violated
    [email protected]> -- ORA-12008 is fine here: that's what was expected
    [email protected]> delete from t where id = 5;
    1 row deleted.
    [email protected]> commit;
    ERROR:
    ORA-03114: not connected to ORACLE
    commit
    ERROR at line 1:
    ORA-00603: ORACLE server session terminated by fatal errorWhy ORA-00603?
    Best regards,
    Maciej

    It may be a bug, or it may be a result of the dependencies between the materialized views. I don't have a 9.2.0.6 instance that I'm willing to trash to test this, but this is what I get on 9.2.0.1.
    If it is a bug they at least changed the behaviour of the bug in 9.2.0.6.
    I ran your script up to the first commit then did:
    SQL> SELECT * FROM t;
            ID T_NAME     T_DATE
             1 A          29-JUL-05
             2 B          29-JUL-05
             3 A          29-JUL-05
             4 A          29-JUL-05
             5 B          29-JUL-05
    SQL> SELECT * FROM t_mv;
    T_NAME             ID T_DATE      COUNT(*)
    A                   4 29-JUL-05          3
    B                   5 29-JUL-05          2
    SQL> SELECT * FROM v;
            ID       T_ID V_NAME
             1          1 V_A_1
             2          2 V_B_1
             3          3 V_A_2
             4          4 V_A_3
             5          5 V_B_2
    SQL> SELECT * FROM v_mv;
    no rows selectedHUH?? But:
    SQL> SELECT v.rowid rowid1, t_mv.rowid rowid2, v.v_name, v.t_id
      2  FROM v, t_mv
      3  WHERE v.t_id = t_mv.id;
    ROWID1             ROWID2             V_NAME           T_ID
    AAAH4QAAIAAAAl1AAD AAAH4MAAIAAAAlFAAA V_A_3               4
    AAAH4QAAIAAAAl1AAE AAAH4MAAIAAAAlFAAB V_B_2               5So, I tried:
    SQL> EXEC DBMS_MVIEW.REFRESH('V_MV');
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM v_mv;
    no rows selectedNow, this is confusing, so:
    SQL> EXEC DBMS_MVIEW.REFRESH('V_MV', 'COMPLETE');
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM v_mv;
    ROWID1             ROWID2             V_NAME           T_ID
    AAAH4dAAIAAAAl1AAD AAAH4ZAAIAAAAlFAAA V_A_3               4
    AAAH4dAAIAAAAl1AAE AAAH4ZAAIAAAAlFAAB V_B_2               5So at least I've got something in the MV. Now, to continue your test:
    SQL> insert into t (id, t_name, t_date) values (6, 'A', sysdate);
    1 row created.
    SQL> insert into v (id, t_id, v_name) values (6, 6, 'V_B_2');
    1 row created.
    SQL> COMMIT;
    Commit complete.I also expected the error but no joy, and look at this:
    SQL> SELECT * FROM v_mv;
    ROWID1             ROWID2             V_NAME           T_ID
    AAAH4dAAIAAAAl1AAE AAAH4ZAAIAAAAlFAAB V_B_2               5Forcing the refresh on v_mv gets:
    SQL> EXEC DBMS_MVIEW.REFRESH('V_MV', 'COMPLETE');
    BEGIN DBMS_MVIEW.REFRESH('V_MV', 'COMPLETE'); END;
    ERROR at line 1:
    ORA-12008: error in materialized view refresh path
    ORA-00001: unique constraint (OPS$ORACLE.V_MV_UK1) violatedVery strange! It gets better:
    SQL> DELETE FROM t WHERE id = 5;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL> EXEC DBMS_MVIEW.REFRESH('V_MV', 'COMPLETE');
    PL/SQL procedure successfully completed.
    SQL> select * from v_mv;
    ROWID1             ROWID2             V_NAME           T_ID
    AAAH4dAAIAAAAl1AAF AAAH4ZAAIAAAAlFAAA V_B_2               6 But:
    SQL> SELECT * FROM t_mv;
    T_NAME             ID T_DATE      COUNT(*)
    A                   6 29-JUL-05          4
    B                   5 29-JUL-05          2
    SQL> SELECT * FROM t;
            ID T_NAME     T_DATE
             1 A          29-JUL-05
             2 B          29-JUL-05
             3 A          29-JUL-05
             4 A          29-JUL-05
             6 A          29-JUL-05Obvioulsy, something is not fast refreshing. So lets force it:
    SQL> EXEC DBMS_MVIEW.Refresh('T_MV', 'COMPLETE');
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM t_mv;
    T_NAME             ID T_DATE      COUNT(*)
    A                   6 29-JUL-05          4
    B                   2 29-JUL-05          1
    SQL> SELECT * FROM v_mv;
    ROWID1             ROWID2             V_NAME           T_ID
    AAAH4dAAIAAAAl1AAB AAAH4qAAIAAAAlEAAB V_B_1               2
    AAAH4dAAIAAAAl1AAF AAAH4qAAIAAAAlEAAA V_B_2               6Which looks right to me.
    Then, I blew everything away and did it allagain up to an including the inserts into t, then I inserted into v and commited. Now, both MV's were correct, so I did:
    SQL> insert into t (id, t_name, t_date) values (6, 'A', sysdate);
    1 row created.
    SQL> insert into v (id, t_id, v_name) values (6, 6, 'V_B_2');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> SELECT * FROM t_mv;
    T_NAME             ID T_DATE      COUNT(*)
    A                   6 29-JUL-05          4
    B                   5 29-JUL-05          2Still strange, so blow it all away again insert into t commit, insert into v commit, then:
    SQL> insert into t (id, t_name, t_date) values (6, 'A', sysdate);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> insert into v (id, t_id, v_name) values (6, 6, 'V_B_2');
    1 row created.
    SQL> commit;
    commit
    ERROR at line 1:
    ORA-12008: error in materialized view refresh path
    ORA-00001: unique constraint (OPS$ORACLE.V_MV_UK1) violatedAt least now it sees the error at commit time for v so lets try the delete:
    SQL> delete from t where id = 5;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL> SELECT * FROM t_mv;
    T_NAME             ID T_DATE      COUNT(*)
    A                   6 29-JUL-05          4
    B                   5 29-JUL-05          2
    SQL> SELECT * FROM t;
            ID T_NAME     T_DATE
             1 A          29-JUL-05
             2 B          29-JUL-05
             3 A          29-JUL-05
             4 A          29-JUL-05
             6 A          29-JUL-05Still not actually refreshing somehow.
    I may play with this some more, it seems truly strange to me.
    John

  • Materialized view taking long time to refresh

    I want to understand why materialized view refresh takes more time than running the sql for the materialized view.
    For example say I have a materialized view test_mv which is created as below; When I run just the select statement i get the result within 34 secs whereas if I try to refresh it using
    BEGIN
    DBMS_MVIEW.refresh ('wi_mv7_monthly','C',ATOMIC_REFRESH=>false);
    end;
    /This takes around 74 secs
    MV creation
    Oracle version : Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    create materialized view TEST_MV
      COLUMN_NAME_1,
      OBJECT_NAME,
      COLUMN_ID,
      "SUM(C.DATA_LENGTH)"
    ) organization heap
    partition by list (COLUMN_ID) (
    PARTITION "first_10_col" VALUES
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10
       PARTITION "After_10_col" VALUES
        11,12, 13, 14, 15, 16, 17, 18, 19, 20
       PARTITION "NONE" VALUES (DEFAULT)
    BUILD IMMEDIATE USING INDEX REFRESH COMPLETE ON DEMAND USING DEFAULT LOCAL ROLLBACK SEGMENT USING ENFORCED CONSTRAINTS
    as
    select  /*+ parallel(o,8) parallel(c,2) */
    C.COLUMN_NAME as COLUMN_NAME_1,O.OBJECT_NAME,C.COLUMN_ID,SUM(C.DATA_LENGTH) from ALL_OBJECTS O
    join ALL_tab_columns c on c.table_name=o.object_name
    group by
    C.COLUMN_NAME,O.OBJECT_NAME,C.COLUMN_IDEdited by: user627047 on Sep 6, 2012 6:56 AM

    I want to understand why materialized view refresh takes more time than running the sql for the materialized view.Mview has to save the data as well .

  • Materialized view takes long to refresh

    On Oracle 11g2, I created a materialized view fast refresh on commit CREATE MATERIALIZED VIEW mv_case
    PARALLEL BUILD IMMEDIATE REFRESH FAST ON COMMIT ENABLE QUERY REWRITE AS
    SELECT p.jperson_id,offense_id,CASE_SENTENCE_DATE,court_ref,CASE_COURT_ORI,
      c.CASE_VERDICT_DATE,CASE_DOCKET,c.CASE_EXPUNGED,c.jcase_id,cc.CYCLEID_ID,
      p.rowid p_rowid,xc.rowid xc_rowid,c.rowid c_rowid,cxo.rowid cxo_rowid,cc.rowid cc_row_id
    FROM jperson p,jperson_x_jcase xc,jcase c,jcase_x_offense cxo,jcase_x_cycleid cc
    where p.jperson_id = xc.jperson_id(+) and xc.jcase_id = c.jcase_id(+)
      and c.jcase_id = cxo.jcase_id(+) and c.jcase_id=cc.jcase_id;
    create index idx_mv_case_pid on mv_case(jperson_id);
    ALTER TABLE mv_case ADD (CONSTRAINT PK_MV_CASE PRIMARY KEY(jcase_id,offense_id)) ;
    create index idx_mv_case_p_rowid on mv_case(p_rowid);
    create index idx_mv_case_xc_rowid on mv_case(xc_rowid);
    create index idx_mv_case_c_rowid on mv_case(c_rowid);
    create index idx_mv_case_cxo_rowid on mv_case(cxo_rowid);
    create index idx_mv_case_cc_rowid on mv_case(cc_row_id); I inserted one single row into one of the master table
    insert into jcase_x_offense (offense_id,jcase_id) values ('test_row3','test_row3');
    commit; The commit tooks a quite long. I looked into the trace file and the actual insert took 0.01 seconds but one of the internel DML took most of time. I copy the relevant TKPROF output for the internal DML belowINSERT INTO QAPF.MV_CASE SELECT /*+ NO_MERGE(JV$) */
      MAS$4.JPERSON_ID,JV$.OFFENSE_ID,MAS$2.CASE_SENTENCE_DATE,
      MAS$2.COURT_REF,MAS$2.CASE_COURT_ORI,MAS$2.CASE_VERDICT_DATE,
      MAS$2.CASE_DOCKET,MAS$2.CASE_EXPUNGED,MAS$2.JCASE_ID,
      MAS$0.CYCLEID_ID,MAS$4.ROWID,MAS$3.ROWID,MAS$2.ROWID,JV$.RID$,
      MAS$0.ROWID
      FROM ( SELECT MAS$.ROWID RID$  ,  MAS$.*  FROM  QAPF.JCASE_X_OFFENSE MAS$ WHERE ROWID IN
              (SELECT  /*+ HASH_SJ */ CHARTOROWID(MAS$.M_ROW$$) RID$
               FROM QAPF.MLOG$_JCASE_X_OFFENSE MAS$ WHERE MAS$.XID$$ = :1 )) JV$,
      JCASE_X_CYCLEID AS OF SNAPSHOT(:B_SCN)  MAS$0, JCASE AS OF SNAPSHOT(:B_SCN)  MAS$2,
      JPERSON_X_JCASE AS OF SNAPSHOT(:B_SCN)  MAS$3, JPERSON AS OF SNAPSHOT(:B_SCN)  MAS$4
      WHERE (MAS$4.JPERSON_ID=MAS$3.JPERSON_ID(+)
      AND MAS$3.JCASE_ID=MAS$2.JCASE_ID(+)
      AND MAS$2.JCASE_ID=JV$.JCASE_ID(+)
      AND MAS$2.JCASE_ID=MAS$0.JCASE_ID)
      AND NOT EXISTS (
        SELECT 1 FROM QAPF.MV_CASE SNA2$
        WHERE (SNA2$.P_ROWID = MAS$4.ROWID)
        AND (SNA2$.XC_ROWID = MAS$3.ROWID OR MAS$3.ROWID IS NULL )
        AND (SNA2$.C_ROWID = MAS$2.ROWID OR MAS$2.ROWID IS NULL )
        AND (SNA2$.CC_ROW_ID = MAS$0.ROWID OR MAS$0.ROWID IS NULL )
        AND JV$.RID$ IS NULL)
      AND NOT EXISTS (
        SELECT 1  FROM JCASE_X_OFFENSE MAS_INNER$, JCASE AS OF SNAPSHOT(:B_SCN)  MAS_OUTER$
        WHERE MAS$2.ROWID = MAS_OUTER$.ROWID AND JV$.RID$ IS NULL
        AND MAS_OUTER$.JCASE_ID=MAS_INNER$.JCASE_ID)
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1     99.51     364.87     377012   17412972          1           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        2     99.51     364.87     377012   17412972          1           0
    Rows     Row Source Operation
          0  LOAD TABLE CONVENTIONAL  (cr=17412968 pr=377012 pw=120527 time=0 us)
          0   FILTER  (cr=17412968 pr=377012 pw=120527 time=0 us)
    3363837    HASH JOIN RIGHT OUTER (cr=264914 pr=280254 pw=120527 time=35845080 us cost=299444 size=1029332286 card=3363831)
          1     VIEW  (cr=112490 pr=180864 pw=119722 time=0 us cost=30743 size=78 card=1)
          1      HASH JOIN SEMI (cr=112490 pr=180864 pw=119722 time=0 us cost=72627 size=208 card=1)
    11354346       TABLE ACCESS FULL JCASE_X_OFFENSE (cr=112488 pr=112447 pw=0 time=4814838 us cost=30703 size=749386770 card=11354345)
          1       TABLE ACCESS BY INDEX ROWID MLOG$_JCASE_X_OFFENSE (cr=2 pr=0 pw=0 time=0 us cost=1 size=142 card=1)
          1        INDEX RANGE SCAN IDX_MLOG$_XID_JCASE_X_OFFENSE (cr=1 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 98375)
    3363837     HASH JOIN  (cr=152424 pr=99390 pw=805 time=29973970 us cost=268690 size=766953468 card=3363831)
    2994042      INDEX FAST FULL SCAN JPERSON_I0 (cr=18134 pr=0 pw=0 time=772990 us cost=17450 size=134731845 card=2994041)(object id 83738)
    3363837      HASH JOIN  (cr=134290 pr=99390 pw=805 time=25292580 us cost=212128 size=615581073 card=3363831)
    3363837       HASH JOIN  (cr=69008 pr=34127 pw=805 time=4750330 us cost=101637 size=393568929 card=3363837)
    3363837        TABLE ACCESS FULL JCASE_X_CYCLEID (cr=33337 pr=33322 pw=0 time=2942460 us cost=33569 size=222013242 card=3363837)
    6586646        TABLE ACCESS FULL JCASE (cr=35671 pr=0 pw=0 time=1584102 us cost=35988 size=335918895 card=6586645)
    6586635       TABLE ACCESS FULL JPERSON_X_JCASE (cr=65282 pr=65263 pw=0 time=5446686 us cost=65632 size=434717844 card=6586634)
    3363837    FILTER  (cr=17148054 pr=96758 pw=0 time=0 us)
    3363837     MAT_VIEW ACCESS BY INDEX ROWID MV_CASE (cr=17148054 pr=96758 pw=0 time=0 us cost=7 size=40 card=1)
    32464070      INDEX RANGE SCAN IDX_MV_CASE_P_ROWID (cr=4489770 pr=15250 pw=0 time=19576798 us cost=3 size=0 card=7)(object id 98467)
          0    FILTER  (cr=0 pr=0 pw=0 time=0 us)
          0     NESTED LOOPS  (cr=0 pr=0 pw=0 time=0 us cost=4 size=78 card=1)
          0      TABLE ACCESS BY USER ROWID JCASE (cr=0 pr=0 pw=0 time=0 us cost=1 size=45 card=1)
          0      INDEX RANGE SCAN JCASE_X_OFFENSE_I0 (cr=0 pr=0 pw=0 time=0 us cost=3 size=33 card=1)(object id 83623)Questions:
    1) what are the objects like JCASE AS OF SNAPSHOT(:B_SCN) ? Can I index them? I tried access it but got error
    select * from JCASE AS OF SNAPSHOT(:B_SCN) ;
    ORA-08187: snapshot expression not allowed here
    08187. 00000 - "snapshot expression not allowed here"
    *Cause:    A snapshot expression using AS OF was specified when not allowed.
    *Action:   Do not use the AS OF clause
    2) In the inline view following the firs FROM, it used ROWID in where clause. I tried create an index on ROWID, and error
    create index idx_jcase_offense_rid on JCASE_X_OFFENSE(rowid)
    ERROR at line 1:
    ORA-00904: : invalid identifier
    Note: I checked that I have indexes all fields in all where clauses in the DML except rowid.
    Thanks for help.

    sybrand_b wrote:
    1 Apparently Oracle is using Flashback technology when no materialized view logs have been set up
    As your MV is a complex MV it is not a candidate for FAST REFRESH ON COMMIT.
    I haven't looked closely at how 11.2 has changed the "fast refresh on commit" - but I would have expected it to raise an Oracle error when the OP tried to create the materialized view with that option if it were not possible.
    I think your first comment is probably the more important one - if the user sets up suitable materialized view logs on all the tables in the outer join then it's possible that the fast refresh could work properly.
    This is pure speculation, of course, based on the absence of an error message.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
    There is a +"Preview"+ tab at the top of the text entry panel. Use this to check what your message will look like before you post the message. If it looks a complete mess you're unlikely to get a response. (Click on the +"Plain text"+ tab if you want to edit the text to tidy it up.)
    +"Science is more than a body of knowledge; it is a way of thinking"+
    +Carl Sagan+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How can I create a materialized view based on hierarchical cube query?

    Hi,
    database version 10gR2.
    When i try to create MV for sql below, i got error .
    I tried creating MV log in several ways, but still, keep getting the same error.
    SQL Error: ORA-12015: cannot create a fast refresh materialized view from a complex query
    12015. 00000 -  "cannot create a fast refresh materialized view from a complex query"
    *Cause:    Neither ROWIDs and nor primary key constraints are supported for
               complex queries.
    *Action:   Reissue the command with the REFRESH FORCE or REFRESH COMPLETE
               option or create a simple materialized view.So, I wonder if it is possible to create MV based on sql below?
    if yes, how should I do it?
    if no, what is the alternative?
    select
          coalesce(UP_ORG_ID_6, UP_ORG_ID_5, UP_ORG_ID_4, UP_ORG_ID_3, UP_ORG_ID_2, UP_ORG_ID_1) as ORG_ID,
          a.day_id as day_id,     
          a.TRADE_TYPE_ID as TRADE_TYPE_ID,
          a.CUST_ID,
          coalesce(UP_CODE_6, UP_CODE_5, UP_CODE_4, UP_CODE_3, UP_CODE_2, UP_CODE_1) as product_id,
          QUANTITY_UNIT,
          COST_UNIT,
          A.SOURCE_ID as SOURCE_ID,
          SUM(CONTRACT_AMOUNT) as CONTRACT_AMOUNT,
          SUM(CONTRACT_COST) as CONTRACT_COST,
          SUM(SALE_AMOUNT) as SALE_AMOUNT,
          SUM(SALE_COST) as SALE_COST,
          SUM(ACTUAL_AMOUNT) as ACTUAL_AMOUNT,
          SUM(ACTUAL_COST) as ACTUAL_COST,
          SUM(TRADE_COUNT) as TRADE_COUNT     
    from DM_F_LO_SALE_DAY a, DM_D_ALL_ORG_FLAT B, DM_D_ALL_PROD_FLAT D
    where a.ORG_ID=B.ORG_ID
          and a.PRODUCT_ID=D.CODE
          and a.day_id=20110201
    group by rollup(UP_ORG_ID_1, UP_ORG_ID_2, UP_ORG_ID_3, UP_ORG_ID_4, UP_ORG_ID_5, UP_ORG_ID_6),
          a.TRADE_TYPE_ID,
             a.day_id,
          A.CUST_ID,
          rollup(UP_CODE_1, UP_CODE_2, UP_CODE_3, UP_CODE_4, UP_CODE_5, UP_CODE_6),
          a.QUANTITY_UNIT,
          a.COST_UNIT,
          a.SOURCE_ID;Thanks in advance.

    Rob vanWjik has an excellent series of fast refresh materialized views starting here:
    http://rwijk.blogspot.com/2009/05/fast-refreshable-materialized-view.html
    Part three specifically on aggregate MVs is here:
    http://rwijk.blogspot.com/2009/06/fast-refreshable-materialized-view.html

  • Materialized view to ensure data integrity over multiple tables

    Hello,
    I have a problem and I am not able to solve it. Partially, It is because of my poor SQL skills. I have three tables and I am using one sequence to enter data into them.
    What I am tying to do is to create a materialized view ( complete or fast, whichever) with refresh on commit option to check that each table contains unique data in comparison to other.
    I am posting code so you can get along:
    CREATE TABLE table_1 (
    ID NUMBER PRIMARY KEY
    CREATE TABLE table_2 (
    ID NUMBER PRIMARY KEY
    CREATE TABLE table_3 (
    ID NUMBER PRIMARY KEY
    INSERT INTO table_1 VALUES (1);
    INSERT INTO table_1 VALUES (2);
    INSERT INTO table_2 VALUES (3);
    INSERT INTO table_2 VALUES (4);
    INSERT INTO table_3 VALUES (5);
    INSERT INTO table_3 VALUES (6); I want to write create a materialized view that will give me output only in case that there are same values in two different tables. I got this far.
    CREATE MATERIALIZED view mv_test
    REFRESH COMPLETE ON COMMIT
    AS
    SELECT count(1) ROW_COUNT
    FROM dual
    WHERE EXISTS (
         SELECT a.id
         FROM table_1 a
         WHERE a.id IN(
             SELECT b.id
             FROM table_2 b))
    OR EXISTS (
        SELECT a.id
         FROM table_1 a
         WHERE a.id IN
                 (SELECT c.id
                 FROM table_3 c))
    OR EXISTS (
        SELECT b.id
             FROM table_2 b
        WHERE b.id IN
                 (SELECT c.id
                 FROM table_3 c));
        ALTER MATERIALIZED VIEW mv_test
        ADD CONSTRAINT cs_mv_test
        CHECK (row_count = 0) DEFERRABLE; This sql statement itself returns no rows if my logic is correct. And in case there were some duplicate rows in two different table, it would return 1 and constraint would throw an error.
    However, I cannot create this with ON COMMIT option. When I try to compile I get:
    ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view I went through documentation, tried creating mat_view logs etc.
    I know that one of the mistakes is that I am referencing dual table and I am not sure if I can use EXISTS.
    Unfortunately, my SQL wisdom ends here. I need help rewriting the sql, so it would work in materialized view with refresh on commit option. Please, help!!!
    I know that since I am using a sequence there is little chance that same value will get into two different tables, but I would like to perform somekind of check.
    Thank you in advance.

    >
    I know that since I am using a sequence there is little chance that same value will get into two different tables, but I would like to perform somekind of check.If you are certain that you control all the inputs to the table and you are definitely using one sequence to insert into all three tables then there is physically no possible way you will get duplicate values across tables.
    Writing something to check if this is the case would almost be like writing something to verify that 1+1 really does equal 2 in 100% of cases.
    if you must, however. consider something similar to the following which may be more performant:
    select *
      from table_1 t1
      full outer join table_2 t2 on (t1.id = t2.id)
      full outer join table_3 t3 on (t1.id = t2.id
                                     or
                                     t2.id = t3.id)
    where t1.id+t2.id+t3.id not in (t1.id,t2.id,t3.id);

  • Create a materialized view on a base view

    I want to create a materialized view on a master view (ordinary view, not a mat. view). But i can not make it work. can it work? I have created a primary key on the master view as:
    create or replace force view v_xxx(a, b)
    unique rely disable novalidate,
    constraint a_pk primary key (a) rely disable novalidate)
    as select a ,b
    from xxx
    When I then try to create the mat. view:
    create materialized view mv_xxx refresh complete
    with primary key
    as
    select * from [email protected]
    I get:
    ORA-12014: table 'V_xxx' does not contain a primary key constraint
    What am I doing wrong?

    I suppose OP is on a 9i db (cause I can't reproduce on 11gr2) and the error is because of the database link:
    SQL> create table emp_t
    as
       select * from emp
    Table created.
    SQL> create or replace view v_emp_t
       empno   constraint v_emp_t_pk primary key rely disable novalidate,
       ename
    as
       select empno, ename from emp_t
    View created.
    SQL> create materialized view mv_emp_t refresh complete
    with primary key
    as
    select * from v_emp_t
    Materialized View created.
    SQL> drop materialized view mv_emp_t
    Materialized View dropped.
    SQL> create materialized view mv_emp_t refresh complete
    with primary key
    as
    select * from v_emp_t@loopback
    Error at line 32
    ORA-12014: table 'V_EMP_T' does not contain a primary key constraintYou can wrap the view with the db link in another view though:
    SQL> create or replace view v_emp_t2
       empno   constraint v_emp_t2_pk primary key rely disable novalidate,
       ename
    as
       select empno, ename from v_emp_t@loopback
    View created.
    SQL> create materialized view mv_emp_t refresh complete
    with primary key
    as
    select * from v_emp_t2
    Materialized View created.

  • How to create a Complex Organization Index  Materialized View Example

    Hi
    I have a 11g database that I'm trying to create a complex Materialized View that I would like to make Organization Index? How do I specify what I want for a primary Key?
    CREATE MATERIALIZED VIEW RCS_STG.MV_NEXT_HOP_iot
    ORGANIZATION INDEX
    AS
    SELECT r2.resource_key, r1.resource_key resource_key2, r2.resource_full_path_name, device_name, device_model,
    service_telephone_number, service_package_name, telephone_number.telephone_number_key, c1.created_on
    FROM network_resource PARTITION (network_resource_subinterface) r1,
    connection c1,
    network_resource PARTITION (network_resource_subinterface) r2,
    device d1,
    tn_network_resource,
    telephone_number
    WHERE r1.resource_key = c1.resource1_key
    AND c1.resource2_key = r2.resource_key
    AND d1.device_key = r2.device_key
    AND tn_network_resource.resource_key(+) = r2.resource_key
    AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key
    UNION ALL
    SELECT r1.resource_key, r2.resource_key resource_key2, r1.resource_full_path_name, device_name, device_model,
    service_telephone_number, service_package_name, telephone_number.telephone_number_key, c1.created_on
    FROM network_resource PARTITION (network_resource_subinterface) r1,
    connection c1,
    network_resource PARTITION (network_resource_subinterface) r2,
    device d1,
    tn_network_resource,
    telephone_number
    WHERE r1.resource_key = c1.resource1_key
    AND c1.resource2_key = r2.resource_key
    AND d1.device_key = r1.device_key
    AND tn_network_resource.resource_key(+) = r1.resource_key
    AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key
    I get an error message ORA-25175: no PRIMARY KEY constraint found
    I would like to specify resource_key, resource_key2, and service_telephone_number as my primary key?

    Ah,
    I get it now. This is what I did.
    CREATE TABLE mv_next_hop_iot
    resource_key NUMBER (38),
    resource_key2 NUMBER (38),
    resource_full_path_name VARCHAR2 (256 BYTE),
    device_name VARCHAR2 (64 BYTE),
    device_model VARCHAR2 (64 BYTE),
    service_telephone_number VARCHAR2 (20 BYTE),
    service_package_name VARCHAR2 (64 BYTE),
    telephone_number_key NUMBER (38),
    created_on DATE,
    CONSTRAINT mv_next_hop_pk PRIMARY KEY (resource_key, resource_key2, service_telephone_number)
    ORGANIZATION INDEX
    CREATE MATERIALIZED VIEW rcs_stg.mv_next_hop_iot
    ON PREBUILT TABLE
    AS
    /* Formatted on 2010/06/10 1:39:04 PM (QP5 v5.149.1003.31008) */
    SELECT resource_key, resource_key2, resource_full_path_name, device_name, device_model, service_telephone_number,
    service_package_name, telephone_number_key, created_on
    FROM (SELECT r2.resource_key, r1.resource_key resource_key2, r2.resource_full_path_name, device_name, device_model,
    NVL (service_telephone_number, ' ') AS service_telephone_number, service_package_name,
    telephone_number.telephone_number_key, c1.created_on
    FROM network_resource PARTITION (network_resource_subinterface) r1,
    connection c1,
    network_resource PARTITION (network_resource_subinterface) r2,
    device d1,
    tn_network_resource,
    telephone_number
    WHERE r1.resource_key = c1.resource1_key
    AND c1.resource2_key = r2.resource_key
    AND d1.device_key = r2.device_key
    AND tn_network_resource.resource_key(+) = r2.resource_key
    AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key
    UNION ALL
    SELECT r1.resource_key, r2.resource_key resource_key2, r1.resource_full_path_name, device_name, device_model,
    NVL (service_telephone_number, ' ') AS service_telephone_number, service_package_name,
    telephone_number.telephone_number_key, c1.created_on
    FROM network_resource PARTITION (network_resource_subinterface) r1,
    connection c1,
    network_resource PARTITION (network_resource_subinterface) r2,
    device d1,
    tn_network_resource,
    telephone_number
    WHERE r1.resource_key = c1.resource1_key
    AND c1.resource2_key = r2.resource_key
    AND d1.device_key = r1.device_key
    AND tn_network_resource.resource_key(+) = r1.resource_key
    AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key)
    Many thanks. the PREBUILT TABLE is the secret.

  • How to add an index to a materialized view in Data Modeler 3.3

    Hello everyone,
    I'm looking for a how-to to add an index to a materialized view in Data Modeler 3.3.0.747, as I coudn't find a way to do it so far.
    I looked here:
    Relational Model
    Physical Model
    Oracle 11g
    Materialized Views
    "my_mv_name"
    "INDEXES" IS NOT HERE IN THE TREE
    "Tables" does not include it either
    Thank you & Best regards,
    Blama

    Hi David,
    thanks a lot. I did so and it worked, but I found a minor bug while doing so:
    I marked the table as "Implement as Materialized View" and went to File->Export->DDL (for Oracle 11g).
    The generated code (I checked all options in "Drop Selection") includes a row:
    DROP MATERIALIZED VIEW mv_mymatview CASCADE CONSTRAINTS ;
    which produces a syntax error.
    Best regards,
    Blama

  • Error While Creating Fast Refresh Materialized view.

    Table Scripts:
    CREATE TABLE CONTRACT_MASTER
      CONTRACT_SEQ                    NUMBER(10)    NOT NULL,
      PDN                             CHAR(5)       NOT NULL,
      APPID                           NUMBER(10)    NOT NULL,
      CONTRACT_LOB_DESC               VARCHAR2(20)  NOT NULL,
      CUSTOMER_NAME                   VARCHAR2(57)  NOT NULL,
      CONTRACT_DT                     DATE          NOT NULL,
      CONTRACT_RECD_DT                DATE          NOT NULL,
      HELD_OFFERING_DT                DATE          NOT NULL,
      DRAFT_AMT                       NUMBER(15,2)  NOT NULL,
      STATUS_DESC                                   VARCHAR2(20)  NOT NULL,
      GIF_UPLOAD_TM                                            TIMESTAMP     NOT NULL
    CREATE table CONTRACT_COMMENTS
      CONTRACT_COMMENTS_SEQ           NUMBER(10)     NOT NULL,
      APPID                           NUMBER(10)     NOT NULL,
      COMMENTS                        VARCHAR2(1000) NOT NULL,
      GIF_UPLOAD_TM                                            TIMESTAMP      NOT NULL
    Constraints on tables
    ALTER TABLE CONTRACT_MASTER ADD
      CONSTRAINT XPKCONTRACT_MASTER PRIMARY KEY (CONTRACT_SEQ) USING INDEX ;
    ALTER TABLE CONTRACT_COMMENTS ADD
      CONSTRAINT XPKCONTRACT_COMMENTS PRIMARY KEY (CONTRACT_COMMENTS_SEQ) USING INDEX ;
    alter table CONTRACT_MASTER add CONSTRAINT XUIAPPCONTRACT_MASTER UNIQUE (APPID) USING INDEX;
    CREATE INDEX XUIAPPCONTRACT_COMMENTS ON
    CONTRACT_COMMENTS(APPID) ;
    Materialized View Creation:
    CREATE MATERIALIZED VIEW LOG ON CONTRACT_MASTER WITH PRIMARY KEY,ROWID;
    CREATE MATERIALIZED VIEW LOG ON CONTRACT_COMMENTS WITH PRIMARY KEY, ROWID;
    CREATE MATERIALIZED VIEW MV_CONTRACT_COMMENTS_HELDOFFERING
    REFRESH FAST
    ENABLE QUERY REWRITE AS
    SELECT APPID,COMMENTS FROM CONTRACT_COMMENTS  WHERE APPID IN (
    SELECT APPID FROM CONTRACT_MASTER WHERE STATUS_DESC = 'Held Offering' )
    Errors generated:
    ERROR at line 4:
    ORA-12015: cannot create a fast refresh materialized view from a complex query
    _*Afer That I have changed the query but still it was not created like:*_
    CREATE  MATERIALIZED VIEW MV_CONT_COMMNTS_HELDOFFERNG
    REFRESH FAST
    ENABLE QUERY REWRITE AS
    SELECT CONTRACT_COMMENTS_SEQ,c.APPID,COMMENTS
    FROM CONTRACT_COMMENTS c,CONTRACT_MASTER  m 
    WHERE m.APPID = c.APPID and m.STATUS_DESC = 'Held Offering'
    *even though error displayed:
    SQL> CREATE  MATERIALIZED VIEW MV_CONT_COMMNTS_HELDOFFERNG*
       2  REFRESH FAST
       3  ENABLE QUERY REWRITE AS
       4  SELECT CONTRACT_COMMENTS_SEQ,c.APPID,COMMENTS
       5  FROM CONTRACT_COMMENTS c,CONTRACT_MASTER  m
       6  WHERE m.APPID = c.APPID and m.STATUS_DESC = 'Held Offering';
    FROM CONTRACT_COMMENTS c,CONTRACT_MASTER  m
    ERROR at line 5:
    ORA-12052: cannot fast refresh materialized view GSSIO.MV_CONT_COMMNTS_HELDOFFERNG
    *Again I have done "Analyzing Materialized Views for Fast Refresh" as follows:*
    1: exec dbms_mview.explain_mview('MV_CONT_COMMNTS_HELDOFFERNG');
    2: SELECT capability_name,  possible, SUBSTR(msgtxt,1,60) AS msgtxt
               FROM mv_capabilities_table
               WHERE capability_name like '%FAST%';
    Output is :
    CAPABILITY_NAME                               P              MSGTXT                                                            
    REFRESH_FAST                                   N                                                                   
    REFRESH_FAST_AFTER_INSERT            N  the SELECT list does not have the rowids of all the detail t      
    REFRESH_FAST_AFTER_ONETAB_DML   N  see the reason why REFRESH_FAST_AFTER_INSERT is disabled          
    REFRESH_FAST_AFTER_ANY_DML         N  see the reason why REFRESH_FAST_AFTER_ONETAB_DML is disabled      
    REFRESH_FAST_PCT                            N  PCT is not possible on any of the detail tables in the mater      
    Please suggest what to do to implement fast refresh materialized view for same.Edited by: dba on Sep 20, 2010 12:00 AM

    If the two MVs have to be consistent with each other as of a specific time, put them into a Refresh Group and refresh them with DBMS_MVIEW.REFRESH
    If an MV is dependent on another, use DBMS_MVIEW.REFRESH_DEPENDENT
    See the "Oracle® Database PL/SQL Packages and Types Reference" documentation pages for DBMS_MVIEW.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com --- this is NOT a documentation site.
    Edited by: Hemant K Chitale on Sep 20, 2010 5:19 PM

  • Error on creation of Materialized view

    Hi all, how are u? :-D
    Well, I´m trying to use MATERIALIZED VIEW with refresh fast,
    when first I grant permissions on the table action to an user,
    after I create the MATERIALIZED VIEW LOG on the master and, finally,
    I create the MATERIALIZED VIEW on the target.
    -- using other_user:
    GRANT SELECT, INSERT, UPDATE, DELETE ON action TO an_user;
    CREATE MATERIALIZED VIEW LOG ON action
       WITH PRIMARY KEY;
    -- using an_user:
    CREATE MATERIALIZED VIEW vw_action
    REFRESH FAST
    START WITH sysdate
    NEXT TRUNC(sysdate) + 1/24
    AS SELECT * FROM other_user.action;But, when I perform the CREATE MATERIALIZED VIEW the following error occurs:
    ERROR at line 5:
    ORA-12018: following error encountered during code generation for "AN_USER"."VW_ACTION"
    ORA-00942: table or view does not exist
    When I execute the query SELECT * FROM other_user.action, the data are returned.
    What can it to be?
    What´s the problem in this case?
    Thank you very much!
    []´s

    Hi Nicolas,
    Well, I´m using Oracle 9.2.0.1 with Linux Red Hat.
    I tryid without synonym and with synonym too, but...
    I´m gonna to search for a solution.
    And I´m gonna to try use the action recommended by oracle:
    ORA-12015 cannot create a fast refresh materialized view from a complex query
    Cause: Neither ROWIDs nor primary key constraints are supported for complex queries.
    Action: Reissue the command with the REFRESH FORCE or REFRESH COMPLETE option or create a simple materialized view.thank you very much!
    []´s

  • Creation of Materialized view and Materialized view log.

    I wanted to create materialized view with 'REFRESH FAST ON COMMIT' option.
    1) Table1 --it is partitioned range + list -- Added primary key
    2) view1   -- having primary keys on view's base table
    Steps:
    1) create materialized view log on Table1 ; -- default primary key
    2) create materialized view log on view1.  --- It is giving below error.
    ORA-00942: table or view does not exist
    i wanted to create Materialized view like below
    create materialized view
    REFRESH fast ON commit
    as
    select ...
    ... from table1
    where c1 in (select c1 from view1 where ... );
    Question:
    1) As i am getting above error while creating MV log on view. Can we create MV log on view or we have to create MV log on view base table?
    2) To create MV with ''REFRESH FAST ON COMMIT' option , do we need to have primary key on master tables? 
    Any pointers on this will really helpful.
    Thanks
    Prasad

    Also created MV LOG on 3 tables and tried with joins ..
    create materialized view
    REFRESH fast ON commit
    as
    select ...
    ... from table1 , tab2 t2,tab3 t3
    where ....
    and ...
    Get same error ORA-12052: cannot fast refresh materialized view AVSYS.EVENT_LOG_MV
    2052. 00000 -  "cannot fast refresh materialized view %s.%s"
    *Cause:    Either ROWIDs of certain tables were missing in the definition or
               the inner table of an outer join did not have UNIQUE constraints on
               join columns.
    *Action:   Specify the FORCE or COMPLETE option. If this error is got
               during creation, the materialized view definition may have be
               changed. Refer to the documentation on materialized views.

  • Fast refresh of a materialized view works incorrect

    Hi All,
    I have created a MV using the sql below:
    create materialized view WLS
    refresh fast
    enable query rewrite
    as
    SELECT Employees.USER_NAME,
           Permissions.ROLE_NAME,
           Vouchers.VOUCHER_ID,
           EmployeeRoles.FROM_DATE,
           EmployeeRoles.TO_DATE,
           VoucherPatterns.rowid   ACC_VOUCHER_PATTERNS_ROW_ID,
           Vouchers.rowid          ACC_VOUCHERS_ROW_ID,
           Ledgers.rowid           ACC_LEDGERS_ROW_ID,
           Employees.rowid         BANK_EMPLOYEES_ROW_ID,
           IncExcUnits.rowid       INC_EXC_UNITS_ROW_ID,
           EmployeeRoles.rowid     BANK_EMPLOYEE_ROLES_ROW_ID,
           ParentRoles.rowid       PARENT_ROLES_ROW_ID,
           Roles.rowid             ROLES_ROW_ID,
           Permissions.rowid       PERMISSIONS_ROLES_ROW_ID,
           RolesMemberships.rowid  ROLES_MEMBERSHIPS_ROW_ID
      FROM ACC_VOUCHER_PATTERNS        VoucherPatterns,
           ACC_VOUCHERS                Vouchers,
           ACC_LEDGERS                 Ledgers,
           BANK_EMPLOYEES              Employees,
           BANK_EMPLOYEE_INC_EXC_UNITS IncExcUnits,
           BANK_EMPLOYEE_ROLES         EmployeeRoles,
           ROLES                       ParentRoles,
           ROLES                       Roles,
           ROLES                       Permissions,
           ROLES_MEMBERSHIPS           RolesMemberships
    WHERE Vouchers.TYPE_VOUCHER_PATTERN_FK =
           VoucherPatterns.VOUCHER_PATTERN_ID
       AND VoucherPatterns.CONFIRM_COUNT = 2
       AND Vouchers.STATE = 'ISU'
       AND Vouchers.LEDGER_FK = Ledgers.LEDGER_ID
       AND Employees.ID = IncExcUnits.BKEM_ID(+)
       AND (((IncExcUnits.INC_EXCLUD_TYPE IS NULL OR
           IncExcUnits.INC_EXCLUD_TYPE != 'EXC') AND
           Ledgers.ORGANIZATION_UNIT_FK = Employees.ORGU_ID) OR
           (Ledgers.ORGANIZATION_UNIT_FK = IncExcUnits.ORGU_ID AND
           IncExcUnits.INC_EXCLUD_TYPE = 'INC'))
       AND EmployeeRoles.BKEM_ID = Employees.ID
       AND ParentRoles.ID = EmployeeRoles.ROLS_ID
       AND ParentRoles.IS_PERMISSION = 'N'
       AND ParentRoles.ROLE_TYPE = 'ORG'
       AND ParentRoles.ID = Roles.ROLS_ID
       AND Roles.IS_PERMISSION = 'N'
       AND Roles.ROLE_TYPE = 'SYS'
       AND Permissions.IS_PERMISSION = 'Y'
       AND Permissions.ROLE_NAME = 'ACC_AccVoucherConfirm'
       AND Roles.ID = RolesMemberships.ROLS_ID
       AND Permissions.ID = RolesMemberships.ROLS_ID_MEMBER_OF;
    Then I have issued a SELECT * though it and that works fine.
    And then I've manipulated the data in some tables such that according to MV's WHERE clause it must return no rows.
    Intuitively before refreshing the MV it will return the data last placed on it,
    But it return the same data after issuing the following command in PL/SQL Developer:
    call dbms_mview.refresh(list => 'WLS', method => 'F');
    And unfortunately the following will correct it:
    call dbms_mview.refresh(list => 'WLS', method => 'C');
    Why the fast refresh of a fast refreshable MV does not work fine while its complete refresh works good?
    How ever after undoing made changes to those tables and issuing the fast refresh using the following command the MV will contain correct updated data:
    call dbms_mview.refresh(list => 'WLS', method => 'F');
    It seems that it has bug in deleting rows from Fast Refreshable MV but upserts work fine.
    I've tried to simulate the problem for a simpler query with simple tables containing some sample data but those don't have any problem.
    Please help me,
    Thanks

    Thanks Martin,
    Finally I've discovered one of possible several situations in which a MV fast refreshed incorrectly.
    This is happened when an OR condition exists among several AND conditions and at least one outer join symbol there exists!
    this is the scenario:
    -- create two sample tables
    create table t as select 1 a, 2 b from dual;
    create table j as select 1 a, 2 b from dual;
    -- defining primary keys
    alter table t add constraint tp primary key (a);
    alter table j add constraint jp primary key (a);
    -- creating MV Logs
    create materialized view log on t with primary key, rowid;
    create materialized view log on j with primary key, rowid;
    -- creating Fast Refresh MV with a sample query
    create materialized view mvt refresh fast enable query rewrite as
    select t.a, j.b, t.rowid tr, j.rowid jr from t,j where t.a = j.a(+)
    and (t.b = j.b or t.a = t.b);
    -- select through MV, the MV returns correct data
    select * from mvt;
         A    B    TR                    JR
        1    2    AAAYwQAAEAAFhwzAAA    AAAYwRAAEAAFhw7AAA
    -- intentionally manipulate the data to the query returns no rows
    update j set a = 2;
    commit;
    -- query the select of MV
    select t.a, j.b, t.rowid tr, j.rowid jr from t,j where t.a = j.a(+)
    and (t.b = j.b or t.a = t.b);
    -- returns now rows, The query rewrite does not work here!
    -- select through MV, the MV returns correct data because it has not refreshed yet!
    select * from mvt;
         A    B    TR                    JR
        1    2    AAAYwQAAEAAFhwzAAA    AAAYwRAAEAAFhw7AAA
    -- fast refreshing the mv and issuing select again
    call dbms_mview.refresh(list => 'MVT', method => 'F');
    select * from mvt;
         A    B        TR                    JR
        1    null    AAAYwuAAEAAFh2jAAA    null
    -- A change is occured but it is not correct, it must returns no rows!
    -- query the select of MV
    select t.a, j.b, t.rowid tr, j.rowid jr from t,j where t.a = j.a(+)
    and (t.b = j.b or t.a = t.b);
         A    B        TR                    JR
        1    null    AAAYwuAAEAAFh2jAAA    null
    -- Query rewrite does work here! because appending a neutral "and 1=1" conditions will show the correct empty result:
    select t.a, j.b, t.rowid tr, j.rowid jr from t,j where t.a = j.a(+)
    and (t.b = j.b or t.a = t.b) and 1=1;
    -- returns no rows
    -- now complete refreshing the MV and achieving the correct result:
    call dbms_mview.refresh(list => 'MVT', method => 'C');
    select * from mvt;
    -- returns no rows
    Is this a BUG?
    Any suggestions?

Maybe you are looking for

  • Siebel 8.1 SWSE installation problem on Linux

    Hi All, I'm trying to install Siebel 8.1 [21039] on Linux (Redhat 4 with update 5) . I have done my gateway server, enterprise server and siebel server successfully. Then I installed the OHS 10.1.3 and Siebel Web Server Extension as the web server, b

  • Error in Vendor Creation

    Hi, In Vendor creation , while  selecting  the Country as United States ( US) in Vendor address the following error message is displayed "Communication error with the external tax system (VERTEX_MS0018) Message no. TAX_TXJCD864 " How to solve this is

  • HP Officejet Pro 8500A Plus doesn't "SLEEP".

    Hello,  Unlike many owners who have printers that don't wake up from sleep or energy saver mode, I'm just the opposite.  Mine won't go into sleep mode, despite having the energy saving mode "ON".  I've powered on/off several times, uninstalled/instal

  • InvocationTargetException at Tomcat Startup

    I am seeing the following error appear in my catalina log after starting Tomcat on Red Hat Linux 8.0 using jdk 1.4.1... I am able to run servlets and JSP pages from the browser as well as within my application but would like to know more about this e

  • Can I get someone to move my iTunes library for me?

    Old PC, new laptop. Tried to move iTunes library of 3200 songs to new laptop. Followed the procedure for doing so by using my 30 GB iPod as the transfer device. Have now failed twice at it. Always end up with an empty iTunes library on new laptop AND