Query Rewrite with regular database Views

Hi all,
I'm trying to make my programmer's life easier by creating a database view for them to query the data, so they don't have to worry about joining tables. However, query rewrite doesn't work no matter how I define the MV and View. Here's an example:
I've Sales tables with columns: PDate, CustCode, Amount
and Customer table with columns: CustCode, CustDesc
I create a view SALES_V with columns: PDate, CustCode, CustDesc, Amount by joining Sales table with Customer table as follows:
create or replace view SALES_V as
select PDate, c.CustCode, c.CustDesc, Amount
from Sales s
join Customer c on (s.CustCode=c.CustCode);
For the sake of speed, I create a materialized view SALES_TOT_MV with columns: PDate, Amount with the following SQL:
create materialized view SALES_TOT_MV
enable query rewrite
as select PDate, sum(Amount) Amount from Sales
group by PDate;
When I run the following query, I expect it to be rewritten to make use of SALES_TOT_MV:
select PDate, sum(Amount) from SALES_V
group by PDate;
However, explain plan always tell me it's using SALES table, not the SALES_TOT_MV.
Can somebody tell me it's a limitation of Oracle optimizer or I'm just missing something for this?
Thanks in advance!!
- Andrew
Edited by: blackhole001 on Jan 28, 2010 12:34 PM

blackhole001 wrote:
Hi all,
I'm trying to make my programmer's life easier by creating a database view for them to query the data, so they don't have to worry about joining tables. This sounds like a pretty horrible idea. I say this because you will eventually end up with programmers that know nothing about your data model and how to properly interact with it.
Additionally, what you will get is a developer that takes one of your views and see's that of the 20 columns in it, it has 4 that he needs. If all those 4 columns comes from a simple 2 table join, but the view has 8 tables, you're wasting a tonne of resources by using the view (and heaven forbid they have to join that view to another view to get 4 of the 20 columns from that other view as well).
Ideally you'd write stored routines that satisfy exactly what is required (if you are the database resource and these other programmers are java, .net, etc... based) and the front end developers would call those routines customized for an exact purpose.
Creating views is not bad, but it's by no means a proper solution to having developers not learn or understand SQL and/or the data model.

