XMLType and materialized subquery factoring

Hi,
Out of curiosity, I've been wondering what kind of storage is used when a view with an XMLType column gets materialized, for example via the WITH clause.
So I tried :
SQL> select * from v$version;
BANNER
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Beta
PL/SQL Release 11.2.0.2.0 - Beta
CORE    11.2.0.2.0      Production
TNS for 32-bit Windows: Version 11.2.0.2.0 - Beta
NLSRTL Version 11.2.0.2.0 - Production
SQL> with t as (
  2    select /*+ materialize */
  3           xmltype('<root>Hello!</root>') as doc
  4    from dual
  5  )
  6  select doc
  7  from t
  8  ;
with t as (
ERROR at line 1:
ORA-00600: internal error code, arguments: [kkdlsexp:qbcp], [], [], [], [], [],
[], [], [], [], [], []Apparently, that's bug #9372157 "WITH clause with XML causes OERI [kkdlsexp:qbcp]" which should have been fixed in 11.2.0.2, but maybe not in XE?
Well, my question is : could someone having access to a full 11.2.0.2 EE check it?
Below is a working example on a "regular" view, describing how to do it :
SQL> set autotrace on
SQL> with t as (
  2    select /*+ materialize */
  3           cast('Hello' as varchar2(30)) as text1,
  4           cast('World' as varchar2(30)) as text2
  5    from dual
  6  )
  7  select text1, text2
  8  from t
  9  ;
TEXT1                          TEXT2
Hello                          World
Execution Plan
Plan hash value: 2441519912
| Id  | Operation                  | Name                     | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT           |                          |     1 |    34 |     4   (0)| 00:00:01 |
|   1 |  TEMP TABLE TRANSFORMATION |                          |       |       |            |          |
|   2 |   LOAD AS SELECT           | SYS_TEMP_0FD9D6618_E893C |       |       |            |          |
|   3 |    FAST DUAL               |                          |     1 |       |     2   (0)| 00:00:01 |
|   4 |   VIEW                     |                          |     1 |    34 |     2   (0)| 00:00:01 |
|   5 |    TABLE ACCESS FULL       | SYS_TEMP_0FD9D6618_E893C |     1 |    34 |     2   (0)| 00:00:01 |
Statistics
          2  recursive calls
          8  db block gets
          4  consistent gets
          1  physical reads
        576  redo size
        487  bytes sent via SQL*Net to client
        419  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
SQL> desc sys.SYS_TEMP_0FD9D6618_E893C
Name                        Null?    Type
C0                                   VARCHAR2(30)
C1                                   VARCHAR2(30)Thanks.

SQL> show parameter compatible
NAME                                 TYPE        VALUE
compatible                           string      11.2.0.0.0

Similar Messages

  • Subquery Factoring and Materialized Hint

    WITH t AS
            (SELECT MAX (lDATE) tidate
               FROM rate_Master
              WHERE     Code = 'G'
                    AND orno > 0
                    AND TYPE = 'L'
                    AND lDATE <= ':entereddate')
    SELECT DECODE (:p1,  'B', RateB,  'S', RateS,  Rate)
      FROM rate_Master, t
    WHERE     Code = 'G'
           AND orno > 0
           AND TYPE = 'L'
           AND NVL (lDATE, SYSDATE) = tidate;In the given example the sub query returns just one row because of the aggregate function max. Making this in to a With clause will be of any benefit ? Also i presume/understand that the subquery factoring would be really useful only when we try to make a sub query which returns more rows in a with clause. Is my intrepration right?
    Secondly adding the /*+ Materialize */ hint to a With query is mandatory or the optimizer by itself will do it and make a temp table transformation. In my example i am forced to give the hint in the query. Please discuss and help
    Thanks in advance.

    ramarun wrote:
    WITH t AS
    (SELECT MAX (lDATE) tidate
    FROM rate_Master
    WHERE     Code = 'G'
    AND orno > 0
    AND TYPE = 'L'
    AND lDATE <= ':entereddate')
    SELECT DECODE (:p1,  'B', RateB,  'S', RateS,  Rate)
    FROM rate_Master, t
    WHERE     Code = 'G'
    AND orno > 0
    AND TYPE = 'L'
    AND NVL (lDATE, SYSDATE) = tidate;In the given example the sub query returns just one row because of the aggregate function max. Making this in to a With clause will be of any benefit ? Also i presume/understand that the subquery factoring would be really useful only when we try to make a sub query which returns more rows in a with clause. Is my intrepration right?I am not aware of any performance Benefit due to use of With clause. IMO, It eases the job to write a Subquery multiple times in a query.
    The solution you adopted has to hit the cache twice and hence do not look very performant. I will advise you to opt for Analytic functions (like the suggestion I provided in another thread). If the solution does not yeild correct results, then provide with a Script that we can replicate (Create table, Sample Insert statement and the expected output).
    select decode(:p1, 'B', RateB, 'S', RateS, Rate)
       from (
                select RateB, RateS, Rate, NVL(ldate, sysdate) ldate, dense_rank() over (order by case when NVL(lDATE, SYSDATE) <= ':entereddate' then NVL(lDATE, SYSDATE) else to_date('01/01/1970', 'DD/MM/YYYY' end DESC) rn
                  from rate_Master
               where Code = 'G'
                   and orno > 0
                   and type = 'L'
             ) a
      where a.rn = 1;>
    Secondly adding the /*+ Materialize */ hint to a With query is mandatory or the optimizer by itself will do it and make a temp table transformation. In my example i am forced to give the hint in the query. Please discuss and help
    Usage of Hints is only for Debugging purposes and is not meant to be used in production code. It is when you have to ascertain the reason for CBO choosing a plan that you do not expect it to take, you use hints to force your plan and find the cost and analyze it. Hence, I do not support the idea of Hints for production code.

  • Subquery factoring and DB Link

    Hello,
    2 node RAC
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE    10.2.0.5.0      Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - ProductionI have a query of the form..
    WITH temp as
                 (select col1, col2, col3 from LOCAL_TABLE)
               SELECT /*+ driving_site (remote1) */
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote2.col1,
                 remote2.col1,
                 remote2.col1,
                 remote2.col1,
                 remote2.col1,
                 null,
                 null
              from remote_view1@dblink remote1, -- Remote View over 2 dbs
                     remote_view2@dblink remote2  -- Remote View over 2 dbs
               where remote1.col1 in (select col1 from temp);This query used to work, but recently there has been a change in remote_view1 after which the query takes a long time to execute.
    The good performing query takes 2 secs, while the bad performing one takes about 8 minutes.
    However, if I remove the subquery factoring and include the query as a sub-query it works well.
               SELECT /*+ driving_site (remote1) */
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote1.col1,
                 remote2.col1,
                 remote2.col1,
                 remote2.col1,
                 remote2.col1,
                 remote2.col1,
                 null,
                 null
              from remote_view1@dblink remote1, -- Remote View over 2 dbs
                     remote_view2@dblink remote2  -- Remote View over 2 dbs
               where remote1.col1 in  (select col1, col2, col3 from LOCAL_TABLE);I tried to check the data from v$sql. I observed that;
    v$sql.remote = 'Y' - good performance
    v$sql.remote = 'N' - bad performance
    Has anyone faced this situation ?
    Rgds,
    Gokul

    Am I right in assuming that queries executed entirely on remote db don't have plans stored in v$sql_planRight.
    SQL> select /*+ domtest */ 1 from dual@domtest;
             1
             1
    SQL> select * from table(dbms_xplan.display_cursor);
    PLAN_TABLE_OUTPUT
    SQL_ID  9d51rf84zvt0s, child number 0
    select /*+ domtest */ 1 from dual@domtest
    NOTE: cannot fetch plan for SQL_ID: 9d51rf84zvt0s, CHILD_NUMBER: 0
          Please verify value of SQL_ID and CHILD_NUMBER;
          It could also be that the plan is no longer in cursor cache (check v$sql_plan)
    8 rows selected.
    SQL> select sql_id, remote, sql_text from v$sql where sql_id = '9d51rf84zvt0s';
    SQL_ID        R SQL_TEXT
    9d51rf84zvt0s Y select /*+ domtest */ 1 from dual@domtest
    SQL> select * from v$sql_plan where sql_id = '9d51rf84zvt0s';
    no rows selected
    SQL> select /*+ domtest */ 1 from dual@domtest t, dual;
             1
             1
    Elapsed: 00:00:00.00
    SQL> select * from table(dbms_xplan.display_cursor);
    PLAN_TABLE_OUTPUT
    SQL_ID  d0m08znks4yak, child number 0
    select /*+ domtest */ 1 from dual@domtest t, dual
    Plan hash value: 3754369022
    | Id  | Operation            | Name | Rows  | Cost (%CPU)| Time     | Inst   |IN-OUT|
    |   0 | SELECT STATEMENT     |      |       |     4 (100)|          |        |      |
    |   1 |  MERGE JOIN CARTESIAN|      |     1 |     4   (0)| 00:00:01 |        |      |
    |   2 |   REMOTE             | DUAL |     1 |     2   (0)| 00:00:01 | DOMTE~ | R->S |
    |   3 |   BUFFER SORT        |      |     1 |     2   (0)| 00:00:01 |        |      |
    |   4 |    FAST DUAL         |      |     1 |     2   (0)| 00:00:01 |        |      |
    Remote SQL Information (identified by operation id):
       2 - SELECT 0 FROM "DUAL" "T" (accessing 'DOMTEST' )
    22 rows selected.
    Elapsed: 00:00:00.04
    SQL> select sql_id, remote, sql_text from v$sql where sql_id = 'd0m08znks4yak';
    SQL_ID        R SQL_TEXT
    d0m08znks4yak N select /*+ domtest */ 1 from dual@domtest t, dua
    SQL> select /*+ driving_site(t) */ 1 from dual@domtest t, dual;
             1
             1
    Elapsed: 00:00:00.00
    SQL> select * from table(dbms_xplan.display_cursor);
    PLAN_TABLE_OUTPUT
    SQL_ID  741u736nrk6dx, child number 0
    select /*+ driving_site(t) */ 1 from dual@domtest t, dual
    NOTE: cannot fetch plan for SQL_ID: 741u736nrk6dx, CHILD_NUMBER: 0
          Please verify value of SQL_ID and CHILD_NUMBER;
          It could also be that the plan is no longer in cursor cache (check v$sql_plan)
    8 rows selected.
    Elapsed: 00:00:00.01
    SQL> select sql_id, remote, sql_text from v$sql where sql_id = '741u736nrk6dx';
    SQL_ID        R SQL_TEXT
    741u736nrk6dx Y select /*+ driving_site(t) */ 1 from dual@domtest
                    t, dual
    Elapsed: 00:00:00.00
    SQL>
    SQL> select * from v$sql_plan where sql_id = '741u736nrk6dx';
    no rows selected
    Elapsed: 00:00:00.01
    SQL> Edited by: Dom Brooks on Aug 21, 2012 1:05 PM

  • Bug in WITH clause (subquery factoring clause) in Oracle 11?

    I'm using WITH to perform a set comparison in order to qualify a given query as correct or incorrect regarding an existing solution. However, the query does not give the expected result - an empty set - when comparing the solution to itself in Oracle 11 whereas it does in Oracle 10. A minimal example os posted below as script. There are also some observations about changes to the tables or the query that make Oracle 11 returning correct results but in my opinion these changes must not change the semantics of the queries.
    Is this a bug or am I getting something wrong? The Oracle versions are mentioned in the script.
    -- Bug in WITH clause (subquery factoring clause)
    -- in Oracle Database 11g Enterprise Edition 11.2.0.1.0?
    DROP TABLE B PURGE;
    DROP TABLE K PURGE;
    DROP TABLE S PURGE;
    CREATE TABLE S (
         m     number NOT NULL,
         x     varchar2(30) NOT NULL
    CREATE TABLE K (
         k char(2) NOT NULL,
         x varchar2(50) NOT NULL
    CREATE TABLE B (
         m     number NOT NULL ,
         k char(2) NOT NULL ,
         n     number
    INSERT INTO S VALUES(1, 'h');
    INSERT INTO S VALUES(2, 'l');
    INSERT INTO S VALUES(3, 'm');
    INSERT INTO K VALUES('k1', 'd');
    INSERT INTO K VALUES('k2', 'i');
    INSERT INTO K VALUES('k3', 'm');
    INSERT INTO K VALUES('k4', 't');
    INSERT INTO K VALUES('k5', 't');
    INSERT INTO K VALUES('k6', 's');
    INSERT INTO B VALUES(1, 'k1', 40);
    INSERT INTO B VALUES(1, 'k2', 30);
    INSERT INTO B VALUES(1, 'k4', 50);
    INSERT INTO B VALUES(3, 'k1', 10);
    INSERT INTO B VALUES(3, 'k2', 20);
    INSERT INTO B VALUES(3, 'k1', 30);
    INSERT INTO B VALUES(3, 'k6', 90);
    COMMIT;
    ALTER TABLE S ADD CONSTRAINT S_pk PRIMARY KEY (m);
    ALTER TABLE K ADD CONSTRAINT K_pk PRIMARY KEY (k);
    ALTER TABLE B ADD CONSTRAINT B_S_fk
    FOREIGN KEY (m) REFERENCES S(m) ON DELETE CASCADE;
    CREATE OR REPLACE VIEW v AS
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC;
    -- Query 1: Result should be 0
    WITH q AS
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    SELECT COUNT(*)
    FROM
    SELECT * FROM q
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM q
    -- COUNT(*)
    -- 6
    -- 1 rows selected
    -- Query 2: Result set should be empty (Query 1 without counting)
    WITH q AS
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    SELECT *
    FROM
    SELECT * FROM q
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM q
    -- M N
    -- null 10
    -- null 30
    -- null 40
    -- 1 40
    -- 3 10
    -- 3 30
    -- 6 rows selected
    -- Observations:
    -- Incorrect results in Oracle Database 11g Enterprise Edition 11.2.0.1.0:
    -- Query 1 returns 6, Query 2 returns six rows.
    -- Correct in Oracle Database 10g Enterprise Edition 10.2.0.1.0.
    -- Correct without the foreign key.
    -- Correct if attribute x is renamed in S or K.
    -- Correct if attribute x is left out in S.
    -- Correct without the ORDER BY clause in the definition of q.
    -- Only two results if the primary key on K is left out.
    -- Correct without any change if not using WITH but subqueries (see below).
    -- Fixed queries
    -- Query 1b: Result should be 0
    SELECT COUNT(*)
    FROM
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    -- COUNT(*)
    -- 0
    -- 1 rows selected
    -- Query 2b: Result set shoud be empty (Query 1b without counting)
    SELECT *
    FROM
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    -- M N
    -- 0 rows selected

    You're all gonna love this one.....
    The WITH clause works. But not easily.
    Go ahead, build the query, (as noted in a recent thread, I, too, always use views), set the grants and make sure DISCOVERER and EULOWNER have SELECT privs.
    1. Log into Disco Admin as EULOWNER. Trust me.
    2. Add the view as a folder to the business area.
    3. Log into Disco Desktop as EULOWNER. Don't laugh. It gets better.
    4. Build the workbook and the worksheet (or just the worksheet if apropos)
    5. Set the appropriate "sharing" roles and such
    6. Save the workbook to the database.
    7. Save the workbook to your computer.
    8. Log out of Desktop.
    9. Log back into Desktop as whatever, whoever you usually are to work.
    10. elect "open existing workbook"
    11. Select icon for "open from my computer". See? I told you it would get better!
    12. Open the save .dis file from your computer.
    13. Save it to the database.
    14. Open a web browser and from there, you're on your own.
    Fortran in VMS. Much easier and faster. I'm convinced the proliferation of the web is a detriment to the world at large...On the other hand, I'm also waiting for the Dodgers to return to Brooklyn.

  • How to use subquery factoring ("with" clause) in OWB?

    Hi,
    Is it possible to use subquery factoring (popularly known as "with" clause) in OWB 10gR2? I have a mapping with a splitter and union-all, which generates a query that has repeated scans of the same table. Subquery Factoring would be very useful here. I think this is a very common situation, so, I hope there's a way to achieve this. (If not in this version, this would be my wishlist item for the next version.)
    Appreciate your help.
    Regards,
    Rahul

    Hi Rahul,
    I'm afraid you have to put this on your wishlist. You may put the query with the "with"-clause into a view (or table function if you need parameters) if performance is too bad. But that is somehow against the idea (and benefits) of owb.
    Another possibility is to use a temporary table and spilt the mappings into two parts: first fill the temp table, then the target table.
    Regards,
    Carsten.

  • Oracle equals_path condition NOT working with table and materialized view

    The user i am using is xdb with dba role.
    1.When i try to use the statement
    SELECT PATH FROM xdb.path_VIEW
    WHERE
    EQUALS_PATH(res, '/home/OE/PurchaseOrders/2002')=1
    the result is
    /home/OE/PurchaseOrders/2002
    2. When i drop the path_view and recreated it like materialized view with statement
    create MATERIALIZED view path_view as
    select /*+ ORDERED */ t2.path path, t.res res,
    xmltype.createxml(xdb.xdb_link_type(NULL, r2.xmldata.dispname, t.name,
    h.name, h.flags, h.parent_oid, h.child_oid),
    'http://xmlns.oracle.com/xdb/XDBStandard.xsd', 'LINK') link,
    t.resid
    from ( select xdb.all_path(9999) paths, value(p) res, p.sys_nc_oid$ resid,
    p.xmldata.dispname name
    from xdb.xdb$resource p
    where xdb.under_path(value(p), '/', 9999)=1 ) t,
    TABLE( cast (t.paths as xdb.path_array) ) t2,
    xdb.xdb$h_link h, xdb.xdb$resource r2
    where t2.parent_oid = h.parent_oid and t2.childname = h.name and
    t2.parent_oid = r2.sys_nc_oid$
    then the equals_path condition STOP working !!!
    3. The same experiment, but i recreate it like table
    create table path_view as .... using the rest of the statement ...
    Can someone help me to understand why equals_path is NOT working on table and materialized view !

    Thanks Jonah. I was under the impression that I already had it but seems like it has to be a direct priv - thru a role doesn't work.
    I granted the reqd privs and then it worked fine. Thx for your help!

  • Recursive WITH (Recursive Subquery Factoring) Never Returns

    11.2.0.2 database on Windows, SQL Developer Version 3.2.20.09, build MAIN-09.87 (Database and SQL Developer are on the same machine. I have also tried connecting to a Linux 11.2 database and have the same results.)
    I've been doing some simple testing with recursive WITH (Recursive Subquery Factoring) and when I run this following statement in SQL*Plus it returns instantly. However when running in SQL Developer it never returns, I've let it run for quite a long time (172 seconds) and gotten nothing, I finally kill the statement. Once I ran it and even killing the job didn't come back. I can get an explain plan but if I try to run it, run as script or autotrace it never returns. I have only one plan in the plan_table for this test, and it's only 4 lines long. No errors, no messages.
    WITH get_plan (query_plan, id, planlevel) as
    select ' '||operation||' '||options||' '||object_name query_plan, id, 1 planlevel
    from plan_table
    where id = 0
    union all
    select lpad(' ',2*planlevel)||p.operation||' '||p.options||' '||p.object_name query_plan, p.id, planlevel+1
    from get_plan g, plan_table p
    where g.id = p.parent_id
    SELECT QUERY_PLAN FROM GET_PLAN ORDER BY PLANLEVEL;

    Hi Jeff, using either give the same results. The query is "running", as is the little graphic with the bouncing gray bar is moving back and forth saying either "Query Results" or "Scriptrunner Task" as appropriate.
    OK this is odd. I run a count(*) on plan_table in SQL*Plus and get 4, in SQL Developer I get 487. Hun? That makes no sense I'm connect as the same user in each. Where are all these other entries coming from and why can't I see them in SQL Plus? Does SQL Developer have it's own PLAN_TABLE?
    **EDIT --- Yes that seems to be the case. The PLAN_ID I see in SQL Plus doesn't even exist in the SQL Deveropler version of the table. OK that's good to know. I assume the plan_table for SQL Developer is local to it somehow? It's not in the database as best I can see.
    Edited by: Ric Van Dyke on Feb 7, 2013 5:19 PM

  • Subquery Factoring -Performance Issue

    Hi experts,
    Oracle 10G
    select
    a.colums,
    b.columns
    from
    ( select
    Colums
    from
    F ,
    (select
    columns
    from
    bigtable
    where
    <condition with recdate and modified date with timezone convertions Given as in end of this qury)
    ) a,
    ( select
    Colums
    from
    tables,
    (select
    columns
    from
    bigtable
    where
    <condition with recdate and modified date with timezone convertions Given as in end of this qury)
    ) b
    (TO_DATE(TO_CHAR(FROM_TZ(CAST(CF.RECDT as timestamp),'GMT') at time zone 'America/Chicago','YYYY-MM-DD
    HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')
         BETWEEN TO_DATE('01-JAN-2009 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('08-JAN-2009 00:00:00', 'DD-MON-YYYY
    HH24:MI:SS')) OR
    (TO_DATE(TO_CHAR(FROM_TZ(CAST(CF.MODIFID_DT as timestamp),'GMT') at time zone 'America/Chicago','YYYY-MM-DD
    HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS')
    BETWEEN TO_DATE('01-JAN-2009 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('08-JAN-2009 00:00:00', 'DD-MON-YYYY
    HH24:MI:SS'))
    Recdt - indexed
    Modifieddt - not iddexed
    bigtable used many times in select to avoid Subquery factoring used (with select) but it increased cost as per explain plan in sqldevleoper please suggest me to increase performance
    Lots of thanks,
    Kalinga

    now the above query use as
    with subfact as
    ( select
    select
    columns
    from
    bigtable
    where
    <condition with recdate and modified date
    select
    a.colums,
    b.columns
    from
    ( select
    Colums
    from
    F ,
    subfact
    where condition
    ) a,
    ( select
    Colums
    from
    tables,
    subfact
    where condition
    ) b
    it is cost increased in nested loop in explain plan why? is thre any other detail required.

  • WITH Subquery Factoring OR "Scalar SubqueriesRun Another Query per row

    Hi Experts
    Please suggest
    which one query is better
    Involved table p is of size 2GB and c1/c2 of size 800M.
    And we have to run a report on p which will do FTS (no where clause on p)
    So FTS on 2 GB table and then running Another Query per row .. so results job very slow
    1)  Select p.id,
             (select sum(q1) from c1 where c1.id = p.id) c1_sum1,
             (select sum(q2) from c2 where c2.id = p.id) c2_sum2
       from p
    2)
    WITH Subquery Factoring
    with c1_vw as
    (select id, sum(q1) c1_sum1
        from c1
             group by id),
       c2_vw as
       (select id, sum(q2) c2_sum2
           from c2
          group by id),
       c1_c2 as
       (select c1.id, c1.c1_sum1, c2.c2_sum2
           from c1_vw c1, c2_vw c2
          where c1.id = c2.id )
       select p.id, c1_sum1, c2_sum2
          from p, c1_c2
         where p.id = c1_c2.id
       / 10.2..0.4
    AIX 5.3
    Thanks In Advance
    ivw

    ivw wrote:
    which one query is betterThe better query IMHO is the one that returns the the correct results in the shortest amount of time using the least system resources (the last two items usually happen at the same time). Maintainability is an issue too. Which one do you like best?
    Its hard to say which query will run best without running both, getting execution plans, and run-time statistics. At a pure guess I would think all things being equal they would have similar performance but do not really know.

  • With clause of select (subquery factoring)

    I've got a script that looks like this:
    with X as (select * from atable)
    select x1.*, x2.*
    from X x1,
    X x2
    This works perfectly well in SQL*Plus, in PL/SQL, etc. Yet when I try to add it as "New Folder from Database" to an existing Business area in Discoverer, I get the infamous "ORA-03001 Unimplemented Feature".
    What am I doing wrong?
    Oracle 9i, Disco 9.0.4

    Hi,
    You will have to define a database view containing your query and load the view into your database. I don't think you can use subquery factoring in a custom folder.
    Rod West

  • What are the precautions to be taken while archiving the POs' and Material

    Hi All,
    I want to archive the Purchase orders and Material documents. Is there any standard rule to follow this procedure. What are the further consequences for the consecutive documents. And how do you check the open POs' of all.
                                 I have archived PRs' and Invoices, but these are not interlinked.
    Could you please help me in this, so that I will be very much thankful to you.
    Regards,
    Ram

    Dear Ramesh,
    Go to Tcode ARCHGUIDE --> Application Specific analyses and setting --> MM -->MM_EKKO and MM_MABTEL
    You can tick on the documentation and link to SAP help for all the guide and need for this archiving.
    Regards,
    w1n

  • Issue to make mandatory field(SELD/BBD and Date of manufactor)in migo for particular Material type and material Number starting with'1' series.

    Hi friend,
    i have issue regarding mandatory  self life field (SELD/BBD and Date of manufactor)in migo for Batch Tab for particular Material start with '1' Series and material type.
    i want to make mandatory above field during GR from migo..any one let me know exit or badi for that to full fill this goal..
    Regard's,
    shaikh Khalid.

    Hi Shaikh
    First of all Thread is not closed seconldy as a good practice if you have resolved your issue kindly document it here so that it may help someone in future
    Nabheet

  • PO number and material issued against this PO for subcontracting

    How to know the link in between the PO number and material issued against this PO for subcontracting.
    I have checked that PO history is not getting updated.
    Thanks,

    Hi,
    We have 2 different scenarios where you can post a goods issue to Subcontract Venodrs.
    Scenarios 1: You can post the goods issue against a subcontrac vendor with out referencing the Subcon PO from ME2O, at this stage we will be knowing what is the stock at subcontract vendor but we will not be knowing the issues against which and how much Quantities are posted.
    So when we are post goods receipt, then we will come to know the consuption quantities.
    Scenario: 2, If we use the delivery concept then we can track the goods issues against the subcon POs.
    If you really keen to track the material issued to Subcon vendor against a PO so better use with delivery.
    Thansk,
    Satya.

  • PO Line Item wise gross value for combination of WBS and Material Group

    Hello,
    Our requirement is to get report for PO Line Item wise gross value for combination of WBS and Material Group. Standard report ME2J gives net price but not gross value for Material Line items. Please let me know if any standard report( or ME2J) will suffice this requirement.
    Regards,
    Milind Dumbre

    Dear Milind
    No standard report available to get the PO Line Item wise gross value for combination of WBS and Material Group. Please go for development by taking reference ME2J.
    Warm regards
    Ramakrishna

  • How to  find the Open sale orders till date for  given plant and material ?

    Hi experts,
                     I have a requirement to calculate the open sale orders for a given plant and material. I have tried in VA05 wherein i can get only for the material and sales area combination. From the document nos obtained from VA05 i can then find the plant. But my question is how do i get the output of VA05 into my progra. (can i use submit for a module pool report ).
    Also if ther is some other standard table or Function module to find the open sale orders till a given date ,it will be even more helpful....in which case i can drop the VA05 route.
    Kindly help
    Thanks in advance
    Ashwin

    Hi Ashwin,
        You can use SAP Tables VBAK and VBUP to get to know if the document is complete or not.
       VBUK-GBSTK is the field that will give you the status of the Sales Order .
      VBUK is used at header level , whereas VBUP is used for Item level.
      So in your case what I would do is :
      Get the Sales Orders that satisy the plant and material criteria from VBAP table , take this Sales Document numbers and go to VBUK or VBUP table to get the Sales Order Status. 
       If I need to find the open quantity as well I will link to VBFA table based on the document number.
      Reward if helpful.
    Thanks,
    Imran

Maybe you are looking for

  • Loading files with my iWeb

    How do I load a file -- say spread sheet, pdf, or word processed document -- with my iWeb? I plan to have a host server different from MMe.

  • After effects cs6 trial not downloading

    hi, i'm having problems downloading after effects cs6 trial, the download assistant is throwing an error and the download manager does not feature AE at all. It has been this wasy for 3 weeks. Please help.

  • A boring 'does it sync' question for Nokia 6131

    Thinking about a new phone, and want isyncability Any experience with how well the Nokia 6131 works?? I know its not on the 'offical' list and I believe there is a plug in available, but wondered if it actually worked out of the box

  • XSL-FO and Background Images

    I'm using JDK-1.4.2 supplied with XALAN along with Apache FOP to generate PDFs and I'm having trouble adding background images. I want to add the company logo as a background image in the header. My code looks like this: <fo:static-content flow-name=

  • SAPKB70017 DDIC_ACTIVATION  Import broke up

    Hello, i hope you can help me. I have planed a queue with the basis support packages SAPKB70017 - SAPKB70019. In phase DDIC_ACTIVATION the import broke up with following message: -   Fehler in Phase: DDIC_ACTIVATION -   Fehlergrund: TP_STEP_FAILURE -