Views vs joins

Hi,
It may be a very basic question, but exploring blogs got me that there will not be much performance improvement if query is not used heavily.
But what if query is used heavily.
I have a query that is executing for several thousands of time(it is in loop).
This query uses join to 4 heavily populated table(with record count > 30 millions in each table [There is no mechanism to purge old data ] )
This query is taking consuming more time [though query is tuned and is using bind variables]. Basic level DBA investigation are already performed like gathering statistics, De-fragmenting, etc.
Sample Query :
SELECT   table1.col1, table2.col2
   FROM    table1,
                  table2,
                  table3,
                  table4
WHERE   cond1
AND          cond2
AND          cond3
AND          cond4
AND          cond5
ORDER BY table3.col1
Will creating a view be useful for above query and querying on that view be help to improve performance issue...?
CREATE OR REPLACE VIEW SOME_VIEW
AS
SELECT   table1.col1, table2.col2
   FROM    table1,
                  table2,
                  table3,
                  table4
Kindly guide/suggest.

Satyakunal wrote:
Thanks all for response!!!
We thought of eliminating this query from loop, However current design does not permits it.
As this is a part of application which is already live since years, design change would take time.
Anyways as suggested and I too felt that Iast alternative would be a design change.
I would say it's the first alternative.  If you cannot just change the code to avoid the looping (you haven't explained why) and replace with more pure SQL, and this requires a redesign of the database, then you are better to start thinking about how you are going to implement this redesign (in small steps or one big go as appropriate?) right now before the problem becomes an even bigger problem.  There's an English saying "A stitch in time saves nine"...  ( A stitch in time saves nine )

