Any room for improvement for this query? Explain Plan attached.

Is there any room for improvement for this query? Table stats are up-to-date. Any suggestions Query rewrite, addition of indexes,...etc ??
select sum(CONF
             when (cd.actl_qty - cd.total_alloc_qty - lsd.Q < 0) then
              0
             else
              cd.actl_qty - cd.total_alloc_qty - lsd.Q
           end)
  from (select sum(reqd_qty) as Q, ITEM_ID as ITEM
          from SHIP_DTL SD
         where exists (select 1
                  from CONF_dtl
                 where CONF_nbr = '1'
                   and ITEM_id = SD.ITEM_id)
         group by ITEM_id) lsd,
       CONF_dtl cd
where lsd.ITEM = cd.ITEM_id
   and cd.CONF_nbr = '1'Total number of rows in the tables involved
select count(*) from CONF_DTL;
  COUNT(*)
   1785889
select count(*) from shp_dtl;
  COUNT(*)
    286675
  Explain Plan
PLAN_TABLE_OUTPUT
Plan hash value: 2325658044
| Id  | Operation                           | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT                    |                    |     1 |    39 |     4  (25)| 00:00:01 |
|   1 |  SORT AGGREGATE                     |                    |     1 |    39 |            |          |
|   2 |   VIEW                              |                    |     1 |    39 |     4  (25)| 00:00:01 |
|   3 |    HASH GROUP BY                    |                    |     1 |   117 |     4  (25)| 00:00:01 |
|   4 |     TABLE ACCESS BY INDEX ROWID     | SHIP_DTL           |     1 |    15 |     1   (0)| 00:00:01
|   5 |      NESTED LOOPS                   |                    |     1 |   117 |     3   (0)| 00:00:01 |
|   6 |       MERGE JOIN CARTESIAN          |                    |     1 |   102 |     2   (0)| 00:00:01 |
|   7 |        TABLE ACCESS BY INDEX ROWID  | CONF_DTL           |     1 |    70 |     1   (0)| 00:00:01 |
|*  8 |         INDEX RANGE SCAN            | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
|   9 |        BUFFER SORT                  |                    |     1 |    32 |     1   (0)| 00:00:01 |
|  10 |         SORT UNIQUE                 |                    |     1 |    32 |     1   (0)| 00:00:01 |
|  11 |          TABLE ACCESS BY INDEX ROWID| CONF_DTL           |     1 |    32 |     1   (0)| 00:00:01 |
|* 12 |           INDEX RANGE SCAN          | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
|* 13 |       INDEX RANGE SCAN              | SHIP_DTL_IND_6 |     1 |       |     1   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   8 - access("CD"."CONF_NBR"='1')
  12 - access("CONF_NBR"='1')
  13 - access("ITEM_ID"="SD"."ITEM_ID")
       filter("ITEM_ID"="CD"."ITEM_ID")

Citizen_2 wrote:
Is there any room for improvement for this query? Table stats are up-to-date. Any suggestions Query rewrite, addition of indexes,...etc ??You say that the table stats are up-to-date, but is the following assumption of the optimizer correct:
select count(*)
from CONF_dtl
where CONF_nbr = '1';Does this query return a count of 1? I doubt that, but that's what Oracle estimates in the EXPLAIN PLAN output. Based on that assumption you get a cartesian join between the two CONF_DTL table instances, and the result - which is still expected to be one row at most - is then joined to the SHIP_DTL table using a NESTED LOOP.
If above assumption is incorrect, the number of rows generated by the cartesian join can be tremendous rendering the NESTED LOOP operation quite inefficient.
You can verify this by using the DBMS_XPLAN.DISPLAY_CURSOR function together with the GATHER_PLAN_STATISTICS hint, if you're already on 10g or later.
For more information regarding the DISPLAY_CURSOR function, see e.g. here: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
It will show you the actual cardinalities compared to the estimated cardinalities.
If the estimate of the optimizer is incorrect, you should find out why. There still might be some issues with the statistics, since this is most obvious reason for incorrect estimates.
Are your index statistics up-to-date?
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/