Similar Messages

  • Query rewrites with Nested materialized views with different aggregations

    Platform used : Oracle 11g.
    Here is a simple fact table (with measures m1,m2) and dimensions (a) Location (b) Calendar and (c) Product. The business problem is that aggregation operator for measure m1,m2 are different along location dimension and Calendar dimension. The intention is to preaggregate the measures for a product along the calendar dimension and Location dimension and store it as materialized views.
    The direct option is to define a materialized view with Inline queries (Because of the different aggrergation operator, it is not possible to write a query without Inline query). http://download-uk.oracle.com/docs/cd/B28359_01/server.111/b28313/qradv.htm#BABEAJBF documents the limitations that it works only for 'Text match' and 'Equivalent queries' and that is too limiting.
    So decided to have nested materialized view, with first view having just joins(my_dim_mvw_joins), the second view having aggregations along Calendar dimension (my_dim_mvw_calendar) and third view having aggregations along the Location dimension(my_dim_mvw_location). Obviously I do not want the query I fire to know about materialized views and I fire it against the fact table. I see that for the fired query (Which needs aggregations along both Calendar and Location), is rewritten with just second materialized view but not the third. (Had set QUERY_REWRITE_INTEGRITY as TRUSTED) .
    Wanted to know whether there are limitations on Query Writes with nested materialized views? Thanks
    (Have given a simple testable example below. Pls ignore the values given in 'CALENDAR_IDs', 'PRODUCT_IDs' etc as they are the same for all the queries)
    -- Calendar hierarchy table
    CREATE TABLE CALENDAR_HIERARCHY_TREE
    (     "CALENDAR_ID" NUMBER(5,0) NOT NULL ENABLE,
    "HIERARCHY1_ID" NUMBER(5,0),
    "HIERARCHY2_ID" NUMBER(5,0),
    "HIERARCHY3_ID" NUMBER(5,0),
    "HIERARCHY4_ID" NUMBER(5,0),
    CONSTRAINT "CALENDAR_HIERARCHY_TREE_PK" PRIMARY KEY ("CALENDAR_ID")
    -- Location hierarchy table
    CREATE TABLE LOCATION_HIERARCHY_TREE
    (     "LOCATION_ID" NUMBER(3,0) NOT NULL ENABLE,
    "HIERARCHY1_ID" NUMBER(3,0),
    "HIERARCHY2_ID" NUMBER(3,0),
    "HIERARCHY3_ID" NUMBER(3,0),
    "HIERARCHY4_ID" NUMBER(3,0),
    CONSTRAINT "LOCATION_HIERARCHY_TREE_PK" PRIMARY KEY ("LOCATION_ID")
    -- Product hierarchy table
    CREATE TABLE PRODUCT_HIERARCHY_TREE
    (     "PRODUCT_ID" NUMBER(3,0) NOT NULL ENABLE,
         "HIERARCHY1_ID" NUMBER(3,0),
         "HIERARCHY2_ID" NUMBER(3,0),
         "HIERARCHY3_ID" NUMBER(3,0),
         "HIERARCHY4_ID" NUMBER(3,0),
         "HIERARCHY5_ID" NUMBER(3,0),
         "HIERARCHY6_ID" NUMBER(3,0),
         CONSTRAINT "PRODUCT_HIERARCHY_TREE_PK" PRIMARY KEY ("PRODUCT_ID")
    -- Fact table
    CREATE TABLE RETAILER_SALES_TBL
    (     "PRODUCT_ID" NUMBER,
    "PRODUCT_KEY" VARCHAR2(50 BYTE),
    "PLAN_ID" NUMBER,
    "PLAN_PERIOD_ID" NUMBER,
    "PERIOD_ID" NUMBER(5,0),
    "M1" NUMBER,
    "M2" NUMBER,
    "M3" NUMBER,
    "M4" NUMBER,
    "M5" NUMBER,
    "M6" NUMBER,
    "M7" NUMBER,
    "M8" NUMBER,
    "LOCATION_ID" NUMBER(3,0),
    "M9" NUMBER,
    CONSTRAINT "RETAILER_SALES_TBL_LOCATI_FK1" FOREIGN KEY ("LOCATION_ID")
    REFERENCES LOCATION_HIERARCHY_TREE ("LOCATION_ID") ENABLE,
    CONSTRAINT "RETAILER_SALES_TBL_PRODUC_FK1" FOREIGN KEY ("PRODUCT_ID")
    REFERENCES PRODUCT_HIERARCHY_TREE ("PRODUCT_ID") ENABLE,
    CONSTRAINT "RETAILER_SALES_TBL_CALEND_FK1" FOREIGN KEY ("PERIOD_ID")
    REFERENCES CALENDAR_HIERARCHY_TREE ("CALENDAR_ID") ENABLE
    -- Location dimension definition to promote query rewrite
    create DIMENSION LOCATION_DIM
    LEVEL CHAIN IS LOCATION_HIERARCHY_TREE.HIERARCHY1_ID
    LEVEL CONSUMER_SEGMENT IS LOCATION_HIERARCHY_TREE.HIERARCHY3_ID
    LEVEL STORE IS LOCATION_HIERARCHY_TREE.LOCATION_ID
    LEVEL TRADING_AREA IS LOCATION_HIERARCHY_TREE.HIERARCHY2_ID
    HIERARCHY PROD_ROLLUP (
    STORE CHILD OF
    CONSUMER_SEGMENT CHILD OF
    TRADING_AREA CHILD OF
    CHAIN
    -- Calendar dimension definition
    create DIMENSION CALENDAR_DIM
    LEVEL MONTH IS CALENDAR_HIERARCHY_TREE.HIERARCHY3_ID
    LEVEL QUARTER IS CALENDAR_HIERARCHY_TREE.HIERARCHY2_ID
    LEVEL WEEK IS CALENDAR_HIERARCHY_TREE.CALENDAR_ID
    LEVEL YEAR IS CALENDAR_HIERARCHY_TREE.HIERARCHY1_ID
    HIERARCHY CALENDAR_ROLLUP (
    WEEK CHILD OF
    MONTH CHILD OF
    QUARTER CHILD OF
    YEAR
    -- Materialized view with just joins needed for other views
    CREATE MATERIALIZED VIEW my_dim_mvw_joins build immediate refresh complete enable query rewrite as
    select product_id, lht.HIERARCHY1_ID, lht.HIERARCHY2_ID, lht.HIERARCHY3_ID, lht.location_id, cht.HIERARCHY1_ID year,
    cht.HIERARCHY2_ID quarter, cht.HIERARCHY3_ID month, cht.calendar_id week, m1, m3, m7, m9
    from retailer_sales_tbl RS, calendar_hierarchy_tree cht, location_hierarchy_tree lht
    WHERE RS.period_id = cht.CALENDAR_ID
    and RS.location_id = lht.location_id
    and cht.CALENDAR_ID in (10,236,237,238,239,608,609,610,611,612,613,614,615,616,617,618,619,1426,1427,1428,1429,1430,1431,1432,1433,1434,1435,1436,1437,1438,1439,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,1452,1453,1454,1455,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1466,1467,1468,1469,1470,1471,1472,1473,1474,1475,1476,1477)
    AND product_id IN (5, 6, 7, 8, 11, 12, 13, 14, 17, 18, 19, 20)
    AND lht.location_id IN (2, 3, 11, 12, 13, 14, 15, 4, 16, 17, 18, 19, 20)
    -- Materialized view which aggregate along calendar dimension
    CREATE MATERIALIZED VIEW my_dim_mvw_calendar build immediate refresh complete enable query rewrite as
    select product_id, HIERARCHY1_ID , HIERARCHY2_ID , HIERARCHY3_ID ,location_id, year, quarter, month, week,
    sum(m1) m1_total, sum(m3) m3_total, sum(m7) m7_total, sum(m9) m9_total,
    GROUPING_ID(product_id, location_id, year, quarter, month, week) dim_mvw_gid
    from my_dim_mvw_joins
    GROUP BY product_id, HIERARCHY1_ID , HIERARCHY2_ID , HIERARCHY3_ID , location_id,
    rollup (year, quarter, month, week);
    -- Materialized view which aggregate along Location dimension
    CREATE MATERIALIZED VIEW my_dim_mvw_location build immediate refresh complete enable query rewrite as
    select product_id, year, quarter, month, week, HIERARCHY1_ID, HIERARCHY2_ID, HIERARCHY3_ID, location_id,
    sum(m1_total) m1_total_1, sum(m3_total) m3_total_1, sum(m7_total) m7_total_1, sum(m9_total) m9_total_1,
    GROUPING_ID(product_id, HIERARCHY1_ID, HIERARCHY2_ID, HIERARCHY3_ID, location_id, year, quarter, month, week) dim_mvw_gid
    from my_dim_mvw_calendar
    GROUP BY product_id, year, quarter, month, week,
    rollup (HIERARCHY1_ID, HIERARCHY2_ID, HIERARCHY3_ID, location_id)
    -- SQL Query Fired (for simplicity have used SUM as aggregation operator for both, but they will be different)
    select product_id, year, HIERARCHY1_ID, HIERARCHY2_ID,
    sum(m1_total) m1_total_1, sum(m3_total) m3_total_1, sum(m7_total) m7_total_1, sum(m9_total) m9_total_1
    from
    select product_id, HIERARCHY1_ID , HIERARCHY2_ID , year,
    sum(m1) m1_total, sum(m3) m3_total, sum(m7) m7_total, sum(m9) m9_total
    from
    select product_id, lht.HIERARCHY1_ID , lht.HIERARCHY2_ID , lht.HIERARCHY3_ID ,lht.location_id, cht.HIERARCHY1_ID year, cht.HIERARCHY2_ID quarter, cht.HIERARCHY3_ID month, cht.calendar_id week,m1,m3,m7,m9
    from
    retailer_sales_tbl RS, calendar_hierarchy_tree cht, location_hierarchy_tree lht
    WHERE RS.period_id = cht.CALENDAR_ID
    and RS.location_id = lht.location_id
    and cht.CALENDAR_ID in (10,236,237,238,239,608,609,610,611,612,613,614,615,616,617,618,619,1426,1427,1428,1429,1430,1431,1432,1433,1434,1435,1436,1437,1438,1439,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,1452,1453,1454,1455,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1466,1467,1468,1469,1470,1471,1472,1473,1474,1475,1476,1477)
    AND product_id IN (5, 6, 7, 8, 11, 12, 13, 14, 17, 18, 19, 20)
    AND lht.location_id IN (2, 3, 11, 12, 13, 14, 15, 4, 16, 17, 18, 19, 20)
    GROUP BY product_id, HIERARCHY1_ID , HIERARCHY2_ID , HIERARCHY3_ID , location_id, year
    ) sales_time
    GROUP BY product_id, year,HIERARCHY1_ID, HIERARCHY2_ID
    This Query rewrites only with my_dim_mvw_calendar. (as saw in Query Plan and EXPLAIN_MVIEW). But we would like it to use my_dim_mvw_location as that has aggregations for both dimensions.

    blackhole001 wrote:
    Hi all,
    I'm trying to make my programmer's life easier by creating a database view for them to query the data, so they don't have to worry about joining tables. This sounds like a pretty horrible idea. I say this because you will eventually end up with programmers that know nothing about your data model and how to properly interact with it.
    Additionally, what you will get is a developer that takes one of your views and see's that of the 20 columns in it, it has 4 that he needs. If all those 4 columns comes from a simple 2 table join, but the view has 8 tables, you're wasting a tonne of resources by using the view (and heaven forbid they have to join that view to another view to get 4 of the 20 columns from that other view as well).
    Ideally you'd write stored routines that satisfy exactly what is required (if you are the database resource and these other programmers are java, .net, etc... based) and the front end developers would call those routines customized for an exact purpose.
    Creating views is not bad, but it's by no means a proper solution to having developers not learn or understand SQL and/or the data model.

  • Query Rewrite to Utilize Materialized Views on a Remote Database

    We have our materilized views stored at a remote database. Is there a way to utilize query rewrite to rewrite the queries issued on the local database such that queries will refer the materialized views at a remote db?
    From the documentation, I already know that the base tables for MVs and MVs should eside in the same instance or the query should be submitted on the instance where MVs reside if base tables are residing in a different remote DB to benefit from query rewrite.
    My aim is to utilize query rewrite to reduce the workload on a primary database by passing queries that can be rewritten to use MVs on a remote DB.
    Thanks for the guidance,

    My aim is to utilize query rewrite to reduce the workload on a primary database by passing queries that can be rewritten to use MVs on a remote DB. If you know that MVs are not stale or acceptable of staled data and don't see network bandwidth problems (small set of result), You would try accessing MV tables directly on remote db using dblinks.

  • Query rewrite with replication Mat. Views

    Hi,
    Is it possible to have query rewrite using MV's
    built from remote tables ?
    Thanks for your help
    11.20.2

    Hi,
    Yes , it is possible
    GRANT GLOBAL QUERY REWRITE system privilege
    use explain _rewrite to verify if rewrite works for MV/sql text
    DBMS_MVIEW.EXPLAIN_REWRITE (
    query VARCHAR2,
    mv VARCHAR2(30),
    statement_id VARCHAR2(30));
    Thanks,
    Ajay More

  • Very high parse times for query rewrite using cube materialized views

    We recently upgraded to version 11.2.0.2 (both AWM and Oracle database server). We are using cube materialized views with query rewrite enabled. Some observations of changes that took place when we rebuilt all the dimensions and cubes in this version:
    1. Queries against the base tables take about 35 seconds to parse. Then they execute in a tenth of a second. Even simple queries that just get a sum of the amount from the fact table (which is joined to all the dimensions) takes that long to parse. Once parsed, the queries fly.
    2. I noticed that the materialized views used to use grouping sets in the group by clause in version 11.2.0.1, but now they use group by rollup, rollup, rollup...
    If we disable query rewrite on the MV or for my session, parse times drop to less than a second. Ideas?

    There does appear to be a slow down in parse times between 11.1.0.7 and 11.2. We are still investigating this, but in the meantime here is a way to force the code in 11.2 to generate a GROUPING SETS clause instead of the new ROLLUP syntax.
    The trick is to create a dummy hierarchy containing only the leaf level. This is necessary for all dimensions that currently have a single hierarchy. As a simple example I created a dimension, PROD, with three levels, A, B, and C, in a single hierarchy. I then created a one dimensional cube, PC. Here is the SELECT statement for the MV in 11.2. Note the ROLLUP clause in the GROUP BY.
    SELECT
      GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")  SYS_GID,
      (CASE GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")
       WHEN 3
       THEN TO_CHAR(('A_' || T3."CLASS_ID") )
       WHEN 1
       THEN TO_CHAR(('B_' || T3."FAMILY_ID") )
       ELSE TO_CHAR(('C_' || T3."ITEM_ID") )  END)     "PROD",
      T3."CLASS_ID" "D1_PROD_A_ID",
      T3."FAMILY_ID" "D1_PROD_B_ID",
      T3."ITEM_ID" "D1_PROD_C_ID",
      SUM(T2."UNIT_PRICE")     "PRICE",
      COUNT(T2."UNIT_PRICE")  "COUNT_PRICE",
      COUNT(*)  "SYS_COUNT"
    FROM
      GLOBAL."PRICE_AND_COST_FACT" T2,
      GLOBAL."PRODUCT_DIM" T3
    WHERE
      (T3."ITEM_ID" = T2."ITEM_ID")
    GROUP BY
      (T3."CLASS_ID") ,
      ROLLUP ((T3."FAMILY_ID") , (T3."ITEM_ID") )Next I modified the dimension to add a new hierarchy, DUMMY, containing just the leaf level, C. Once I have mapped the new level and re-enabled MVs, I get the following formulation.
    SELECT
      GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")  SYS_GID,
      (CASE GROUPING_ID(T3."CLASS_ID", T3."FAMILY_ID", T3."ITEM_ID")
       WHEN 3
       THEN ('A_' || T3."CLASS_ID")
       WHEN 1
       THEN ('B_' || T3."FAMILY_ID")
       WHEN 0
       THEN ('C_' || T3."ITEM_ID")
       ELSE NULL END)  "PROD",
      T3."CLASS_ID" "D1_PROD_A_ID",
      T3."FAMILY_ID" "D1_PROD_B_ID",
      T3."ITEM_ID" "D1_PROD_C_ID",
      SUM(T2."UNIT_PRICE")     "PRICE",
      COUNT(T2."UNIT_PRICE")  "COUNT_PRICE",
      COUNT(*)  "SYS_COUNT"
    FROM
      GLOBAL."PRICE_AND_COST_FACT" T2,
      GLOBAL."PRODUCT_DIM" T3
    WHERE
      (T3."ITEM_ID" = T2."ITEM_ID")
    GROUP BY
      GROUPING SETS ((T3."CLASS_ID") , (T3."FAMILY_ID", T3."CLASS_ID") , (T3."ITEM_ID", T3."FAMILY_ID", T3."CLASS_ID") )This puts things back the way they were in 11.1.0.7 when the GROUPING SETS clause was used in all cases. Note that the two queries are logically equivalent.

  • Query Rewrite (QSM-01263) and Views in Execution Plan

    Hello!
    I created a query rewrite enabled materialized view from a query, which contains only tables (no views). Query rewrite didn't work, so i checked the query with dbms_mview.explan_rewrite, which told my that my query contains references to views or dictionary tables. I checked my query again, but there are only tables, no views, no dictionary tables.
    When I look in the execution plan of my query I see that the query optimizer generates views, I guess from my subquery (?). "A view definition was processed, either from a stored view...or as defined by steps...".
    I suppose that's the reason why my query rewrite doesn't work. All my other mat views are working fine, so the usual parameters (query_rewrite_enabled, integrity, etc.) are set correctly.
    Do you have any ideas how to get my query rewrite enabled work?
    Thanks!

    Modifying the query (potentially with hints) so that Oracle doesn't do the view transformation would be one option.

  • Progammatic update a table with a database view  in the page

    Hi All,
    I am using JDev 11g. With FOD database schema, I have one database view Products which comes from two tables Products_Base and Product_Transactions. I created three EOs (ProductEO, ProductsBaseEO, ProductTransactionsEO) and three VOs (ProductVO, ProductsBaseVO, ProductTransactionsVO) based on their EOs respectively.
    Here is my scenario. I have an ADF form which is based on the database view Products and is dragged and dropped from Data Controls->ProductVO. When an existing record is submitted, a backing bean method will be called to update the data against the table Products_Base (and the table Product_Transactions at the same time) programmatically. An update method updateProductPrice() is added into the Application Module and published it to UI Client. The submit button in the page is created by directly dragging and dropping Data Controls->updateProductPrice into the page. When I run it, I got the following error message,
    Failed to post data to database during "Update": SQL Statement "UPDATE PRODUCTS ProductEO SET COST_PRICE=:1 WHERE PRODUCT_ID=:2".
    What I don't understand here is that, in my update method updateProductPrice(), it supposes to update the table Products_Base. But from the error, it appears that it is trying to update the view Products. Can anyone give me a help on what I did wrong here? When I try to debug it, it throws an exception to this line in the method updateProductPrice(),
    getDBTransaction().commit();
    Here are my codes,
    The method which got called in the backing bean
    public String cb6_action() {
    DCBindingContainer bc = (DCBindingContainer)getBindings();
    FacesCtrlAttrsBinding ProductId = (FacesCtrlAttrsBinding)bc.get("ProductId");
    FacesCtrlAttrsBinding CostPrice = (FacesCtrlAttrsBinding)bc.get("CostPrice");
    JUCtrlActionBinding action =
    (JUCtrlActionBinding)bc.findCtrlBinding("updateProductPrice");
    DCDataControl dc = action.getDataControl();
    ApplicationModule am = (ApplicationModule)dc.getDataProvider();
    AppModule service = (AppModule)am;
    service.updateProductPrice(new Long(ProductId.toString()), CostPrice.toString());
    return null;
    public BindingContainer getBindings() {
    return BindingContext.getCurrent().getCurrentBindingsEntry();
    The update method defined in the Application module (AppModuleImpl.java)
    public void updateProductPrice(long productId, String costPrice) {
    ProductsBaseEOImpl product = retrieveProductById(productId);
    if (product != null) {
    try {
    product.setCostPrice(new Number(costPrice));
    getDBTransaction().commit();
    catch (JboException ex) {
    getDBTransaction().rollback();
    throw ex;
    catch (SQLException ex1) {
    getDBTransaction().rollback();
    private ProductsBaseEOImpl retrieveProductById(long productId) {
    EntityDefImpl productDef = ProductsBaseEOImpl.getDefinitionObject();
    Key productKey = ProductsBaseEOImpl.createPrimaryKey(new DBSequence(productId));
    return (ProductsBaseEOImpl)productDef.findByPrimaryKey(getDBTransaction(),productKey);
    Edited by: john wang on Oct 27, 2009 7:14 AM

    or
    merge into test
    using (select rowid rid
                , id
                , sub_id
                , startdate
                , lead (startdate) over (order by id, sub_id) - 1 ed
           from test) x
    on (x.rid = test.rowid)
    when matched then
       update set end_date = x.ed
    ;

  • Help with a database view/table

    Hi,
    I have seperate oracle9i database on one machine (UNIX).
    Myview view has poor performance in dbtest, but it has good performance in dbdev.
    Both DBs are having relatively similar configuration.
    When I set the autotrace on I realized the indexes are in place on both databases.
    But it takes 2 times more to query dbtest than dbdev.
    Here is the difference when I query both views and the autotrace is on:
    SELECT id from Myview; on DBTEST:
    Statistics
    105 recursive calls
    0 db block gets
    83147 consistent gets
    456 physical reads
    0 redo size
    2777 bytes sent via SQL*Net to client
    400 bytes received via SQL*Net from client
    10 SQL*Net roundtrips to/from client
    4 sorts (memory)
    0 sorts (disk)
    122 rows processed
    SELECT id from Myview; on DBDEV:
    Statistics
    105 recursive calls
    0 db block gets
    42537 consistent gets
    267 physical reads
    0 redo size
    3601 bytes sent via SQL*Net to client
    414 bytes received via SQL*Net from client
    12 SQL*Net roundtrips to/from client
    4 sorts (memory)
    0 sorts (disk)
    157 rows processed
    How can I identify where the problem is? Why "consistent gets" and "physical reads" parameters are about 2 times in DBTEST. I believe this is why I have poor performance in DBTEST.
    Could someone give me a clue on how to idetify the issue?
    Thanks

    "I have seperate oracle9i database on one machine (UNIX)."Correction: "I have two seperate oracle9i database installed on one machine (UNIX).
    Can anyone help me with this? If you need more infor let me know.
    Thanks in advance.

  • Query issue with 9i database only

    Hi,
    I am getting this strage error in 9i database only for the following query. It works perfectly fine in any 8i databases. The query is executed from schema user X with all the referenced tables from schema user B.
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    SELECT COUNT (ref_id), gparent_id, ref_id, ref_value
    FROM (SELECT (SELECT ref_id
    FROM sams_sec_application_setup
    WHERE setup_id = a.setup_id) ref_id,
    (select ref_id from sams_sec_application_setup where setup_id =
    (SELECT parent_id
    FROM sams_sec_application_setup
    WHERE setup_id =
    (SELECT parent_id
    FROM sams_sec_application_setup b
    WHERE setup_id = a.setup_id))) gparent_id,
    (SELECT ref_value
    FROM sams_sec_application_setup
    WHERE setup_id = a.setup_id) ref_value
    FROM sams_sec_security a
    WHERE setup_id IN (
    SELECT setup_id
    FROM sams_sec_application_setup a
    WHERE application_id = (SELECT application_id
    FROM sams_sec_application
    WHERE application_name = 'SOFA')
    AND GROUP_ID = (SELECT GROUP_ID
    FROM sams_sec_group
    WHERE group_name = 'Alliances'))
    AND user_id = 'srikulka '
    AND entity_id IN (
    SELECT a.role_id
    FROM sams_sec_role a,
    sams_sec_permission b,
    sams_sec_role_permission c
    WHERE a.role_id = c.role_id
    AND b.permission_id = c.permission_id
    AND b.permission_name = 'Admin'
    AND b.application_id =
    (SELECT application_id
    FROM sams_sec_application
    WHERE application_name = 'SOFA')))
    GROUP BY ref_id, gparent_id, ref_value;
    The same query executed without any error in 8i databases.
    The query is executed from schema user X with all the referenced tables in schema user B.
    Thanks and regards,
    Ambili

    3113 is a generic error and there are many known reasons for encountering this error. I suggest you search for related docs on Metalink.

  • Inner join query used with 7 Database tables

    HI All,
    In a report they used the Inner join Query with 6 Data base table..now there is a performance issue with at query.
    its taking so much of time to trigger that query. Please help how to avoid that performance issue for that.
    In that 2 database tables containing lakhs of records..
    According to my knowledge it can be avoided by using secondary indexs for those 2 database tables..
    and by replacing the Inner join Query with FOR ALL ENTRIES statement.
    i want how to use the logic by using FORALL ENTRIES statement for this..
    So, please give you proper suggestion to avoid this issue..
    Thanking you.
    Moderator message: Please Read before Posting in the Performance and Tuning Forum
    Edited by: Thomas Zloch on Oct 16, 2011 10:27 PM

    Hi,
    And what do you mean with "they used"? If "SAP used" then yo will need to ask a SAP for note
    FOR ALL ENTRIES is quite good described in help. Please search forum also.
    Without query it won't be possible to tell how it can be optimized, however you can try to use SE30/SAT and ST05. Maybe it will help you.
    BR
    Marcin Cholewczuk

  • Hierarchical Query/START WITH/Remote Database error

    Running on: EE 10.1.0.4.0 - 64bit
    Remote DB: EE 11.1.0.6.0 - 64bit Production
    Trying:
    <PRE>
    WITH
    Moo
    AS
    SELECT
    1
    FROM
    Dual@EPO11_Link A
    CONNECT BY
    LEVEL = 1
    START WITH
    EXISTS (SELECT * FROM Dual@EPO11_Link B WHERE A.Dummy = B.Dummy)
    SELECT
    FROM
    Moo;
    </PRE>
    Getting:
    ORA-00904: "A3"."$nso_col_1": invalid identifier
    ORA-02063: preceding line from EPO11_LINK
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    - The CTE's query runs fine on its own.
    - removing the @ from the first Dual@EPO11_Link , works.
    - removing the @ from the second Dual@EPO11_Link , errors:
    ORA-02016: cannot use a subquery in a START WITH on a remote database
    02016. 00000 - "cannot use a subquery in a START WITH on a remote database"
    *Cause:   
    *Action:
    Error at Line: 10 Column: 24
    - Removing the START WITH clause, works.
    - Changing the START WITH clause's "=" to "IN", works.
    - Changing the START WITH to EXISTS (SELECT * FROM Dual@EPO11_Link B WHERE A.Dummy = B.Dummy) results in:
    ORA-00904: "A3"."DUMMY": invalid identifier
    ORA-02063: preceding line from EPO11_LINK
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Am i missing something here?
    Edited by: Brian Tkatch on Jan 19, 2012 1:27 PM

    Searching error messages books:
    These have the ORA-02016:
    8: http://docs.oracle.com/cd/A58617_01/server.804/a58312/newch228.htm#19589
    9: http://docs.oracle.com/cd/A91202_01/901_doc/server.901/a90202/e1500.htm#1001663
    These do not have the ORA-02016:
    10R1: http://docs.oracle.com/cd/B14117_01/server.101/b10744/e1500.htm#ORA-02009
    10R2: http://docs.oracle.com/cd/B19306_01/server.102/b14219/e1500.htm#ORA-02009
    11R1: http://docs.oracle.com/cd/B28359_01/server.111/b28278/e1500.htm#ORA-02009
    Starting with (heh) 10R1 a bunch of error messages were removed regarding hierarchical queries, including this one.
    Is it allowed or not?

  • Jdeveloper problem with the dataBase view

    Hi all
    hope your fine
    i have toad database and jdeveloper 10g installed on our
    machine. i connect our database in jdeveloper by using new
    database connection wizard.and the test connection give success ..
    the problem is i can see all the tables and views data but the views that i have access to view from another schema i can see in toad but not in jdeveolper ?!!
    so why is it ?

    Check if you have a filter defined on your database connection.
    If you can upgrade to 11g, then you'll find the other users on the "Other Users" section of the database browser.

  • UpdateXML query rewrite with unstructured data?

    Hi,
    I'm currently loading unstructured, non-schema based XML and am trying to address some performance issues when I merge changes to a document.
    I currently read the document from the table, merge the changes using XQuery and save the document back - however, I'm aware that this can be excessive when a minor number of changes are involved (I'm also seeing some contention on the path table when a number of parallel threads are involved).
    I know that using "updateXML" and "insertChildXML" can be more efficient due to the XPath rewrite - however, I'm not sure if this is applicable when the XML is unstructured and non-schema based.
    Any advice on this would be greatly appreciated.
    Regards
    Larry

    Hi Larry,
    I know that using "updateXML" and "insertChildXML" can be more efficient due to the XPath rewrite - however, I'm not sure if this is applicable when the XML is unstructured and non-schema based.XPath rewrite applies to structured (Object-Relational) storage, but to Binary XML and/or XMLIndex as well.
    Besides, with Binary XML and a SECUREFILE LOB storage, a "sliding update" is used when the data is written back to disk (only the modified portion of the LOB is affected) thus reducing the overhead of writing whole documents over and over again even for small changes.
    For example (OOX_SML_WORKBOOK is a binary XMLType table here) :
    -- unstructured XMLIndex with path-subsetting :
    CREATE INDEX oox_sml_workbook_uxi1 ON oox_sml_workbook (object_value) INDEXTYPE IS XDB.XMLIndex
      PARAMETERS ('PATH TABLE oox_sml_workbook_ptb
      PATHS (INCLUDE (/workbook/sheets/sheet)
                         NAMESPACE MAPPING (xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"))');
    -- update of an attribute using updateXML function :
    update oox_sml_workbook
    set object_value = updateXML( object_value
                                , '/workbook/sheets/sheet[@sheetId="3"]/@name'
                                , 'NewName'
                                , 'xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"' )
    where xmlexists('declare default element namespace "http://schemas.openxmlformats.org/spreadsheetml/2006/main"; (::)
                     /workbook/sheets/sheet[@sheetId="3"]'
                    passing object_value)
    ;If you're lucky and currently working with the latest patchset (11.2.0.3), you can also use XQuery Update Facility, a small extension to the XQuery standard that allows various kinds of operations on nodes : inserting (after/before), updating, renaming and deleting.
    This extension supersedes the old proprietary functions updateXML, insertXML etc.
    And it can be optimized via XPath/XQuery rewrite too :
    update oox_sml_workbook
    set object_value =
        xmlquery('declare default element namespace "http://schemas.openxmlformats.org/spreadsheetml/2006/main"; (::)
                  copy $d := .
                  modify (
                    for $i in $d/workbook/sheets/sheet
                    return replace value of node $i/@name with concat("MySheet",$i/@sheetId)
                  return $d'
                  passing object_value
                  returning content)
    ;

  • Query works with indexs but view does not

    Hi,
    I am using the following query:
    SQL> select t.xml_msg_text
    2 from xml_tbl t
    3 where xmlexists (
    4 'declare namespace ns1 = "Abc:SET"; fn:collection("oradb:/DEV/TABLE1")/ROW[ID1=$d/main/ns1:id]'
    5 passing t.xml_msg_text as "d"
    6 );
    It gets executed very fast as it uses the underlying XMLType indexes.
    But if I create a view usign this query. And then Select * from View_Name. It does not use the indexes and takes forever to execute.
    Any suggestions please.
    Thanks..

    Actually I can't create the Explain Plan for this in SqlPlus:
    In the following query:
    select t.xml_msg_text
    from xml_tbl t
    where xmlexists (
    'declare namespace ns1 = "Abc:SET"; fn:collection("oradb:/DEV/TABLE1")/ROW[ID1=$d/main/ns1:id]'
    passing t.xml_msg_text as "d"
    WHEREAS
    I can create the Explain Plan for
    select t.xml_msg_text
    from xml_tbl t
    - There is XQuery Code
    - And TABLE1 is in another schema but I have created the synonym and given the proper rights. That's why I can execute the query but can't see the plan in SQL Plus.
    Please suggest.
    Thanks..

  • Materialized views on prebuilt tables - query rewrite

    Hi Everyone,
    I am currently counting on implementing the query rewrite functionality via materialized views to leverage existing aggregated tables.
    Goal*: to use aggregate-awareness for our queries
    How*: by creating views on existing aggregates loaded via ETL (+CREATE MATERIALIZED VIEW xxx on ON PREBUILT TABLE ENABLE QUERY REWRITE+)
    Advantage*: leverage oracle functionalities + render logical model simpler (no aggregates)
    Disadvantage*: existing ETL's need to be written as SQL in view creation statement --> aggregation rule exists twice (once on db, once in ETL)
    Issue*: Certain ETL's are quite complex via lookups, functions, ... --> might create overy complex SQLs in view creation statements
    My question: is there a way around the issue described? (I'm assuming the SQL in the view creation is necessary for oracle to know when an aggregate can be used)
    Best practices & shared experiences are welcome as well of course
    Kind regards,
    Peter

    streefpo wrote:
    I'm still in the process of testing, but the drops should not be necessary.
    Remember: The materialized view is nothing but a definition - the table itself continues to exist as before.
    So as long as the definition doesn't change (added column, changed calculation, ...), the materialized view doesn't need to be re-created. (as the data is not maintained by Oracle)Thanks for reminding me but if you find a documented approach I will be waiting because this was the basis of my argument from the beginning.
    SQL> select * from v$version ;
    BANNER                                                                                                                                                                    
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production                                                                                                    
    PL/SQL Release 11.2.0.1.0 - Production                                                                                                                                    
    CORE     11.2.0.1.0     Production                                                                                                                                                
    TNS for Linux: Version 11.2.0.1.0 - Production                                                                                                                            
    NLSRTL Version 11.2.0.1.0 - Production                                                                                                                                    
    SQL> desc employees
    Name                                                                                            Null?    Type
    EMPLOYEE_ID                                                                                     NOT NULL NUMBER(6)
    FIRST_NAME                                                                                               VARCHAR2(20)
    LAST_NAME                                                                                       NOT NULL VARCHAR2(25)
    EMAIL                                                                                           NOT NULL VARCHAR2(25)
    PHONE_NUMBER                                                                                             VARCHAR2(20)
    HIRE_DATE                                                                                       NOT NULL DATE
    JOB_ID                                                                                          NOT NULL VARCHAR2(10)
    SALARY                                                                                                   NUMBER(8,2)
    COMMISSION_PCT                                                                                           NUMBER(2,2)
    MANAGER_ID                                                                                               NUMBER(6)
    DEPARTMENT_ID                                                                                            NUMBER(4)
    SQL> select count(*) from employees ;
      COUNT(*)                                                                                                                                                                
           107                                                                                                                                                                
    SQL> create table mv_table nologging as select department_id, sum(salary) as totalsal from employees group by department_id ;
    Table created.
    SQL> desc mv_table
    Name                                                                                            Null?    Type
    DEPARTMENT_ID                                                                                            NUMBER(4)
    TOTALSAL                                                                                                 NUMBER
    SQL> select count(*) from mv_table ;
      COUNT(*)                                                                                                                                                                
            12                                                                                                                                                                
    SQL> create materialized view mv_table on prebuilt table with reduced precision enable query rewrite as select department_id, sum(salary) as totalsal from employees group by department_id ;
    Materialized view created.
    SQL> select count(*) from mv_table ;
      COUNT(*)                                                                                                                                                                
            12                                                                                                                                                                
    SQL> select object_name, object_type from user_objects where object_name = 'MV_TABLE' ;
    OBJECT_NAME                                                                                                                      OBJECT_TYPE                              
    MV_TABLE                                                                                                                         TABLE                                    
    MV_TABLE                                                                                                                         MATERIALIZED VIEW                        
    SQL> insert into mv_table values (999, 100) ;
    insert into mv_table values (999, 100)
    ERROR at line 1:
    ORA-01732: data manipulation operation not legal on this view
    SQL> update mv_table set totalsal = totalsal * 1.1 where department_id = 10 ;
    update mv_table set totalsal = totalsal * 1.1 where department_id = 10
    ERROR at line 1:
    ORA-01732: data manipulation operation not legal on this view
    SQL> delete from mv_table where totalsal <= 10000 ;
    delete from mv_table where totalsal <= 10000
    ERROR at line 1:
    ORA-01732: data manipulation operation not legal on this view While investigating for this thread I actually made my own question redundant as the answer became gradually clear:
    When using complex ETL's, I just need to make sure the complexity is located in the ETL loading the detailed table, not the aggregate
    I'll try to clarify through an example:
    - A detailed Table DET_SALES exists with Sales per Day, Store & Product
    - An aggregated table AGG_SALES_MM exists with Sales, SalesStore per Month, Store & Product
    - An ETL exists to load AGG_SALES_MM where Sales = SUM(Sales) & SalesStore = (SUM(Sales) Across Store)
    --> i.e. the SalesStore measure will be derived out of a lookup
    - A (Prebuilt) Materialized View will exist with the same column definitions as the ETL
    --> to allow query-rewrite to know when to access the table
    My concern was how to include the SalesStore in the materialized view definition (--> complex SQL!)
    --> I should actually include SalesStore in the DET_SALES table, thus:
    - including the 'Across Store' function in the detailed ETL
    - rendering my Aggregation ETL into a simple GROUP BY
    - rendering my materialized view definition into a simple GROUP BY as wellNot sure how close your example is to your actual problem. Also don't know if you are doing an incremental/complete data load and the data volume.
    But the "SalesStore = (SUM(Sales) Across Store)" can be derived from the aggregated MV using analytical function. One can just create a normal view on top of MV for querying. It is hard to believe that aggregating in detail table during ETL load is the best approach but what do I know?

Maybe you are looking for

  • Posting Date in PSA for 2LIS_03_BX

    Hi, When I am executing 2LIS_03_BX for Stock Init, Posting Date in PSA is showing todays date. Why this is happening? I run the IP on 9/12/2011, in PSA the posting dates are 9/12/2011 but in R/3 Side the dates are different. Basically I want the old

  • Using applets in forms 9i

    i am trying to use an "normal" applet (myapplet) designed for use in a html-page in forms9i. properties in applet can be set as "<param name="image1" value="1.jpg">... i used jdevloper to create a wrapper-bean: new->beans->Oracle Forms Pluggable Java

  • Tab Font size

    Hello please how to change the font size and color of a tab label ? thanks

  • Middle button stuck thinkpad T440s

    Hey, i get a strange behavior from Synaptics. on my new T440s laptop there is no dedicated middle button, it's just a touchpad that can be clicked as a whole and is divided to left middle and right click logically by synaptics. The problem is, after

  • Can't do a factory reset from preinstall directory

    Hi I have a Satellite Pro L450D laptop I bought just over 12 months ago. It has an AMD Sempron processor - Window 7 Home Edition - 32bit system. My problem is the laptop has become so slow that is has become impossible to use it. I do have Kaspersky