Similar Messages

  • View and join Table

    Hi,
      what is the differnce between view and join table

    Hi,
    There are 4 types of views in SAP.
    Database View - To club more than one table
    Projection View - To hide fields in one table
    Maintenance View - To maintain database records in table
    Help View - To provide help for a fields (Same functionality as Search help. This is outdated)
    View are improves performance in the following aspects
    1. If you want to use more than two table in 'JOIN' condition better to use Views . It will improves performance of a program
    2. If you want to use mutiple FOR ALL ENTRIES clause, better to club all SELECT statement in a view.
    Note:
    1.Views does not contain data in it. It fetches data from the database only depending on the condition ...
    2.Views are part of data dictionary. They are a window to view the data in database
    3.views can be used to give security to data. users can be allowed to view only basic data only
    For More Info,go thru this Threads,
    join
    Views vs Inner Join
    Regards,
    Padmam.

  • Materialized View with Joins

    Dear Dev/DBAs,
    I have the following scenario:
    SQL> CREATE TABLE T1 (ID NUMBER(3),NAME VARCHAR2(10));
    SQL> CREATE TABLE T2 (ID NUMBER(3),NAME VARCHAR2(10));
    The T1 contains records having the ID num from 10 to 80 and the T2 having the ID from 90 to 170
    SQL> SELECT * FROM T1 JOIN ALL SELECT * FROM T2
    It give all records in the 2 tables.
    I'm planning to create a materialized view (like CREATE MATERIALIZED VIEW V_TAB REFRESH ON COMMIT AS SELECT * FROM T1 JOIN ALL SELECT * FROM T2) and it seems i can't do with the error ORA-12054, further the oracle documentation says that materialized view can only be used with a simple join.
    Do you have another solution??
    Note that the materialized views can be used to improve queries.
    Thank you in advance

    Straight from the link I posted:
    *Restrictions on Fast Refresh on Materialized Views with UNION ALL*Materialized views with the UNION ALL set operator support the REFRESH FAST option if the following conditions are satisfied:
    * The defining query must have the UNION ALL operator at the top level.
    The UNION ALL operator cannot be embedded inside a subquery, with one exception: The UNION ALL can be in a subquery in the FROM clause provided the defining query is of the form SELECT * FROM (view or subquery with UNION ALL) as in the following example:
    CREATE VIEW view_with_unionall AS
    (SELECT c.rowid crid, c.cust_id, 2 umarker
    FROM customers c WHERE c.cust_last_name = 'Smith'
    UNION ALL
    SELECT c.rowid crid, c.cust_id, 3 umarker
    FROM customers c WHERE c.cust_last_name = 'Jones');
    CREATE MATERIALIZED VIEW unionall_inside_view_mv
    REFRESH FAST ON DEMAND AS
    SELECT * FROM view_with_unionall;
    Note that the view view_with_unionall satisfies the requirements for fast refresh.
    * Each query block in the UNION ALL query must satisfy the requirements of a fast refreshable materialized view with aggregates or a fast refreshable materialized view with joins.
    The appropriate materialized view logs must be created on the tables as required for the corresponding type of fast refreshable materialized view.
    Note that the Oracle Database also allows the special case of a single table materialized view with joins only provided the ROWID column has been included in the SELECT list and in the materialized view log. This is shown in the defining query of the view view_with_unionall.
    * The SELECT list of each query must include a maintenance column, called a UNION ALL marker. The UNION ALL column must have a distinct constant numeric or string value in each UNION ALL branch. Further, the marker column must appear in the same ordinal position in the SELECT list of each query block.
    * Some features such as outer joins, insert-only aggregate materialized view queries and remote tables are not supported for materialized views with UNION ALL.
    * Partiton Change Tracking (PCT)-based refresh is not supported for UNION ALL materialized views.
    * The compatibility initialization parameter must be set to 9.2.0 or higher to create a fast refreshable materialized view with UNION ALL.

  • Materialized view with join

    In 10g release 2,I tried to create following materialized view with join:
    test_link is a normal table
    test_geom is a table contains a column in SDO_GEOMETRY
    CREATE MATERIALIZED VIEW LOG ON test_link with rowid
    CREATE MATERIALIZED VIEW LOG ON test_geom with rowid,primary key
    CREATE MATERIALIZED VIEW MV_LINK USING INDEX REFRESH FAST ON DEMAND AS
    SELECT li.rowid link_rowid,geom.rowid geom_rowid,li.link_id,geom.link
    FROM test_link li, test_geom geom
    WHERE li.link_id=geom.link_id
    But I always got an error like:
    ORA-12015: cannot create a fast refresh materialized view from a complex query
    If I change the geometry table to another table, everything works fine.
    Anyone have ideas?

    Unfortunately, creating a fast refreshable materialized view on a join with one of the select columns being a user defined type (sdo_geometry is a user defined type) is not allowed. See 5303489 in the metalink bug database.
    You could do like the workaround in the article suggests and create two materialized views and then create a regular view on top.
    In our scenario, our materialized view also contains unions, so we would really like to have one physical object at the end of the day. One approach that we are currently investigating is to create the materialized view (MV1) without the geometry column, which makes it fast refreshable, and also create a materialized view (MV2) on the table containing the geometry column. MV2 is also fast refreshable. We then create a table (T3) that contains all of the columns from MV1, plus a geometry column. An insert, update, delete trigger on MV1 is created. The trigger is used to push all of the columns from MV1 to T3 and the geometry column from MV2 to T3. I have created the above in one of our test environments and haven't encountered any issues yet.
    Let me know if you come up with a better approach.

  • Sample of Materialized View (with join)

    Does anyone have an example of a Materialized View that joins 2 tables ?

    Khe, khe then you'd better ask directly your question instead of somehow cover it :)
    OK speaking about MVs the fisrt thing as always is Oracle documentation and Data warehousing guide contains 4 chapter devoted to MVs Basic MVs, advanced MVs, basic query rewrite and advanced query rewrite.
    Here is the link where you should start
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14223/basicmv.htm
    And MV logs are needed to do incremental (fast, actually sometimes it might be much slower than complete refresh) refresh on MVs.
    Gints Plivna
    http://www.gplivna.eu

  • Question about using views in joins

    I have a question that is related to views. When a view is joined with another table, how does Oracle internally handle it? Does it create a temporary table that contains the resultant rows of the view and join that temorary table to the other table or does it use the view's SQL and embed it into the join condition?
    Thanks.
    Edited by: soleil4716 on Aug 13, 2010 11:58 AM

    soleil4716 wrote:
    I have a question that is related to views. When a view is joined with another table, how does Oracle internally handle it? Does it create a temporary table that contains the resultant rows of the view and join that temorary table to the other table or does it use the view's SQL and embed it into the join condition?
    No oracle do not create temporary table to joining table and views.There no difference joining just table<=>table and table<=>view.There is important join condition,and oracle will join these table and view according these conditions.

  • 10g doing VIEW type join even when no view in SQL - and performing poorly

    Using 10.2.0.2.0
    Every once in a while I see CBO deciding to use VIEW type join even when there is no view in the SQL and whenever it does that the performance just sucks.
    Example –
    SQL-
    SELECT a.emplid, a.empl_rcd, TO_CHAR (((a.dur) + (:"SYS_B_00")), :"SYS_B_01"),
    a.seqnum
    FROM ps_wrk_adhoc_tao5 a, ps_tl_prof_wrk5 b, ps_tl_empl_data c
    WHERE a.dur =
    (SELECT MAX (a1.dur)
    FROM ps_wrk_adhoc_tao5 a1
    WHERE a1.process_instance = :"SYS_B_02"
    AND a1.emplid = a.emplid
    AND a1.empl_rcd = a.empl_rcd)
    AND a.dur < TO_DATE (:"SYS_B_03", :"SYS_B_04")
    AND NOT EXISTS (
    SELECT :"SYS_B_05"
    FROM ps_tl_ta_exceptn5 q
    WHERE q.process_instance = :"SYS_B_06"
    AND q.exception_id = :"SYS_B_07"
    AND q.emplid = a.emplid
    AND q.empl_rcd = a.empl_rcd
    AND q.dur = a.dur)
    AND :"SYS_B_08" = :"SYS_B_09"
    AND c.emplid = a.emplid
    AND b.emplid = a.emplid
    AND c.empl_rcd = a.empl_rcd
    AND b.empl_rcd = a.empl_rcd
    AND c.effdt =
    (SELECT MAX (c1.effdt)
    FROM ps_tl_empl_data c1
    WHERE c1.emplid = c.emplid
    AND c1.empl_rcd = c.empl_rcd
    AND c1.effdt <= ((a.dur) + (:"SYS_B_10")))
    AND b.effdt =
    (SELECT MAX (b1.effdt)
    FROM ps_tl_prof_wrk5 b1
    WHERE b1.process_instance = :"SYS_B_11"
    AND b1.emplid = b.emplid
    AND b1.empl_rcd = b.empl_rcd
    AND b1.effdt <= ((a.dur) + (:"SYS_B_12")))
    AND c.time_rptg_status = :"SYS_B_13"
    AND b.empl_status IN (:"SYS_B_14", :"SYS_B_15", :"SYS_B_16", :"SYS_B_17")
    AND a.process_instance = :"SYS_B_18"
    AND b.process_instance = :"SYS_B_19"
    Plan –
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 18
    NESTED LOOPS ANTI 1 153 13
    NESTED LOOPS 1 125 12
    NESTED LOOPS 1 103 10
    HASH JOIN 1 76 9
    INDEX RANGE SCAN SYSADM.PS0WRK_ADHOC_TAO5 7 245 2
    SORT AGGREGATE 1 21
    TABLE ACCESS BY INDEX ROWID SYSADM.PS_WRK_ADHOC_TAO5 6 126 3
    INDEX RANGE SCAN SYSADM.PS_WRK_ADHOC_TAO5 6 2
    VIEW SYS.VW_SQ_1 524 20 K 6
    HASH GROUP BY 524 40 K 6
    FILTER
    MERGE JOIN 1 K 124 K 5
    SORT JOIN 151 5 K 2
    INDEX RANGE SCAN SYSADM.PS_TL_PROF_WRK5 151 5 K 1
    SORT JOIN 214 8 K 3
    INDEX RANGE SCAN SYSADM.PS0WRK_ADHOC_TAO5 214 8 K 2
    TABLE ACCESS BY INDEX ROWID SYSADM.PS_TL_PROF_WRK5 1 27 1
    INDEX UNIQUE SCAN SYSADM.PS_TL_PROF_WRK5 1 0
    TABLE ACCESS BY INDEX ROWID SYSADM.PS_TL_EMPL_DATA 1 22 2
    INDEX RANGE SCAN SYSADM.PS_TL_EMPL_DATA 1 1
    SORT AGGREGATE 1 20
    FIRST ROW 1 20 2
    INDEX RANGE SCAN (MIN/MAX) SYSADM.PS_TL_EMPL_DATA 1 20 2
    INDEX RANGE SCAN SYSADM.PS_TL_TA_EXCEPTN5 1 28 1
    If I use a rule hint here I get this plan. I get the plan given below on another database even without the rule hint –
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=HINT: RULE
    FILTER
    FILTER
    TABLE ACCESS BY INDEX ROWID SYSADM.PS_TL_EMPL_DATA
    NESTED LOOPS
    NESTED LOOPS
    TABLE ACCESS BY INDEX ROWID SYSADM.PS_TL_PROF_WRK5
    INDEX RANGE SCAN SYSADM.PS_TL_PROF_WRK5
    TABLE ACCESS BY INDEX ROWID SYSADM.PS_WRK_ADHOC_TAO5
    INDEX RANGE SCAN SYSADM.PS_WRK_ADHOC_TAO5
    INDEX RANGE SCAN SYSADM.PS_TL_EMPL_DATA
    SORT AGGREGATE
    TABLE ACCESS BY INDEX ROWID SYSADM.PS_WRK_ADHOC_TAO5
    INDEX RANGE SCAN SYSADM.PS_WRK_ADHOC_TAO5
    INDEX RANGE SCAN SYSADM.PS_TL_TA_EXCEPTN5
    SORT AGGREGATE
    INDEX RANGE SCAN SYSADM.PS_TL_EMPL_DATA
    SORT AGGREGATE
    INDEX RANGE SCAN SYSADM.PS_TL_PROF_WRK5
    The whole schema was analyzed using dbms.stats only yesterday. My question is why is Oracle doing VIEW, and how can I stop it from doing that. Hint is not an option.

    I understand that SQL Developer takes it's NLS settings from Preferences - Database - NLS Parameters. What I was not aware of is that when SQL Developer is run for the first time the NLS Parameters seem to be populated from the settings on the OS of the PC it is running on. To test that this was the case I did the following
    I work on a Windows XP system with Regional Options - Standards and Formats and Regional Options - Location set with English (United Kingdom) and United Kingdom respectively.
    I unzipped two clean SQL Developer instances (both Version 1.2.1). The first instance I first ran under my current PC set up without importing settings from a previous installation. The Preferences - Database - NLS Parameters - Language and Preferences - Database - NLS Parameters - Territory had been populated with English and United Kingdom.
    I then changed the Regional Options on the OS to English (United States) and United States and ran the second instance of SQL Developer for the first time, again without importing settings. In this instance of SQL Developer the NLS Parameters were populated with American and America.
    When the first instance of SQL Developer was the checked under these OS settings the NLS Parameters were still English and United Kingdom.
    I was not aware this was the case and, if my test is correct, it seems to contradict the SQL Developer user guide http://download.oracle.com/docs/cd/E10405_01/doc/appdev.120/e10406/intro.htm#CHDBHCAG
    James
    Message was edited by: Jampat to include SQL Developer version number.

  • Is it possible to place a view of joined tables into Shared Memory?

    Thanks.

    Tom,
    The view of joined tables is just a possible selection method. You may select first and store all data in shared Memory. You better define a shared obkect with a read method and a buffer attribute.
    The best thing you can do here is just to say what you want to do and why. It is always difficult to give a satifactory answer to an abstract question.
    Regards,
    Clemens

  • The order doesn't work in my view with join between two lists. And now?

    Hi,
    I work with sharepoint 2010.
    I did the join between two list follow this
    post.
    I did it and everything is ok, but the order doesn't work.
    What can be it?
    Thanks
    K2rto'4 - Analista Sharepoint
    "Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善

    Hi,
    I've two lists in my view with join. The list A and the list B.
    I'm ordering the view with the column list A.
    The column list A it's a column for type lookup to list B's column.
    In my view i'm ordering with the column list A of type lookup.
    The view with join is not ordering in order growing.
    I want the view will be ordering by order growing.
    Do you understood?
    Hugs
    K2rto'4 - Analista Sharepoint
    "Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善

  • Partition Eliminiation on views and joins with other partitioned tables

    I have a bunch of tables that are daily partioned and other which are not. We constantly join all these tables. I have noticed that partition elimination doesn't happen in most cases and I want some input or pointers on these.
    Case 1
    We have a view that joins a couple of partitioned tables on the id fileds and they the partition key is timestamp with local time zone.
    TABLEA
    tableaid
    atime
    TABLEB
    tablebid
    tableaid
    btime
    The view basically joins on tableaid, a.tableaid = b.tableaid(+) and a bunch of other non partitioned tables. atime and btime are the individal partition keys in the tables and these time do not match up like the id's in other words there is a little bit of correlation but they can be very different.
    When I run a query against the view providing a time range for btime, I see partition elimination on tabled in the explain plan with KEY on Pstart/Pstop. But its a full tablescan on tablea. I was hoping there would be somekind of partition elimination here since its also partioned daily on the same datatype timestamp with local time zone.
    Case 2
    I have a couple of more partitioned tables
    TABELC
    tablecid
    tablebid
    ctime
    TABLED
    tabledid
    tablebid
    dtime
    As you can see these tables are joined with tablebid and the times here generally correlate to tableb's timestamp as well.
    Sub Case 1
    When I join these tables to the view and give a time range on btime, I see partition elimination happening on tableb but not on tablea or any of the other tables.
    Sub Case 2
    Then I got rid of the view, wrote a query that us similar to the view where I join on tableaid (tablea and tableb), then on tablebid (tableb, tablec and tabled) and a few other tables and execute the query with some time range on btime and I still see that partition elimination happens only on tableb.
    I thought that if other tables are also partitioned on a similark key that partition eliminition should happen? Or what am I missing here that is preventing from partition elimination on the other tables.

    Performance is of utmost importance and partition pruning is going to help in that. I guess that's what I'm trying to acheive.
    To achive partition elimination on tablec, d, etc I'm doing an outer join with btime and that seems to work. Also since most of the time after the partition elimination, I don't need a full tablescan since the period I will be querying most of the time will be small I also created a local index on id field that I'm using to join so that it can do a "TABLE ACCESS BY LOCAL INDEX ROWID" this way it should peform better than a global index since the index traversal path should be small when compared to the global index.
    Of couse I still have problem with the tablea not being pruned, since I cannot do an outer join on two fields in the same table (id and time). So might just include the time criteria again and may be increase the time range a little more when compared to what the actual user submitted to try not to miss those rows.
    Any suggestions is always welcome.

  • View n Join

    hello all..
    can any one tell me what is the <b>diff</b> betwn a <b>view n a Join</b>.. I do know the functionality of both the concepts, i want to know the difference..
                             thank u...

    Hi Shalu,
    <b>
    What is a View ?</b>
    When you want to fetch data from one or more than one tables from the database, Views can be used. But once a view is created it resides permanently in the database memory for future usage. Also with a view creation it can be used to maintain data in the SM30 transaction when a table maintainence is created for a table. Before creating a view we need to be definite if it is of definite usage in the future.
    <b>
    What is a Inner join ?</b>
    When you want to fetch data from one or more than one tables from the database, only in a ABAP program Inner joins can be used. The inner join does the same thing as the view but it is available only in the run time of ABAP code execution.
    <b>Difference between View and Inner Join</b>
    Inner Join: Run time entity enable to join only Transparent Tables. As the no. of tables fopr the join increases the performace decreases as it occupies more meory and runtime. Also the code becomes complex.
    <b>View:</b> A view is a permanent database entity. There is no restriction on the no. of tables. Any type of join can be written in the conditions tab. At run time in a ABAP code a view can be used with select statements as we do with tables.
    <b>
    Types of Views:</b>
    Database View: This is a view that can be used on to fetch data in the ABAP code to. Data about an application object is often distributed on several database tables. A database view provides an application-specific view on such distributed data. Database views are defined in the ABAP Dictionary. A database view is automatically created in the underlying database when it is activated. Application programs can access the data of a database view using the database interface. You can access the data in ABAP programs with both OPEN SQL and NATIVE SQL. However, the data is actually selected in the database. Since the join operation is executed in the database in this case, you can minimize the number of database accesses in this way. Database views implement an inner join
    Projection View: Projection views are used to hide fields of a table. This can minimize interfaces; for example when you access the database, you only read and write the field contents actually needed. A projection view contains exactly one table. You cannot define selection conditions for projection views. There is no corresponding object in the database for a projection view. The R/3 System maps the access to a projection view to the corresponding access to its base table. You can also access pooled tables and cluster tables with a projection view.
    Maintenance View: These views are created for the table maintainance for tables. Maintenance views offer easy ways to maintain complex application objects. Data distributed on several tables often forms a logical unit, for example an application object, for the user. You want to be able to display, modify and create the data of such an application object together. Normally the user is not interested in the technical implementation of the application object, that is in the distribution of the data on several tables. A maintenance view permits you to maintain the data of an application object together. The data is automatically distributed in the underlying database tables.
    Search Help View: It is used for producing search helps. You have to create a help view if a view with outer join is needed as selection method of a search help. The selection method of a search help is either a table or a view. If you have to select data from several tables for the search help, you should generally use a database view as selection method. However, a database view always implements an inner join. If you need a view with outer join for the data selection, you have to use a help view as selection method.
    If a Database View already exist, use it instead of the inner joi statements.
    If it doesn't, do not create the Database View. It makes no sesne to create a database view just because you need it in a program or 2.
    And, if you have the same inner join being repeated for 8 times, for different where condition, I would rather sugget to select the data in only one inner-join select(With a where condition that would get al the records). Then you can read the internal table using READ or LOOP statements.
    Re: View Vs Join
    Hope it will solve ur problem..
    <b>Reward Points if it is helpful.</b>
    Thanks & Regards
    ilesh 24x7

  • Fast Refresh on Materialized View With Join

    Hi All,
    i have created following Materialized View Logs and MV
    on EMP and DEPT
    CREATE MATERIALIZED VIEW LOG ON DEPT
    WITH PRIMARY KEY,SEQUENCE
    INCLUDING NEW VALUES;
    CREATE MATERIALIZED VIEW LOG ON EMP
    WITH PRIMARY KEY,SEQUENCE
    INCLUDING NEW VALUES;
    CREATE MATERIALIZED VIEW EMP_MVW
    TABLESPACE OSMIS_REPORT_DATA
    REFRESH FAST ON COMMIT
    AS
    SELECT A.EMPNO,A.ENAME,A.DEPTNO,A.JOB,A.MGR,A.HIREDATE,A.SAL,A.COMM,B.DNAME,B.LOC
    FROM EMP A,DEPT B
    WHERE A.DEPTNO=B.DEPTNO
    The Create MV Stmnt raised following error.
    ERROR at line 6:
    ORA-12052: cannot fast refresh materialized view SCOTT.EMP_MVW
    I have tried the same with ROWID also,but same error
    while creating MV.
    Pls anyone give idea to Fast Refersh on MV with Joins
    Thnks
    Raj.G.
    mail : [email protected]

    Actually you can get Oracle to tell you why the view does not have the capabilities you want using the DBMS_MVIEW package. For example you could have done something like this...
    Personal Oracle Database 10g Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> CREATE MATERIALIZED VIEW LOG ON dept
      2    WITH PRIMARY KEY, SEQUENCE
      3      INCLUDING NEW VALUES;
    Materialized view log created.
    SQL> CREATE MATERIALIZED VIEW LOG ON emp
      2    WITH PRIMARY KEY,SEQUENCE
      3      INCLUDING NEW VALUES;
    Materialized view log created.
    SQL> CREATE MATERIALIZED VIEW emp_mvw
      2    REFRESH FAST ON COMMIT
      3  AS
      4  SELECT a.empno, a.ename, a.deptno,
      5         a.job, a.mgr, a.hiredate,
      6         a.sal, a.comm, b.dname, b.loc
      7  FROM   emp a,dept b
      8  WHERE  a.deptno = b.deptno;
    FROM   emp a,dept b
    ERROR at line 7:
    ORA-12052: cannot fast refresh materialized view SCOTT.EMP_MVW
    SQL> CREATE MATERIALIZED VIEW emp_mvw
      2    REFRESH ON COMMIT -- remove the FAST to allow view to compile
      3  AS
      4  SELECT a.empno, a.ename, a.deptno,
      5         a.job, a.mgr, a.hiredate,
      6         a.sal, a.comm, b.dname, b.loc
      7  FROM   emp a,dept b
      8  WHERE  a.deptno = b.deptno;
    Materialized view created.
    SQL> @\oracle\product\10.1.0\Db_1\RDBMS\ADMIN\utlxmv.sql -- create mv_capabilities_table
    Table created.
    SQL> EXEC DBMS_MVIEW.EXPLAIN_MVIEW ('EMP_MVW');
    PL/SQL procedure successfully completed.
    SQL> SELECT capability_name, possible, msgtxt
      2  FROM   mv_capabilities_table
      3  WHERE  capability_name LIKE '%REFRESH_FAST_AFTER%';
    CAPABILITY_NAME                P MSGTXT
    REFRESH_FAST_AFTER_INSERT      N the SELECT list does not have the rowids of all the detail tables
    REFRESH_FAST_AFTER_INSERT      N mv log must have ROWID
    REFRESH_FAST_AFTER_INSERT      N mv log must have ROWID
    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
    SQL> DROP MATERIALIZED VIEW LOG ON dept;
    Materialized view log dropped.
    SQL> DROP MATERIALIZED VIEW LOG ON emp;
    Materialized view log dropped.
    SQL> DROP MATERIALIZED VIEW emp_mvw;
    Materialized view dropped.
    SQL> CREATE MATERIALIZED VIEW LOG ON dept
      2    WITH ROWID, SEQUENCE
      3      INCLUDING NEW VALUES;
    Materialized view log created.
    SQL> CREATE MATERIALIZED VIEW LOG ON emp
      2    WITH ROWID,SEQUENCE
      3      INCLUDING NEW VALUES;
    Materialized view log created.
    SQL> CREATE MATERIALIZED VIEW emp_mvw
      2    REFRESH FAST ON COMMIT
      3  AS
      4  SELECT a.ROWID emp_rowid, b.ROWID dept_rowid,
      5         a.empno, a.ename, a.deptno,
      6         a.job, a.mgr, a.hiredate,
      7       a.sal, a.comm, b.dname, b.loc
      8  FROM   emp a,dept b
      9  WHERE  a.deptno = b.deptno;
    Materialized view created.
    SQL> DELETE mv_capabilities_table;
    18 rows deleted.
    SQL> EXEC DBMS_MVIEW.EXPLAIN_MVIEW ('EMP_MVW');
    PL/SQL procedure successfully completed.
    SQL> SELECT capability_name, possible, msgtxt
      2  FROM   mv_capabilities_table
      3  WHERE  capability_name LIKE '%REFRESH_FAST_AFTER%';
    CAPABILITY_NAME                P MSGTXT
    REFRESH_FAST_AFTER_INSERT      Y
    REFRESH_FAST_AFTER_ONETAB_DML  Y
    REFRESH_FAST_AFTER_ANY_DML     Y
    SQL>

  • Fast refresh of "materialized view with joins only"

    Hi,
    My Requirement:
    I need to create a materialized view joining two tables.
    Table1 -> Does not have primary key
    Table2 -> Has a primary key
    I need to refesh the mat view only when DML commands are done on Table1 alone.
    And it will be better if i have a Refresh on commit rather on demand.
    The following code is what i used and it dint work for me:
    CREATE MATERIALIZED VIEW LOG ON Table1 WITH ROWID;
    CREATE MATERIALIZED VIEW LOG ON Table2;
    CREATE MATERIALIZED VIEW AAYT_ETF
    REFRESH FORCE ON COMMIT
    ENABLE QUERY REWRITE
    AS
    SELECT A.rowid "table1_rowid", A.ACCTNUM, A.CORR_NUM, A.OFC_NUM, A.RR_NUM, A.BUY_SELL_CDE, A.ACT_AMT, A.CSP_SYM, A.SECR_DESC, A.ACT_QTY
    FROM Table1 A, Table2 G WHERE
    A.CSP_NUM = G.CSP_NUM AND
    G.ASST_SUB_STYP = 'ETF';
    Issue Faced: In this case the refresh happends even while i do DML on Table2.
    But i need the refresh only when i do DML on Table1. I also unable to create Refresh Fast Mat view.
    Can anyone please tell me how to create the Materialized view Log and the Materialized view. Thanks in advance.

    This forum only is for questions relating to the use of OLAP Option. I would post your question on the database forum.
    Keith Laker
    Oracle Data Warehouse Product Management
    OLAP Blog: http://oracleOLAP.blogspot.com/
    OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
    DM Blog: http://oracledmt.blogspot.com/
    OWB Blog : http://blogs.oracle.com/warehousebuilder/
    OWB Wiki : http://wiki.oracle.com/page/Oracle+Warehouse+Builder
    DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html

  • Using a view to join two tables

    Thank you in advance for any advice you can lend.
    I am using this code in my MySQL db to create a view.
    select
        job.id as job_id,
        umr_cost_calculation.plant_name,
        max(umr_cost_calculation.id) as max_id
    from
        job,
        umr_cost_calculation
    where
        job.id = umr_cost_calculation.job_id
    group by job.id , umr_cost_calculation.plant_name
    I did this so I can join two tables and pull in the most current cost data for a specific plant. The report will, at times, show the wrong (older) data. I can re-run the report, filter to just the one job and see again the wrong data. When I add the max_id to the report, it display the id and updates the report with the correct data. It appears that the view was stale and by adding the ID to the report this fixed the issue.
    1) Is this the best way to make this join? I don't see how Crystal supports a subquery to make a join (this is why I used the view).
    2) If I leave the max_id on the report, will this force the view to always update?

    Try:
    Select
    D1.EmpLoginID,
    Count(D1.ID),
    Count(D1.AlarmCode),
    D1.EmpName,
    D1.EmpAddress,
    D2.Db2Count
    FROM DB1.Data D1
    LEFT JOIN (SELECT
    empLoginID, Count(*) as Db2Count
    FROM DB2.ALL_Database
    WHERE site = 'Atlanta'
    GROUP BY empLoginID
    ) D2
    ON D1.EmpLoginID = D2.EmpLoginID
    GROUP BY D1.empLoginID, D1.EmpName, D2.EmpAddress, D2.Db2Count
    Order BY D1.empLoginID ASC
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Materialized View with Join for FAST Refresh

    Hi Gurus,
    Facing issues in MV with a simple join for FAST Refresh.
    2 sample Tables:
    1. employee
    empid integer PK
    empname varchar(50)
    deptid integer FK
    2. delta_employee
    empid integer PK
    empname varchar(50)
    deptid integer FK
    dmlflag varchar(2)
    watermark integer
    Code is as given below -
    CREATE MATERIALIZED VIEW LOG ON work.employee
    WITH SEQUENCE,rowid(empid)
    INCLUDING NEW VALUES;
    CREATE MATERIALIZED VIEW LOG ON work.delta_employee
    WITH SEQUENCE,rowid(empid)
    INCLUDING NEW VALUES;
    CREATE MATERIALIZED VIEW work.MVEmployee REFRESH force on
    demand with rowid AS
    select e.empid,e.empname,e.deptid,d.empid t1
    from work.employee e, work.delta_employee d
    where e.empid = d.empid;
    Able to perform Complete Refresh. Not able to use Fast Refresh for
    incremental refresh.
    Please help.
    Thanks,
    J Kumar

    Found a solution,
    As per oracle documentation rowid fileds should be included in the Select statement. Even though I included the rowid fields, empid in this case it still didnt work.
    The implementation of the rowid column should be included with tablename.rowid instead of the tablename.columnname !
    Modified script is as given below.
    CREATE MATERIALIZED VIEW WORK.MVEMPLOYEE
    REFRESH FORCE ON DEMAND
    WITH PRIMARY KEY
    AS
    select e.rowid "empid",d.rowid "t1" ,e.empname,e.deptid
    from work.employee e, work.delta_employee d
    where e.empid = d.empid;
    And It really WORKS

  • Materialized View  with Joins and Possibilities of Partitioning

    Hi,
    We have a materialized view which has a data to query around 12 gb. The query goes some thing like
    this.
      Select a.c1,a.c2,b.c1,b.c2,c.c1,c.c2
      from a,b,c
      where a.c1=b.c1
      --and the where condition goes on...
      --i.e Basically joining 3 different tables with complex join conditions but without any group functions and subqueries.
       Now i have few questions here.
    Firstly as the Mview is created with joins we will have to create separate logs for each tables and we have did the same. The logs are created with rowid and sequence for better performance during refresh.
    Question No 1
    Is this is a best approach for materializing a query with complex join conditions. Or Is it better to make 3 different materialized views for each 3 tables and join those 3 MViews and write a query for my report. I ask this question just to make sure the refresh time is brought down by this method. But as such as we have created 3 different logs for 3 tables the refresh must be happening separately.
    Question No 2
    Data is likely to grow faster and faster on this. So we have a idea of making this a partitioned Mview. Can the Pro's advice me on this and suggest me the right practice for the same and help me to correct links from where i can pick a example and continue from there.
    Question No 3
    How to find whether the materialized view has refreshed on a fast mode or complete mode after the last refresh.
    Apart from querying and checking the rowid which i feel is quiet cumbersome for a mview with a data volume like what we have. By default when i see the info in TOAD for this Mview it shows Refresh Mode as "Force". But how to ascertain this.
    Thanks in anticipation for a good round of discussion

    Hi,
    We have a materialized view which has a data to query around 12 gb. The query goes some thing like
    this.
      Select a.c1,a.c2,b.c1,b.c2,c.c1,c.c2
      from a,b,c
      where a.c1=b.c1
      --and the where condition goes on...
      --i.e Basically joining 3 different tables with complex join conditions but without any group functions and subqueries.
       Now i have few questions here.
    Firstly as the Mview is created with joins we will have to create separate logs for each tables and we have did the same. The logs are created with rowid and sequence for better performance during refresh.
    Question No 1
    Is this is a best approach for materializing a query with complex join conditions. Or Is it better to make 3 different materialized views for each 3 tables and join those 3 MViews and write a query for my report. I ask this question just to make sure the refresh time is brought down by this method. But as such as we have created 3 different logs for 3 tables the refresh must be happening separately.
    Question No 2
    Data is likely to grow faster and faster on this. So we have a idea of making this a partitioned Mview. Can the Pro's advice me on this and suggest me the right practice for the same and help me to correct links from where i can pick a example and continue from there.
    Question No 3
    How to find whether the materialized view has refreshed on a fast mode or complete mode after the last refresh.
    Apart from querying and checking the rowid which i feel is quiet cumbersome for a mview with a data volume like what we have. By default when i see the info in TOAD for this Mview it shows Refresh Mode as "Force". But how to ascertain this.
    Thanks in anticipation for a good round of discussion

Maybe you are looking for