Similar Messages

  • Tuning needed for sql:EXPLAIN PLAN attached

    DB Version:10gR2
    The below sql was running slow, so i took an explain plan
    SQL> explain plan for
      2  SELECT COUNT(1) FROM SHIP_DTL WHERE
      3  SHIP_DTL.PLT_ID = 'AM834'
      4  AND SHIP_DTL.WHSE = '34' AND
      5  SHIP_DTL.STAT_CODE != '845'
      6  ORDER BY SHIP_DTL.LOAD_SEQ ASC;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation                    |  Name             | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT             |                   |     1 |    18 |     5  (20)|
    |   1 |  SORT AGGREGATE              |                   |     1 |    18 |            |
    |*  2 |   TABLE ACCESS BY INDEX ROWID| SHIP_DTL        |   200 |  3600 |     5  (20)|
    |*  3 |    INDEX RANGE SCAN          | SHIP_DTL_IND_4  |   203 |       |     3   (0)|
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       2 - filter("SHIP_DTL"."WHSE"='34' AND "SHIP_DTL"."STAT_CODE"<>845)
       3 - access("SHIP_DTL"."PLT_ID"='AM834')Why is there an INDEX RANGE scan where there is no BETWEEN operator in the query? What are various options(indexes, rewriting query) in tuning this query?

    james_p wrote:
    DB Version:10gR2
    The below sql was running slow, so i took an explain planCheck your plan, the optimizer estimates that the following query:
    select count(*)
    from SHIP_DTL
    where "SHIP_DTL"."PLT_ID"='AM834';only returns 200 records. Is this correct? Please post the result of above query.
    It probably isn't the case, because retrieving 200 records per index range scan and single row random table access shouldn't take long, at maximum a couple of seconds if you need to read each block actually from disk rather than from the cache.
    If the estimate is wrong you need to check the statistics on the table and index that were used by the optimizer to come to that conclusion.
    Are you sure that this plan is the actual plan used at execution time? You can check for the actual plans used to execute by using the DBMS_XPLAN.DISPLAY_CURSOR function in 10g if the SQL is still cached in the Shared Pool. You need to pass the SQL_ID and SQL_CHILD_NUMBER which you can retrieve from V$SESSION while the statement is executing.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • What privileges or role is required for user to acces the explain plan?

    Hi mates,
    Can anyone pls tell me what privileges or roles(grants) are requred for a user to access the explain plan in oORACLE 8i 8174..
    I think the select any dictionary is not valid for explain plan accessibility in 8i.
    Cheers.

    I already had that... Just that a user (not a dba) requires access to the explain plan and I dont want to grant him a dba role.
    Are you aware of any other grant I can give to the user?

  • Is there any better way of writing this query??

    I have a query on insert which looks like this,
    INSERT INTO TEMP( I1,I2)
    SELECT TI1 FROM CLIENT1
    WHERE R_CD ='PR' OR 'SR',
    SELECT TI2 FROM CLIENT2
    WHERE R_CD = 'MN' OR 'OP
    There are two tables where the source data is coming from and inserted into TEMP table. I find this query to be inefficient. Anybody who can help me writing a good one?? Thanks.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by [email protected]:
    I have a query on insert which looks like this,
    INSERT INTO TEMP( I1,I2)
    SELECT TI1 FROM CLIENT1
    WHERE R_CD ='PR' OR 'SR',
    SELECT TI2 FROM CLIENT2
    WHERE R_CD = 'MN' OR 'OP
    There are two tables where the source data is coming from and inserted into TEMP table. I find this query to be inefficient. Anybody who can help me writing a good one?? Thanks.<HR></BLOCKQUOTE>
    A possible solution,
    INSERT INTO TEMP( I1,I2)
    SELECT C1.TI1, C2.TI2
    FROM CLIENT1 C1, CLIENT2 C2
    WHERE (C1.R_CD = 'PR' OR C1.R_CD ='SR') AND
    (C2.R_CD = 'MN' OR C2.R_CD = 'OP')
    null

  • Query Explain Plan Help

    I am running the following query against my database
    SELECT p.ID
      FROM rap_counterparties cou,
           rap_presentation_cou_ratings pcr,
           rap_presentation_states sta,
           rap_app_user_profiles aup,
           rap_presentations p
    WHERE cou.unt_id = aup.unt_id
       AND aup.aur_id = 7529
       AND pcr.cou_id = cou.ID
       AND sta.cur_present_state_instance_flg = 'Y'
       AND sta.state_type_id = pcr.pst_state_type_id
       AND sta.pre_id = pcr.pst_pre_id
       AND sta.state_type_id IN (326, 322, 323, 324, 325)
       AND cou.unt_id = p.unt_id
       AND p.ID = sta.pre_id
       AND (   p.private_flg != 'Y'
            OR (p.private_flg = 'Y' AND p.created_by_user_id = 10000083)
    Explain plan of the query is
    PLAN_TABLE_OUTPUT
    | Id  | Operation                        |  Name                  | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                 |                        |     8 |   456 |  3936  (16)|
    |*  1 |  TABLE ACCESS BY INDEX ROWID     | RAP_PRESENTATIONS      |     1 |    15 |     2  (50)|
    |   2 |   NESTED LOOPS                   |                        |     8 |   456 |  3936  (16)|
    |*  3 |    HASH JOIN                     |                        |  1745 | 73290 |  2145  (27)|
    |*  4 |     HASH JOIN                    |                        | 14257 |   431K|  1299  (25)|
    |*  5 |      HASH JOIN                   |                        |  5173 | 87941 |   583  (16)|
    |   6 |       TABLE ACCESS BY INDEX ROWID| RAP_APP_USER_PROFILES  |    18 |   144 |     3  (34)|
    |*  7 |        INDEX RANGE SCAN          | RAP_AUP_IX_01          |    18 |       |     2  (50)|
    |   8 |       TABLE ACCESS FULL          | RAP_COUNTERPARTIES     |   118K|  1042K|   560  (13)|
    |*  9 |      INDEX FAST FULL SCAN        | RAP_PCR_PK             |   326K|  4467K|   659  (25)|
    |* 10 |     INDEX FAST FULL SCAN         | RAP_PST_IX_02          |   120K|  1291K|   821  (29)|
    |* 11 |    INDEX RANGE SCAN              | RAP_PRE_PK             |     1 |       |            |
    Predicate Information (identified by operation id):
       1 - filter(("P"."PRIVATE_FLG"<>'Y' OR "P"."CREATED_BY_USER_ID"=10000083 AND
                  "P"."PRIVATE_FLG"='Y') AND "COU"."UNT_ID"="P"."UNT_ID")
       3 - access("STA"."STATE_TYPE_ID"="PCR"."PST_STATE_TYPE_ID" AND
                  "STA"."PRE_ID"="PCR"."PST_PRE_ID")
       4 - access("PCR"."COU_ID"="COU"."ID")
       5 - access("COU"."UNT_ID"="AUP"."UNT_ID")
       7 - access("AUP"."AUR_ID"=7529)
       9 - filter("PCR"."PST_STATE_TYPE_ID"=322 OR "PCR"."PST_STATE_TYPE_ID"=323 OR
                  "PCR"."PST_STATE_TYPE_ID"=324 OR "PCR"."PST_STATE_TYPE_ID"=325 OR "PCR"."PST_STATE_TYPE_ID"=326)
      10 - filter("STA"."CUR_PRESENT_STATE_INSTANCE_FLG"='Y' AND ("STA"."STATE_TYPE_ID"=322 OR
                  "STA"."STATE_TYPE_ID"=323 OR "STA"."STATE_TYPE_ID"=324 OR "STA"."STATE_TYPE_ID"=325 OR
                  "STA"."STATE_TYPE_ID"=326))
      11 - access("P"."ID"="STA"."PRE_ID")
    Table Row count
    rap_app_user_profiles : 30639
    rap_counterparties : 118583
    rap_presentation_cou_ratings -- 652781
    rap_presentation_states -- 982413
    rap_presentations -- 246145
    Questions
    1. Why is the index not being used on the table rap_counterparties. If I force a hint then the index is being used
    2. Is there a way I can have an index range scan as opposed to the index fast full scan.
    3. This query runs in 3s. Is there anything else I can do to tune this query?
    4. In predicate 9 and 10 the two tables have fast full scan. If the filter of unit generates only a few records why can't those few records be joined with these tables. Why the whole tables are first being scanned and then joined
    Appreciate your response

    Thanks for the suggestions.
    So I tried using the FIRST_ROW HINT and i am getting the nested loops join and it runs fast in 250ms.
    SELECT /*+FIRST_ROWS*/
           p.ID ID
      FROM rap_presentations p,
           rap_counterparties cou,
           rap_presentation_states sta,
           rap_presentation_cou_ratings pcr
    WHERE cou.unt_id IN (
               SELECT prof.unt_id
                 FROM rap_application_users u, rap_app_user_profiles prof
                WHERE u.ID = prof.aur_id AND u.ID = 7529
                      AND prof.aro_id NOT IN (8))
       AND cou.unt_id = p.unt_id
       AND p.ID = sta.pre_id
       AND sta.cur_present_state_instance_flg = 'Y'
       AND sta.state_type_id = pcr.pst_state_type_id
       AND sta.pre_id = pcr.pst_pre_id
       AND pcr.cou_id = cou.ID
       AND (   p.private_flg != 'Y'
            OR (p.private_flg = 'Y' AND p.created_by_user_id = 7529)
       AND sta.state_type_id IN (326, 322, 323, 324, 325)
    Explain plan:
    PLAN_TABLE_OUTPUT
    | Id  | Operation                           |  Name                         | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                    |                               |     7 |   434 | 43334   (2)|
    |*  1 |  TABLE ACCESS BY INDEX ROWID        | RAP_PRESENTATIONS             |     1 |    15 |     2  (50)|
    |   2 |   NESTED LOOPS                      |                               |     7 |   434 | 43334   (2)|
    |   3 |    NESTED LOOPS                     |                               |  1593 | 74871 | 41699   (2)|
    |   4 |     NESTED LOOPS                    |                               | 13016 |   457K| 15196   (2)|
    |   5 |      NESTED LOOPS                   |                               |  4723 |   101K|   798   (2)|
    |   6 |       VIEW                          | VW_NSO_1                      |    16 |   208 |            |
    |   7 |        SORT UNIQUE                  |                               |    16 |   256 |            |
    |   8 |         NESTED LOOPS                |                               |    16 |   256 |     4  (25)|
    |*  9 |          INDEX UNIQUE SCAN          | RAP_AUR_PK                    |     1 |     5 |     2  (50)|
    |* 10 |          TABLE ACCESS BY INDEX ROWID| RAP_APP_USER_PROFILES         |    16 |   176 |     3  (34)|
    |* 11 |           INDEX RANGE SCAN          | RAP_AUP_IX_01                 |    18 |       |     2  (50)|
    |  12 |       TABLE ACCESS BY INDEX ROWID   | RAP_COUNTERPARTIES            |   295 |  2655 |    50   (2)|
    |* 13 |        INDEX RANGE SCAN             | RAP_COU_IX_02                 |    95 |       |     2  (50)|
    |* 14 |      TABLE ACCESS BY INDEX ROWID    | RAP_PRESENTATION_COU_RATINGS  |     3 |    42 |     4  (25)|
    |* 15 |       INDEX RANGE SCAN              | RAP_PCR_IX_03                 |    10 |       |     3  (34)|
    |* 16 |     INDEX RANGE SCAN                | RAP_PST_IX_02                 |     1 |    11 |     3  (34)|
    |* 17 |    INDEX RANGE SCAN                 | RAP_PRE_PK                    |     1 |       |            |
    Predicate Information (identified by operation id):
       1 - filter(("P"."PRIVATE_FLG"<>'Y' OR "P"."PRIVATE_FLG"='Y' AND "P"."CREATED_BY_USER_ID"=7529) AND
                  "COU"."UNT_ID"="P"."UNT_ID")
       9 - access("U"."ID"=7529)
      10 - filter("PROF"."ARO_ID"<>8)
      11 - access("PROF"."AUR_ID"=7529)
      13 - access("COU"."UNT_ID"="VW_NSO_1"."$nso_col_1")
      14 - filter("PCR"."PST_STATE_TYPE_ID"=322 OR "PCR"."PST_STATE_TYPE_ID"=323 OR
                  "PCR"."PST_STATE_TYPE_ID"=324 OR "PCR"."PST_STATE_TYPE_ID"=325 OR "PCR"."PST_STATE_TYPE_ID"=326)
      15 - access("PCR"."COU_ID"="COU"."ID")
      16 - access("STA"."PRE_ID"="PCR"."PST_PRE_ID" AND "STA"."STATE_TYPE_ID"="PCR"."PST_STATE_TYPE_ID" AND
                  "STA"."CUR_PRESENT_STATE_INSTANCE_FLG"='Y')
           filter("STA"."STATE_TYPE_ID"=322 OR "STA"."STATE_TYPE_ID"=323 OR "STA"."STATE_TYPE_ID"=324 OR
                  "STA"."STATE_TYPE_ID"=325 OR "STA"."STATE_TYPE_ID"=326)
      17 - access("P"."ID"="STA"."PRE_ID")
    But my query that runs to get the data has a union with another query and with the change it looks like below
    SELECT /*+FIRST_ROWS*/
           p.ID ID
      FROM rap_presentations p,
           rap_counterparties cou,
           rap_presentation_states sta,
           rap_presentation_cou_ratings pcr
    WHERE cou.unt_id IN (
               SELECT prof.unt_id
                 FROM rap_application_users u, rap_app_user_profiles prof
                WHERE u.ID = prof.aur_id AND u.ID = 7529
                      AND prof.aro_id NOT IN (8))
       AND cou.unt_id = p.unt_id
       AND p.ID = sta.pre_id
       AND sta.cur_present_state_instance_flg = 'Y'
       AND sta.state_type_id = pcr.pst_state_type_id
       AND sta.pre_id = pcr.pst_pre_id
       AND pcr.cou_id = cou.ID
       AND (   p.private_flg != 'Y'
            OR (p.private_flg = 'Y' AND p.created_by_user_id = 7529)
       AND sta.state_type_id IN (326, 322, 323, 324, 325)
    UNION
    SELECT /*+index(pfs)*/
           p.ID ID
      FROM rap_presentations p,
           rap_presentation_states sta,
           rap_facilities f,
           rap_presentation_fac_states pfs
    WHERE f.unt_id IN (
               SELECT prof.unt_id
                 FROM rap_application_users u, rap_app_user_profiles prof
                WHERE u.ID = prof.aur_id AND u.ID = 7529
                      AND prof.aro_id NOT IN (8))
       AND f.unt_id = p.unt_id
       AND p.ID = sta.pre_id
       AND sta.cur_present_state_instance_flg = 'Y'
       AND sta.state_type_id = pfs.pst_state_type_id
       AND sta.pre_id = pfs.pst_pre_id
       AND pfs.fac_id = f.ID
       AND pfs.fac_num = f.num
       AND f.current_facility_instance_flg = 'Y'
       AND (   p.private_flg != 'Y'
            OR (p.private_flg = 'Y' AND p.created_by_user_id = 7529)
       AND sta.state_type_id IN (326, 322, 323, 324, 325)
    Explain plan :
    PLAN_TABLE_OUTPUT
    | Id  | Operation                          |  Name                  | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                   |                        |     8 |   534 | 14931  (80)|
    |   1 |  SORT UNIQUE                       |                        |     8 |   534 | 14931  (80)|
    |   2 |   UNION-ALL                        |                        |       |       |            |
    |*  3 |    TABLE ACCESS BY INDEX ROWID     | RAP_PRESENTATIONS      |     1 |    15 |     2  (50)|
    |   4 |     NESTED LOOPS                   |                        |     7 |   455 |  3728  (17)|
    |*  5 |      HASH JOIN                     |                        |  1542 | 77100 |  2145  (27)|
    |*  6 |       HASH JOIN                    |                        | 12598 |   479K|  1300  (24)|
    |*  7 |        HASH JOIN                   |                        |  4571 |   111K|   584  (16)|
    |*  8 |         TABLE ACCESS BY INDEX ROWID| RAP_APP_USER_PROFILES  |    16 |   176 |     3  (34)|
    |*  9 |          INDEX RANGE SCAN          | RAP_AUP_IX_01          |    18 |       |     2  (50)|
    |  10 |         NESTED LOOPS               |                        |   118K|  1621K|   561  (13)|
    |* 11 |          INDEX UNIQUE SCAN         | RAP_AUR_PK             |     1 |     5 |     2  (50)|
    |  12 |          TABLE ACCESS FULL         | RAP_COUNTERPARTIES     |   118K|  1042K|   560  (13)|
    |* 13 |        INDEX FAST FULL SCAN        | RAP_PCR_PK             |   326K|  4467K|   659  (25)|
    |* 14 |       INDEX FAST FULL SCAN         | RAP_PST_IX_02          |   120K|  1291K|   821  (29)|
    |* 15 |      INDEX RANGE SCAN              | RAP_PRE_PK             |     1 |       |            |
    |  16 |    NESTED LOOPS                    |                        |     1 |    79 | 11201   (2)|
    |  17 |     NESTED LOOPS                   |                        |    75 |  4800 | 11124   (2)|
    |  18 |      NESTED LOOPS                  |                        |   617 | 32701 |  9867   (2)|
    |  19 |       NESTED LOOPS                 |                        |  2104 | 69432 |  5606   (2)|
    |  20 |        NESTED LOOPS                |                        |    16 |   256 |     4  (25)|
    |* 21 |         INDEX UNIQUE SCAN          | RAP_AUR_PK             |     1 |     5 |     2  (50)|
    |* 22 |         TABLE ACCESS BY INDEX ROWID| RAP_APP_USER_PROFILES  |    16 |   176 |     3  (34)|
    |* 23 |          INDEX RANGE SCAN          | RAP_AUP_IX_01          |    18 |       |     2  (50)|
    |* 24 |        TABLE ACCESS BY INDEX ROWID | RAP_FACILITIES         |   135 |  2295 |   351   (2)|
    |* 25 |         INDEX RANGE SCAN           | RAP_FAC_IX_02          |  1608 |       |     5  (20)|
    |* 26 |       INDEX RANGE SCAN             | RAP_PFR_PK             |     1 |    20 |     3  (34)|
    |* 27 |      INDEX RANGE SCAN              | RAP_PST_IX_02          |     1 |    11 |     3  (34)|
    |* 28 |     TABLE ACCESS BY INDEX ROWID    | RAP_PRESENTATIONS      |     1 |    15 |     2  (50)|
    |* 29 |      INDEX UNIQUE SCAN             | RAP_PRE_PK             |     1 |       |            |
    Predicate Information (identified by operation id):
       3 - filter(("P"."PRIVATE_FLG"<>'Y' OR "P"."PRIVATE_FLG"='Y' AND "P"."CREATED_BY_USER_ID"=7529)
                  AND "COU"."UNT_ID"="P"."UNT_ID")
       5 - access("STA"."STATE_TYPE_ID"="PCR"."PST_STATE_TYPE_ID" AND
                  "STA"."PRE_ID"="PCR"."PST_PRE_ID")
       6 - access("PCR"."COU_ID"="COU"."ID")
       7 - access("COU"."UNT_ID"="PROF"."UNT_ID")
       8 - filter("PROF"."ARO_ID"<>8)
       9 - access("PROF"."AUR_ID"=7529)
      11 - access("U"."ID"=7529)
      13 - filter("PCR"."PST_STATE_TYPE_ID"=322 OR "PCR"."PST_STATE_TYPE_ID"=323 OR
                  "PCR"."PST_STATE_TYPE_ID"=324 OR "PCR"."PST_STATE_TYPE_ID"=325 OR "PCR"."PST_STATE_TYPE_ID"=326)
      14 - filter("STA"."CUR_PRESENT_STATE_INSTANCE_FLG"='Y' AND ("STA"."STATE_TYPE_ID"=322 OR
                  "STA"."STATE_TYPE_ID"=323 OR "STA"."STATE_TYPE_ID"=324 OR "STA"."STATE_TYPE_ID"=325 OR
                  "STA"."STATE_TYPE_ID"=326))
      15 - access("P"."ID"="STA"."PRE_ID")
      21 - access("U"."ID"=7529)
      22 - filter("PROF"."ARO_ID"<>8)
      23 - access("PROF"."AUR_ID"=7529)
      24 - filter("F"."CURRENT_FACILITY_INSTANCE_FLG"='Y')
      25 - access("F"."UNT_ID"="PROF"."UNT_ID")
      26 - access("PFS"."FAC_ID"="F"."ID" AND "PFS"."FAC_NUM"="F"."NUM")
           filter("PFS"."PST_STATE_TYPE_ID"=322 OR "PFS"."PST_STATE_TYPE_ID"=323 OR
                  "PFS"."PST_STATE_TYPE_ID"=324 OR "PFS"."PST_STATE_TYPE_ID"=325 OR "PFS"."PST_STATE_TYPE_ID"=326)
      27 - access("STA"."PRE_ID"="PFS"."PST_PRE_ID" AND
                  "STA"."STATE_TYPE_ID"="PFS"."PST_STATE_TYPE_ID" AND "STA"."CUR_PRESENT_STATE_INSTANCE_FLG"='Y')
           filter("STA"."STATE_TYPE_ID"=322 OR "STA"."STATE_TYPE_ID"=323 OR "STA"."STATE_TYPE_ID"=324
                  OR "STA"."STATE_TYPE_ID"=325 OR "STA"."STATE_TYPE_ID"=326)
      28 - filter(("P"."PRIVATE_FLG"<>'Y' OR "P"."PRIVATE_FLG"='Y' AND "P"."CREATED_BY_USER_ID"=7529)
                  AND "F"."UNT_ID"="P"."UNT_ID")
      29 - access("P"."ID"="STA"."PRE_ID")
    Question:
    1. When I put the query with the FIRST_ROWS hint in a union with another query, the explain plan reverts back to the older explain plan. how can I avoid it when running by iteslf it runs really quick?
    2. Why is the cost with nested loops more higher? Is it because of statistics?
    2. Does the database parameter db_multiblock_read_count have any affect  on the fast full scan?
    3. I gather statistics using the followin method
    begin
       dbms_stats.gather_schema_stats(
          ownname          => 'RAP_OWNER',
          estimate_percent => dbms_stats.auto_sample_size,
          method_opt       => 'for all columns size auto',
          degree           => 7
    end;
    Sometimes I also use the following method
    BEGIN
    dbms_stats.gather_schema_stats( ownname=>'RAP_OWNER',
    METHOD_OPT=>'FOR ALL INDEXED COLUMNS SIZE SKEWONLY',
    CASCADE=>TRUE, ESTIMATE_PERCENT=>100);
    END;
    Which one is good or should I use both?
    Appreciate your input.

  • Performance problem: Query explain plan changes in pl/sql vs. literal args

    I have a complex query with 5+ table joins on large (million+ row) tables. In it's most simplified form, it's essentially
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between 123 and 456;
    Its performance was excellent with literal arguments (1 sec per execution).
    But, when I used pl/sql bind argument variables instead of 123 and 456 as literals, the explain plan changes drastically, and runs 10+ minutes.
    Ex:
    CREATE PROCEDURE runQuery(param1 INTEGER, param2 INTEGER){
    CURSOR LT_CURSOR IS
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between param1 AND param2;
    BEGIN
    FOR aRecord IN LT_CURSOR
    LOOP
    (print timestamp...)
    END LOOP;
    END runQuery;
    Rewriting the query 5 different ways was unfruitful. DB hints were also unfruitful in this particular case. LargeTable.pk_id was an indexed field as were all other join fields.
    Solution:
    Lacking other options, I wrote a literal query that concatenated the variable args. Open a cursor for the literal query.
    Upside: It changed the explain plan to the only really fast option and performed at 1 second instead of 10mins.
    Downside: Query not cached for future use. Perfectly fine for this query's purpose.
    Other suggestions are welcome.

    AmandaSoosai wrote:
    I have a complex query with 5+ table joins on large (million+ row) tables. In it's most simplified form, it's essentially
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between 123 and 456;
    Its performance was excellent with literal arguments (1 sec per execution).
    But, when I used pl/sql bind argument variables instead of 123 and 456 as literals, the explain plan changes drastically, and runs 10+ minutes.
    Ex:
    CREATE PROCEDURE runQuery(param1 INTEGER, param2 INTEGER){
    CURSOR LT_CURSOR IS
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between param1 AND param2;
    BEGIN
    FOR aRecord IN LT_CURSOR
    LOOP
    (print timestamp...)
    END LOOP;
    END runQuery;
    Rewriting the query 5 different ways was unfruitful. DB hints were also unfruitful in this particular case. LargeTable.pk_id was an indexed field as were all other join fields.
    Solution:
    Lacking other options, I wrote a literal query that concatenated the variable args. Open a cursor for the literal query.
    Upside: It changed the explain plan to the only really fast option and performed at 1 second instead of 10mins.
    Downside: Query not cached for future use. Perfectly fine for this query's purpose.
    Other suggestions are welcome.Best wild guess based on what you've posted is a bind variable mismatch (your column is declared as a NUMBER data type and your bind variable is declared as a VARCHAR for example). Unless you have histograms on the columns in question ... which, if you're using bind variables is usually a really bad idea.
    A basic illustration of my guess
    http://blogs.oracle.com/optimizer/entry/how_do_i_get_sql_executed_from_an_application_to_uses_the_same_execution_plan_i_get_from_sqlplus

  • Query needs tuning; Explain plan attached

    DB version:10gR2
    Currently, the below query is taking more than 28 secs to complete. The table stats are up-to-date.
    Is there a way to rewrite/tune this query?
    SELECT DISTINCT TASK_HDR.TASK_ID,
                     TASK_HDR.WHSE,
                     TASK_HDR.TASK_DESC,
                     TASK_HDR.INVN_TYPE,
                     TASK_HDR.INVN_NEED_TYPE,
                     TASK_HDR.DFLT_TASK_PRTY,
                     TASK_HDR.CURR_TASK_PRTY,
                     TASK_HDR.XPECTD_DURTN,
                     TASK_HDR.ACTL_DURTN,
                     TASK_HDR.ERLST_START_DATE_TIME,
                     TASK_HDR.LTST_START_DATE_TIME,
                     TASK_HDR.LTST_CMPL_DATE_TIME,
                     TASK_HDR.BEGIN_AREA,
                     TASK_HDR.BEGIN_ZONE,
                     TASK_HDR.BEGIN_AISLE,
                     TASK_HDR.END_AREA,
                     TASK_HDR.END_ZONE,
                     TASK_HDR.END_AISLE,
                     TASK_HDR.START_CURR_WORK_GRP,
                     TASK_HDR.START_CURR_WORK_AREA,
                     TASK_HDR.END_CURR_WORK_GRP,
                     TASK_HDR.END_CURR_WORK_AREA,
                     TASK_HDR.START_DEST_WORK_GRP,
                     TASK_HDR.START_DEST_WORK_AREA,
                     TASK_HDR.END_DEST_WORK_GRP,
                     TASK_HDR.END_DEST_WORK_AREA,
                     TASK_HDR.TASK_TYPE,
                     TASK_HDR.TASK_GENRTN_REF_CODE,
                     TASK_HDR.TASK_GENRTN_REF_NBR,
                     TASK_HDR.NEED_ID,
                     TASK_HDR.TASK_BATCH,
                     TASK_HDR.STAT_CODE,
                     TASK_HDR.CREATE_DATE_TIME,
                     TASK_HDR.MOD_DATE_TIME,
                     TASK_HDR.USER_ID,
                     TASK_HDR.RLS_DATE_TIME,
                     TASK_HDR.SKU_ID,
                     TASK_HDR.TASK_CMPL_REF_CODE,
                     TASK_HDR.TASK_CMPL_REF_NBR,
                     TASK_HDR.OWNER_USER_ID,
                     TASK_HDR.ONE_USER_PER_GRP,
                     TASK_HDR.NEXT_TASK_ID,
                     TASK_HDR.EXCEPTION_CODE,
                     TASK_HDR.CURR_LOCN_ID,
                     TASK_HDR.TASK_PARM_ID,
                     TASK_HDR.RULE_ID,
                     TASK_HDR.VOCOLLECT_ASSIGN_ID,
                     TASK_HDR.CURR_USER_ID,
                     TASK_HDR.MHE_FLAG,
                     TASK_HDR.PICK_TO_TOTE_FLAG,
                     TASK_HDR.MHE_ORD_STATE,
                     TASK_HDR.PRT_TASK_LIST_FLAG,
                     TASK_HDR.RPT_PRTR_REQSTR,
                     TASK_HDR.ORIG_TASK_ID
       FROM INVN_NEED_TYPE, TASK_DTL, TASK_HDR
        WHERE (TASK_HDR.TASK_ID = TASK_DTL.TASK_ID(+))
          AND TASK_HDR.WHSE = '01' AND TASK_HDR.STAT_CODE >= 99 AND
              TASK_HDR.INVN_NEED_TYPE = INVN_NEED_TYPE.INVN_NEED_TYPE AND
              INVN_NEED_TYPE.WHSE = TASK_HDR.WHSE AND
              (INVN_NEED_TYPE.CO = '88') AND (INVN_NEED_TYPE.DIV = '51') AND
              (TASK_DTL.PKT_CTRL_NBR IS NULL OR TASK_DTL.INVN_NEED_TYPE = 1) AND
              TASK_HDR.MOD_DATE_TIME <= sysdate-85
      ORDER BY TASK_HDR.CREATE_DATE_TIME DESC
      The explain plan:
    PLAN_TABLE_OUTPUT
    | Id  | Operation                        | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)|
    |   0 | SELECT STATEMENT                 |                   | 10032 |  1969K|       |  3143   (2)|
    |   1 |  SORT ORDER BY                   |                   | 10032 |  1969K|  4232K|  3143   (2)|
    |   2 |   HASH UNIQUE                    |                   | 10032 |  1969K|  4232K|  2689   (2)|
    |   3 |    FILTER                        |                   |       |       |       |            |
    |   4 |     NESTED LOOPS OUTER           |                   | 10032 |  1969K|       |  2235   (1)|
    |   5 |      NESTED LOOPS                |                   |  3226 |   570K|       |   284   (3)|
    |   6 |       TABLE ACCESS BY INDEX ROWID| TASK_HDR          |  3412 |   559K|       |   282   (2)|
    |   7 |        INDEX RANGE SCAN          | TASK_HDR_IND_3    |  9042 |       |       |     8  (13)|
    |   8 |       INDEX UNIQUE SCAN          | PK_INVN_NEED_TYPE |     1 |    13 |       |     1   (0)|
    |   9 |      TABLE ACCESS BY INDEX ROWID | TASK_DTL          |     3 |    60 |       |     1   (0)|
    |  10 |       INDEX RANGE SCAN           | PK_TASK_DTL       |     3 |       |       |     1   (0)|
    ---------------------------------------------------------------------------------------------------

    My apologies, yes, it is:
    SELECT TASK_HDR.TASK_ID,
                     TASK_HDR.WHSE,
                     TASK_HDR.TASK_DESC,
                     TASK_HDR.INVN_TYPE,
                     TASK_HDR.INVN_NEED_TYPE,
                     TASK_HDR.DFLT_TASK_PRTY,
                     TASK_HDR.CURR_TASK_PRTY,
                     TASK_HDR.XPECTD_DURTN,
                     TASK_HDR.ACTL_DURTN,
                     TASK_HDR.ERLST_START_DATE_TIME,
                     TASK_HDR.LTST_START_DATE_TIME,
                     TASK_HDR.LTST_CMPL_DATE_TIME,
                     TASK_HDR.BEGIN_AREA,
                     TASK_HDR.BEGIN_ZONE,
                     TASK_HDR.BEGIN_AISLE,
                     TASK_HDR.END_AREA,
                     TASK_HDR.END_ZONE,
                     TASK_HDR.END_AISLE,
                     TASK_HDR.START_CURR_WORK_GRP,
                     TASK_HDR.START_CURR_WORK_AREA,
                     TASK_HDR.END_CURR_WORK_GRP,
                     TASK_HDR.END_CURR_WORK_AREA,
                     TASK_HDR.START_DEST_WORK_GRP,
                     TASK_HDR.START_DEST_WORK_AREA,
                     TASK_HDR.END_DEST_WORK_GRP,
                     TASK_HDR.END_DEST_WORK_AREA,
                     TASK_HDR.TASK_TYPE,
                     TASK_HDR.TASK_GENRTN_REF_CODE,
                     TASK_HDR.TASK_GENRTN_REF_NBR,
                     TASK_HDR.NEED_ID,
                     TASK_HDR.TASK_BATCH,
                     TASK_HDR.STAT_CODE,
                     TASK_HDR.CREATE_DATE_TIME,
                     TASK_HDR.MOD_DATE_TIME,
                     TASK_HDR.USER_ID,
                     TASK_HDR.RLS_DATE_TIME,
                     TASK_HDR.SKU_ID,
                     TASK_HDR.TASK_CMPL_REF_CODE,
                     TASK_HDR.TASK_CMPL_REF_NBR,
                     TASK_HDR.OWNER_USER_ID,
                     TASK_HDR.ONE_USER_PER_GRP,
                     TASK_HDR.NEXT_TASK_ID,
                     TASK_HDR.EXCEPTION_CODE,
                     TASK_HDR.CURR_LOCN_ID,
                     TASK_HDR.TASK_PARM_ID,
                     TASK_HDR.RULE_ID,
                     TASK_HDR.VOCOLLECT_ASSIGN_ID,
                     TASK_HDR.CURR_USER_ID,
                     TASK_HDR.MHE_FLAG,
                     TASK_HDR.PICK_TO_TOTE_FLAG,
                     TASK_HDR.MHE_ORD_STATE,
                     TASK_HDR.PRT_TASK_LIST_FLAG,
                     TASK_HDR.RPT_PRTR_REQSTR,
                     TASK_HDR.ORIG_TASK_ID
       FROM INVN_NEED_TYPE,TASK_HDR
        WHERE TASK_HDR.WHSE = '01' AND TASK_HDR.STAT_CODE >= 99 AND
              TASK_HDR.INVN_NEED_TYPE = INVN_NEED_TYPE.INVN_NEED_TYPE AND
              INVN_NEED_TYPE.WHSE = TASK_HDR.WHSE AND
              (INVN_NEED_TYPE.CO = '88') AND (INVN_NEED_TYPE.DIV = '51') AND
              TASK_HDR.MOD_DATE_TIME <= sysdate-85
         AND EXISTS (SELECT 1
                               FROM TASK_DTL
                             WHERE TASK_HDR.TASK_ID = TASK_DTL.TASK_ID
                                AND (TASK_DTL.PKT_CTRL_NBR IS NULL OR TASK_DTL.INVN_NEED_TYPE = 1))
      ORDER BY TASK_HDR.CREATE_DATE_TIME DESCAlthough you have an OUTER JOIN on TASK_DTL.TASK_ID, this is converted to an INNER JOIN with (TASK_DTL.PKT_CTRL_NBR IS NULL OR TASK_DTL.INVN_NEED_TYPE = 1), which is the equivalent of the 'EXISTS' version above.
    I haven't been able to test this.

  • Suggestion for improvement for the IDE

    A very simple improvement that will make the users life so much
    easier.
    When the IDE loads a project / workspace, when it loads the
    previous set of files back into the IDE, why not also have it
    place the cursor in the row and column it was last at?
    I hope to see the change in the next release!
    Thanks,
    Frank
    null

    Hi
    We appericiate your valuable comments/suggestions. I have filed
    an enhacement request for it.
    regards
    Frank Garber (guest) wrote:
    : A very simple improvement that will make the users life so much
    : easier.
    : When the IDE loads a project / workspace, when it loads the
    : previous set of files back into the IDE, why not also have it
    : place the cursor in the row and column it was last at?
    : I hope to see the change in the next release!
    : Thanks,
    : Frank
    null

  • Please any one help me in this query

    i have 6 tables. in my object i have to transfer the data to the internal table i_vbrk. it must include the following fields from the respective fields
    vbrk   -  vbeln, vkorg, vtweg, fkdat,knumv
    vbrp   -  vbeln, matnr, aktnr, arktx, netwr, wavwr
    mara   -  matnr, extwg, matkl
    marc   -  matnr, mmsta
    marm   -  umrez, matnr
    konv   -  knumv, kschl, kposn, kbetr.
    please help me in joining the tables to one internal table

    Hi,
    data:begin of it_vbrk occurs 0,
    vbeln like vbrk-vbeln,
    vkorg like vbrk-vkorg,
    vtweg like vbrk-vtweg,
    fkdat like vbrk-fkdat,
    knumv like vbrk-knumv,
    end of it_vbrk.
    data:begin of it_vbrp occurs 0,
    vbeln like vbrp-vbeln,
    matnr like vbrp-matnr,
    aktnr like vbrp-aktnr,
    arktx like vbrp-arktx,
    netwr like vbrp-netwr,
    wavwr like vbrp-wavwr,
    end of it_vbrp.
    data:begin of it_mara occurs 0,
    matnr like mara-matnr,
    extwg like mara-extwg,
    matkl like mara-matkl,
    end of it_mara.
    data:begin of it_marc occurs 0,
    matnr like marc-matnr,
    mmsta like marc-mmsta,
    end of it_marc.
    data:begin of it_marm occurs 0,
    umrez like marm-umrez,
    matnr like marm-matnr,
    end of it_marm.
    data:begin of it_konv occurs 0,
    knumv like konv-knumv,
    kschl like konv-kschl,
    kposn like konv-kposn,
    kbetr like konv-kbetr,
    end of it_konv.
    select vbeln vkorg vtweg fkdat knumv
    from vbrk
    into table it_vbrk.
    select vbeln matnr aktnr arktx netwr wavwr
    from vbrp
    into table it_vbrp
    for all entries in it_vbrk
    where vbeln = it_vbrk-vbeln.
    select matnr extwg matkl
    from mara
    into table it_mara
    for all entries in it_vbrp
    where matnr = it_vbrp-matnr.
    select matnr mmsta
    from marc
    into table it_marc
    for all entries in it_mara
    where matnr = it_mara-matnr.
    select umrez matnr
    from marm
    into table it_marm
    for all entries in it_mara
    where matnr = it_mara-matnr.
    select knumv kschl kposn kbetr
    from konv
    into table it_konv
    for all entries in it_vbrk
    where knumv = it_vbrk-knumv.
    regards,
    sowjanya.

  • Strange query / explain plan

    (I posted this in the Oracle Text forum, but I think it's as appropriate here.)
    Consider the following queries:
    :the_filter := 'FILE';
    (1)
    SELECT COUNT(*)
    FROM FOO
    WHERE CONTAINS(search_col,:the_filter) > 0;
    (2)
    SELECT COUNT(*)
    FROM FOO
    WHERE 'FILE' IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    (3)
    SELECT COUNT(*)
    FROM FOO
    WHERE :the_filter IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    (1) and (2) use the text index and run normally, but (3) does a full table scan, but I don't understand why.
    The reason behind my using a query of the form (3) is to say 'keep the record if the filter is null or the record contains the filter'. I'm using the filter as a switch, and (3) is actually a simplified form of a complex query with several tables and filters. How can I do this without the query using a full table scan?
    Below is the script and a record of the full session:
    SET ECHO ON;
    SET TIMING ON;
    DROP TABLE FOO;
    CREATE TABLE FOO (search_col VARCHAR2(100));
    -- Loads of dummy data
    INSERT INTO FOO (search_col) SELECT OBJECT_NAME || ' ' || OBJECT_TYPE
    FROM ALL_OBJECTS WHERE ROWNUM <= 20000;
    COMMIT;
    CREATE INDEX I1 ON FOO(search_col) INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS(' section group ctxsys.html_section_group');
    variable the_filter varchar2(100);
    begin
    :the_filter := 'FILE';
    end;
    SET AUTOTRACE ON EXPLAIN;
    SELECT COUNT(*)
    FROM FOO
    WHERE CONTAINS(search_col,:the_filter) > 0;
    SELECT COUNT(*)
    FROM FOO
    WHERE 'FILE' IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    SELECT COUNT(*)
    FROM FOO
    WHERE :the_filter IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    SQL*Plus: Release 10.2.0.1.0 - Production on Tue Nov 21 11:21:22 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    SQL> SET TIMING ON;
    SQL> DROP TABLE FOO;
    Table dropped.
    Elapsed: 00:00:00.73
    SQL> CREATE TABLE FOO (search_col VARCHAR2(100));
    Table created.
    Elapsed: 00:00:00.03
    SQL> -- Loads of dummy data
    SQL> INSERT INTO FOO (search_col) SELECT OBJECT_NAME || ' ' || OBJECT_TYPE
    2 FROM ALL_OBJECTS WHERE ROWNUM <= 20000;
    20000 rows created.
    Elapsed: 00:00:01.92
    SQL> COMMIT;
    Commit complete.
    Elapsed: 00:00:00.01
    SQL> CREATE INDEX I1 ON FOO(search_col) INDEXTYPE IS CTXSYS.CONTEXT
    2 PARAMETERS(' section group ctxsys.html_section_group');
    Index created.
    Elapsed: 00:00:10.76
    SQL> variable the_filter varchar2(100);
    SQL> begin
    2 :the_filter := 'FILE';
    3 end;
    4 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> SET AUTOTRACE ON EXPLAIN;
    SQL> SELECT COUNT(*)
    2 FROM FOO
    3 WHERE CONTAINS(search_col,:the_filter) > 0;
    COUNT(*)
    29
    Elapsed: 00:00:00.07
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=59)
    1 0 SORT (AGGREGATE)
    2 1 DOMAIN INDEX OF 'I1' (Cost=0 Card=1 Bytes=59)
    SQL> SELECT COUNT(*)
    2 FROM FOO
    3 WHERE 'FILE' IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    COUNT(*)
    29
    Elapsed: 00:00:00.08
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=59)
    1 0 SORT (AGGREGATE)
    2 1 DOMAIN INDEX OF 'I1' (Cost=0 Card=1 Bytes=59)
    SQL> SELECT COUNT(*)
    2 FROM FOO
    3 WHERE :the_filter IS NULL OR CONTAINS(search_col,:the_filter) > 0;
    COUNT(*)
    29
    Elapsed: 00:00:04.06
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=34482 Card=1 Bytes=5
    9)
    1 0 SORT (AGGREGATE)
    2 1 TABLE ACCESS (FULL) OF 'FOO' (Cost=34482 Card=453 Bytes=
    26727)

    Nothing is really strange when you are attempting to integrate with legacy systems! =)
    If no numerical processing is done why should numerical values be stored as numbers?

  • Is there any logical flaw in this query?

    DB version:10gR2
    Do you see any logical flaw, room for improvement in this query
    SELECT SHIP_QRY.RCVD_SHPMT_NBR, SHIP_QRY.ORIG_SHPMT_NBR, SHIP_QRY.DC_ORD_NBR, SHIP_QRY.WORK_ORD_NBR, SHIP_QRY.MFG_PLNT, SHIP_QRY.CONS_CASE_PRTY, SHIP_QRY.CONS_PRTY_DATE, SHIP_QRY.CONS_SEQ, SHIP_QRY.MFG_DATE, SHIP_QRY.RCVD_DATE, SHIP_QRY.XPIRE_DATE, SHIP_QRY.SHIP_BY_DATE, SHIP_QRY.PROC_IMMD_NEEDS, SHIP_QRY.VOL, SHIP_QRY.EST_WT, SHIP_QRY.ACTL_WT, SHIP_QRY.CASE_SIZE_TYPE, SHIP_QRY.PKG_NBR, SHIP_QRY.PKG_TYPE, SHIP_QRY.PO_NBR, SHIP_QRY.SHIP_VIA, SHIP_QRY.TRLR_NBR, SHIP_QRY.STAT_ID, SHIP_QRY.STAT_DATE_TIME, SHIP_QRY.VENDOR_CNTR_NBR, SHIP_QRY.PHYS_ENTITY_CODE, SHIP_QRY.PLT_ID, SHIP_QRY.TIER_QTY, SHIP_QRY.SNGL_pdt_CASE, SHIP_QRY.PUTWY_TYPE, SHIP_QRY.OUT_OF_ZONE_INDIC, SHIP_QRY.LAST_FROZN_DATE_TIME, SHIP_QRY.LAST_CNT_DATE_TIME, SHIP_QRY.SPL_INSTR_CODE_1, SHIP_QRY.SPL_INSTR_CODE_2, SHIP_QRY.SPL_INSTR_CODE_3, SHIP_QRY.SPL_INSTR_CODE_4, SHIP_QRY.SPL_INSTR_CODE_5, SHIP_QRY.MOD_DATE, SHIP_QRY.MOD_DATE_TIME, SHIP_QRY.USER_ID, SHIP_QRY.RETN_DISP_CODE, SHIP_QRY.FINAL_DISP_CODE, SHIP_QRY.INCUB_DATE, SHIP_QRY.SUPP_FTZ_CASE, SHIP_QRY.RCPT_IN_PROC_FLAG, SHIP_QRY.CD_MASTER_ID, SHIP_QRY.VENDOR_MASTER_ID, SHIP_QRY.VOCO_INTRNL_REVERSE_ID, SHIP_QRY.VOCO_INTRNL_REVERSE_PLT_ID, SHIP_QRY.CASE_NBR, SHIP_QRY.ship, SHIP_QRY.LOCN_ID, SHIP_QRY.PREV_LOCN_ID, SHIP_QRY.DEST_LOCN_ID FROM SHIP_QRY WHERE ( SHIP_QRY.CASE_NBR = :1 ) FOR UPDATE WAIT :"SYS_B_0"
    Edited by: user10583227 on Jan 13, 2009 7:05 PM

    How do you expect from us to find your logical flaw when we don't have any idea about your intention?
    Please post the details with some sample input data and your required output data along with brief explanation.
    Got me?
    Regards.
    Satyaki De.

  • Explain plan doubt.

    I have done 'explain plan' for this query:-
    explain plan for
    select MD.* from ppbs_mobile_detail MD, ppbs_inv_sim_serial ISS where MD.LATEST_SIM_SERIAL_NO=ISS.SIM_SERIAL_NO
    and MD.MOBILE_NO=ISS.MOBILE_NO
    which is having indexes on all the four columns of the 2 tables used: LATEST_SIM_SERIAL_NO,SIM_SERIAL_NO,MOBILE_NO,
    MOBILE_NO.
    But only 1 index on mobile no. of ppbs_mobile_detail is firing.
    Is that, indexes on only 1 table should fire.
    I hope, my question is clear. Please help in solving the doubt.
    Regards.

    thanks for ur update.
    i tried, @?/rdbms/admin/utlxplan.sql but it was giving a error like 'unable to open file "?/rdbms/admin/utlxplan.sql"'.
    So, i re-created the table.
    I gave both the analyze statements,
    SQL> analyze table PPBS_INV_SIM_SERIAL compute statistics for table for all indexed columns for all indexes ;
    SQL> analyze table PPBS_MOBILE_DETAIL compute statistics for table for all indexed columns for all indexes ;
    Output of select * from TABLE(dbms_xplan.display) is:-
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 1 | 164 | 21174 |
    | 1 | HASH JOIN | | 1 | 164 | 21174 |
    | 2 | TABLE ACCESS FULL | PPBS_INV_SIM_SERIAL | 3221K| 86M| 9772 |
    | 3 | TABLE ACCESS FULL | PPBS_MOBILE_DETAIL | 1469K| 190M| 2718 |
    Note: cpu costing is off, PLAN_TABLE' is old version
    regards.

  • Explain Plan for Procedure

    Hi,
    For getting the explain plan for a query, we use the statement
    "explain plan for " + Query
    Similarly, to get an explain plan for a procedure, do we have any way like
    "explain plan for " + "Execute " + Procedure
    How do we get an explain plan for a procedure that is executed
    Thanks in Advance.

    teckfreak wrote:
    Hi Robert,
    I am working on an utility application which will execute the procedure and show the explain plan to the user for him to analyze the explain plan and take necessary steps for optimization. I am showing the Procedure inputs to the user, allowing him to enter values and taking them and executing the procedure. I am setting the trace and extracting the explain plan for the procedure using TKPROF utility and showing it to the user.
    While doing so, the trace file is stored in udump folder. I am accessing the trace file from TKPROF utility. I am able to run the TKPROF from the command prompt. But if I try automating the TKPROF command in a .NET application using Process.Start, it says "Not able to access the file.". I tried giving full permissions to Everyone and it still throws the error. Kindly guide me how to proceed.. A different approach that you might want to consider (as indicated by William):
    - Flush the shared pool and use a unique MODULE description for each execution of your procedure (e.g. using DBMS_APPLICATION_INFO.SET_MODULE), e.g. using a logon trigger
    - Query V$SQL for your unique MODULE description and run DBMS_XPLAN.DISPLAY_CURSOR for each corresponding child cursor found (SQL_ID + CHILD_NUMBER) in the shared pool. This plan generation could be automated using a procedure
    The result of this approach corresponds to the tracing using TKPROF since it will provide the actual execution plans used at runtime rather than separate EXPLAIN PLAN results which might differ from the actual plans.
    This assumes that your shared pool is sufficiently large to hold all the child cursor created by your procedure without aging them out while the procedure is running. It's probably also only applicable to an environment where not too much work is being done while running this test and the recommended flushing of the shared pool.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Explain Plan for domain index

    I am running explain plan for queries using a domain index. i.e. an oracle text 'contains' clause. The usage of the domain index appears in the plan o.k, but I am interested in seeing the underlying access to the DR$...$I etc tables and assoicated indexes belonging to ctxsys. Is it possible to see this access ?
    Basically I have all the objects created by the domain index in their own tablespace using a storage preference, but I am wondering if the sub indexes should be moved out from the sub tables for better performance ? Any guidance is appreciated.

    I am running explain plan for queries using a domain index. i.e. an oracle text 'contains' clause. The usage of the domain index appears in the plan o.k, but I am interested in seeing the underlying access to the DR$...$I etc tables and assoicated indexes belonging to ctxsys. Is it possible to see this access ?
    Basically I have all the objects created by the domain index in their own tablespace using a storage preference, but I am wondering if the sub indexes should be moved out from the sub tables for better performance ? Any guidance is appreciated.

  • Can I refactor this query to use an index more efficiently?

    I have a members table with fields such as id, last name, first name, address, join date, etc.
    I have a unique index defined on (last_name, join_date, id).
    This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
    SELECT members.*
            FROM members
            WHERE last_name = 'Smith'
            ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
    SELECT members.*
            FROM members
            WHERE last_name like 'S%'
            ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
    Last_Name:  JoinDate:
    Smith          2/5/2010
    Smuckers     1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
    So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?

    xaeryan wrote:
    I have a members table with fields such as id, last name, first name, address, join date, etc.
    I have a unique index defined on (last_name, join_date, id).
    This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
    SELECT members.*
    FROM members
    WHERE last_name = 'Smith'
    ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
    SELECT members.*
    FROM members
    WHERE last_name like 'S%'
    ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
    Last_Name:  JoinDate:
    Smith          2/5/2010
    Smuckers     1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
    So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?Come on. Index column order does matter. "LIKE 'x%'" actually is full table scan. The db engine accesses contiguous index entries and then uses the ROWID values in the index to retrieve the table rows.

Maybe you are looking for

  • Mavericks forgetting my display arrangement

    I have a MacBook Pro with three external displays - two of which are connected via USB/DisplayLink adapter. Since upgrading to Mavericks, my system forgets the display arrangement every time I reboot. It defaults back to "mirroring" which I have to f

  • Field Currency of Context Node BTADMINH - How to set default

    I've got a field called currency for context node BTADMINH for UI Component BT115QH_SLSQ. This component and view and context node are all enhanced. This currency field takes values such as USD, EUR, etc (currency values for dollar amount). How can I

  • Interactive Reporting 9.2.0.2 & Date Formatting

    I have a computed field in my query wh/ uses the SYSDATE as a base, uses the ADD_MONTH function to change it to the previous month. I then use the TO_CHAR to convert it to the format of MMMM-YY. I run the query, but it seems to convert the SYSDATE -1

  • Portal Error:Unexpected error when trying to access gatewayed content.

    hi friends... Am encountering a Portal Error: Unexpected error when trying to access gatewayed content. this error generally occurs on click on submit buttons.. occuring on my test portal only.... kindly help m resolve this issue...

  • Wow. Applauses for the Skype Support. (Account Blo...

    Dear Sirs, I come with a complaint. Skype has completely BLOCKED/SUSPENDED without any kind of explanation leaving me at a loss as to why.  I cannot believe what I am having to go through to get help with my account that has been blocked. I have no i