QUERY EXPLAIN_PLAN

Hello GURUS
I am on 10.2.0.2.0. I am sorry for big query. It is running really slow. Also please look at the explain plan
I am trying to fix the problem but still the same, runnig slow.
THE SS_SKU_STORE_WEEK is big table with aroundf 1 million rows, it is also partitioned table.
SS_SKU_STORE ia aslo parttitoned table has around 5000 rows
item and ITEM_VENDOR table has aroun 50 thousand rows.PLEASE SUGGEST ME THE SOLUTION.
is there any better way to display execution plan.
Also do we need index in the query if the table is already partitioned
SELECT  /*+ index( ss_sku_store SS_SKU_ST_PK ) */
            TO_NUMBER( ss_sku_store.sku || ss_sku_store.store_num) rowkey,
            ss_sku_store.sku psku,
            ' ' || INITCAP( item.descrip ) description,
            dept_id,
            TO_CHAR( dept_id ) || '.' || TO_CHAR( sub_dept_id ) subdepartment,
            TO_CHAR( dept_id ) || '.' || TO_CHAR( sub_dept_id ) ||'.'|| TO_CHAR( class_id ) class,
            NVL( vendor_id, -1 ),
            NVL( buyer_num, -1),
            NVL( TRIM(pattern_cd), -1),
            DECODE(Color_Cd, 0, -1, NVL( Color_Cd, -1)) Color_Cd,
            NVL( size_cd, -1),
            -1 list_id,
            ss_sku.sku skuattribute,
            ss_sku_store.store_num pstore,
            INITCAP( store.name ) location,
            store.state,
            NVL( INITCAP( regional_vp), 0) regional_vp,
            NVL( INITCAP( regional_merch_mgr), 0) regional_merch_mgr,
            NVL( INITCAP( district_mgr), 0) district_mgr,
            NVL( INITCAP( area_mgr), 0) area_mgr,
            NVL( sq_footage, -1),
            SUBSTR( '000' || fashion_attribute.seq, -3, 3 ) || NVL( store.fashion_att_cd, '' ) fashion_att_cd,
            SUBSTR( '000' || cust_profile.seq, -3, 3 ) || NVL( store.cust_type_cd, '' ) cust_type_cd,
            NVL( section_count, -1) section_count,
            '000' corp_vol_grp_cd,
            0 storegroup,
            store.store_num storeattribute,
            0 storesort,
            submit_status,
            DECODE( current_user, current_user,  1) lockedflag,
            '' aggregatedrowkey,
            '' AttributeDescription,
            starting_on_hand     onhand
   FROM     cust_profile,
            fashion_attribute,
            ( SELECT   vendor_id,
                       sku
              FROM     item_vendor
              WHERE    sku IN ( SELECT  sku
                                FROM    ss_session_sku
                                WHERE   user_key = 164)
              AND      primary_flag = 1 ) primaryvendor,
            ( SELECT   SKU,
                       DECODE( status, 0, 0, DECODE( status, 1 ,0 ,1) ) AS submit_status
              FROM     ( SELECT   /*+ full(ss_session_sku) use_nl(ss_session_sku,ss_sku_store_week) index(ss_sku_store_week SS_SKU_STR_WK_SKU )*/
                                  SS_SKU_Store_Week.SKU,
                                  MAX( NVL( ssk_week_status, 0 ) ) AS status
                         FROM     ss_session_sku,
                                  ss_sku_store_week
                         WHERE    user_key              = 164
                         AND      ss_sku_store_week.sku = ss_session_sku.sku
                         GROUP BY ss_sku_store_week.sku )
             ) sku_status,
            ss_sku,
            store,
            ss_sku_store,
            item
   WHERE    sku_status.sku           =  item.sku
   AND      sku_status.sku           =  ss_sku.sku
   AND      sku_status.sku           =  ss_sku_store.sku
   AND      sku_status.sku           =  primaryvendor.sku
   AND      sku_status.sku           =  sku_status.sku
   AND      ss_sku_store.store_num   =  store.store_num
   AND      store.cust_type_cd       =  cust_profile.cust_type_cd(+)
   AND      store.fashion_att_cd     =  fashion_attribute.fashion_att_cd(+)
   ORDER BY ss_sku_store.sku,
            ss_sku_store.store_num
PLAN_TABLE_OUTPUT
| Id  | Operation                                   | Name                    | Rows  | Bytes | Cost  | Pstart| Pstop |
|   0 | SELECT STATEMENT                            |                         |     1 |   296 |    14 |       |       |
|   1 |  SORT GROUP BY                              |                         |     1 |   296 |    14 |       |       |
|   2 |   NESTED LOOPS OUTER                        |                         |     1 |   296 |    13 |       |       |
|   3 |    NESTED LOOPS OUTER                       |                         |     1 |   278 |    12 |       |       |
|   4 |     NESTED LOOPS                            |                         |     1 |   260 |    11 |       |       |
|   5 |      NESTED LOOPS                           |                         |     1 |   178 |    10 |       |       |
|   6 |       NESTED LOOPS                          |                         |     1 |   153 |    10 |       |       |
PLAN_TABLE_OUTPUT
|   7 |        NESTED LOOPS                         |                         |     1 |    76 |     8 |       |       |
|   8 |         NESTED LOOPS                        |                         |     1 |    54 |     7 |       |       |
|   9 |          NESTED LOOPS                       |                         |     1 |    44 |     5 |       |       |
|  10 |           NESTED LOOPS                      |                         |     1 |    36 |     5 |       |       |
|  11 |            SORT UNIQUE                      |                         |     1 |    10 |     1 |       |       |
|  12 |             INDEX RANGE SCAN                | SS_SESS_SKU_PK          |     1 |    10 |     1 |       |       |
|  13 |            TABLE ACCESS BY INDEX ROWID      | ITEM_VENDOR             |     1 |    26 |     3 |       |       |
|  14 |             INDEX RANGE SCAN                | ITEM_VENDOR_ITEM_FK_IDX |     1 |       |     2 |       |       |
|  15 |           PARTITION HASH ITERATOR           |                         |     1 |     8 |     0 |   KEY |   KEY |
|  16 |            TABLE ACCESS BY LOCAL INDEX ROWID| SS_SKU_STORE_WEEK       |     1 |     8 |     0 |   KEY |   KEY |
|  17 |             INDEX RANGE SCAN                | SS_SKU_STR_WK_SKU       |   601 |       |     0 |   KEY |   KEY |
PLAN_TABLE_OUTPUT
|  18 |          TABLE ACCESS FULL                  | SS_SESSION_SKU          |     1 |    10 |     2 |       |       |
|  19 |         TABLE ACCESS BY INDEX ROWID         | SS_SKU                  |     1 |    22 |     1 |       |       |
|  20 |          INDEX UNIQUE SCAN                  | SS_SKU_PK               |     1 |       |     0 |       |       |
|  21 |        TABLE ACCESS BY INDEX ROWID          | ITEM                    |     1 |    77 |     2 |       |       |
|  22 |         INDEX UNIQUE SCAN                   | ITEM_PK                 |     1 |       |     1 |       |       |
|  23 |       PARTITION HASH ITERATOR               |                         |   489 | 12225 |     0 |   KEY |   KEY |
|  24 |        TABLE ACCESS BY LOCAL INDEX ROWID    | SS_SKU_STORE            |   489 | 12225 |     0 |   KEY |   KEY |
|  25 |         INDEX RANGE SCAN                    | SS_SKU_ST_PK            |    69 |       |     0 |   KEY |   KEY |
|  26 |      TABLE ACCESS BY INDEX ROWID            | STORE                   |     1 |    82 |     1 |       |       |
|  27 |       INDEX UNIQUE SCAN                     | STORE_PK                |     1 |       |     0 |       |       |
|  28 |     TABLE ACCESS BY INDEX ROWID             | FASHION_ATTRIBUTE       |     1 |    18 |     1 |       |       |
PLAN_TABLE_OUTPUT
|  29 |      INDEX UNIQUE SCAN                      | FASHION_ATTRIBUTE_PK    |     1 |       |     0 |       |       |
|  30 |    TABLE ACCESS BY INDEX ROWID              | CUST_PROFILE            |     1 |    18 |     1 |       |       |
|  31 |     INDEX UNIQUE SCAN                       | CUST_PROFILE_PK         |     1 |       |     0 |       |       |
-----------------------------------------------------------------------------------------------------------------------You help is highly appreciated
Message was edited by:
user553284

How can I check Execution plan for the parameter to be passed for query.
alter session set events '10046 trace name context forever, level 4'This will trace your session. Then:
- issue your query
- disconnect
- lookup the trace file in your user_dump_dest directory on the database server
- tkprof <trace file> a.txt sys=no
- watch the row source operation in that tkprof file
If you want to find out what bind variable values were passed, you'll have to dig in the trace file itself and watch out for #BINDS and the "value=" string.
Good luck.
Regards,
Rob.

Similar Messages

  • Query tuning for data-warehousing application in Oracle 8i.

    We have to pick up 24 months old data. Each month data is kept in a different partition.
    2007-May month data is kept in PRESC200705 partition
    SELECT r.account_id,
    p.presc_num,
    spm.product_id,
    p.month,
    t.best_call_state,
    sum(p.trx_count)
    FROM rlup_assigned_account r,
    temp_presc_num_TEST t,
    retail.prescrip_retail partition (PRESC200705) p,
    sherlock.sherlock_product_mapping spm
    WHERE spm.product_id like '056%'
    and spm.mds6 = p.product_id
    and t.CLIENT_ID = p.presc_num
    and r.ndc_pyr_id = p.payer_plan
    and t.best_call_state = r.ST
    GROUP BY r.account_id,
    p.presc_num,
    spm.product_id,
    p.month,
    t.best_call_state
    Q This Query is to be tuned
    SQL> SELECT table_name,
    2 partition_name,
    3 high_value,
    4 num_rows
    5 FROM user_tab_partitions
    6 ;
    no rows selected

    I have the following task:
    Requirement:
    According to the client, new partitions are created every month.
    So the query should contain only the 24 most recent partions leaving one old partition every month.
    So, the query becomes dynamic.
    The query will have to leave one old partion every month and move ahead with the new partion created.
    The total partitions accessed should not cross 24.
    Is this possible?
    Partition# for OCt 2007
    1
    2
    3
    4
    5
    6
    7
    24
    Partition# for Nov 2007
    Old|New
    1
    2..1
    3..2
    4..3
    5..4
    6..5
    7..6
    24..23
    ..24
    Secondly, with one month data (in a partitioned table), the query takes about one hour to run.
    with 24 month data accessed by the query, the query will take 24 hours to run.
    I am sure that Oracle can be tuned to run on such huge data with ease and the query output can
    come within seconds.. Otherwise, nobody would use oracle for datawarehousing applicaions.
    Q. How do I write a dynamic query that references 24 recent partitions, using the query provided:
    abc>SELECT r.account_id,
    2 p.presc_num,
    3 spm.product_id,
    4 p.month,
    5 t.best_call_state,
    6 sum(p.trx_count)
    7 FROM rlup_assigned_account r,
    8 temp_presc_num_TEST t,
    9 retail.prescrip_retail partition (PRESC200705) p,
    10 sherlock.sherlock_product_mapping spm
    11 WHERE spm.product_id like '056%'
    12 and t.CLIENT_ID='934759'
    13 and spm.mds6 = p.product_id
    14 and t.CLIENT_ID = p.presc_num
    15 and r.ndc_pyr_id = p.payer_plan
    16 and t.best_call_state = r.ST
    17 GROUP BY r.account_id,
    18 p.presc_num,
    19 spm.product_id,
    20 p.month,
    21 t.best_call_state
    22 ;
    retail.prescrip_retail partition (PRESC200705) p,
    Partition name, PRESC200705 cannot be hardcoded into the sql.
    Sql should take a range of 24 recent partitions.
    And the query should execute fast too.
    Now, is that what is called a challenge?
    +++++++++++++++++++++++++++++++++++++++++++++++
    Here are the index/constraints/explain_plan output on prescrip_retail table (which is partitioned)
    as well as other tables to which prescrip_retail table is joined
    This is what prescrip_retail looks like. This is the table having partitions.
    It does not seem to have a primary key!
    SQL> desc prescrip_retail
    Name Null? Type
    PRESC_NUM NUMBER
    PFIER_NUM CHAR(8)
    RELID NOT NULL CHAR(9)
    ME_NUM NOT NULL CHAR(10)
    PRODUCT_ID NOT NULL CHAR(6)
    PRODUCT_FRMSTR NOT NULL CHAR(1)
    PAYER_PLAN NOT NULL CHAR(6)
    MONTH NOT NULL DATE
    PYMT_CODE NOT NULL CHAR(1)
    NRX_COUNT NOT NULL NUMBER(7)
    NRX_QUANTITY NOT NULL NUMBER(9)
    NRX_DOLLARS NOT NULL NUMBER(13,2)
    TRX_COUNT NOT NULL NUMBER(7)
    TRX_QUANTITY NOT NULL NUMBER(9)
    TRX_DOLLARS NOT NULL NUMBER(13,2)
    Table Size of Prescrip_Retail...
    1 select table_name,tablespace_name,pct_free,pct_used,num_rows,avg_space
    2 from all_tables
    3* where table_name='PRESCRIP_RETAIL'
    SQL> /
    TABLE_NAME TABLESPACE_NAME PCT_FREE PCT_USED NUM_ROWS AVG_SPACE
    PRESCRIP_RETAIL 2806673860 360
    Explain Plan for the query to be tuned...
    22:32:31 SQL> explain plan set statement_id='vista_query'
    22:43:33 2 for
    22:43:35 3 SELECT r.pfier_account_id,
    22:43:41 4 p.presc_num,
    22:43:41 5 spm.product_id,
    22:43:41 6 p.month,
    22:43:41 7 t.best_call_state,
    22:43:41 8 sum(p.trx_count)
    22:43:41 9 FROM rlup_assigned_account r,
    22:43:41 10 temp_presc_num_TEST t,
    22:43:41 11 retail.prescrip_retail partition (PRESC200705) p,
    22:43:41 12 sherlock.sherlock_product_mapping spm
    22:43:41 13 WHERE spm.product_id like '056%'
    22:43:41 14 and spm.mds6 = p.product_id
    22:43:41 15 and t.CLIENT_ID = p.presc_num
    22:43:41 16 and r.ndc_pyr_id = p.payer_plan
    22:43:41 17 and t.best_call_state = r.ST
    22:43:41 18 GROUP BY r.pfier_account_id,
    22:43:41 19 p.presc_num,
    22:43:41 20 spm.product_id,
    22:43:41 21 p.month,
    22:43:41 22 t.best_call_state;
    Explained.
    SQL> select statement_id,operation,options,object_name
    2 from plan_table
    3 where statement_id='vista_query';
    22:46:03 SQL> /
    STATEMENT_ID OPERATION OPTIONS OBJECT_NAME
    vista_query SELECT STATEMENT
    vista_query SORT GROUP BY
    vista_query HASH JOIN
    vista_query TABLE ACCESS FULL TEMP_PRESC_NUM_TEST
    vista_query HASH JOIN
    vista_query TABLE ACCESS FULL RLUP_ASSIGNED_ACCOUNT
    vista_query HASH JOIN
    vista_query TABLE ACCESS FULL SHERLOCK_PRODUCT_MAPPING
    vista_query TABLE ACCESS FULL PRESCRIP_RETAIL
    9 rows selected.
    Partition Pruning: This is supposed to provide an insight to the partitions oracle
    vists internally...
    I guess we can use "month>= add_months(sysdate,-24)" instead of partions too.
    I don't think Oracle is visiting any partitions.
    I'll also search into all_tab_partitions to verify this.
    Explain_Plan for what partitions oracle visits internally (partition pruning):
    SQL> ed
    Wrote file afiedt.buf
    1 explain plan set statement_id='vista'
    2 for select * from retail.prescrip_retail
    3* where month>= add_months(sysdate,-24)
    SQL> /
    Explained.
    Elapsed: 00:00:00.05
    22:13:56 SQL> select statement_id,operation,options,object_name
    22:14:28 2 from plan_table
    22:14:30 3 where statement_id='vista';
    STATEMENT_ID OPERATION
    OPTIONS OBJECT_NAME
    vista SELECT STATEMENT
    vista PARTITION RANGE
    ITERATOR
    vista TABLE ACCESS
    FULL PRESCRIP_RETAIL
    Elapsed: 00:00:01.00
    Indexes/Constraints on PRESCRIP_RETAIL table:
    SQL> ED
    Wrote file afiedt.buf
    1 SELECT TABLE_NAME,TABLE_TYPE,INDEX_NAME,INDEX_TYPE,PCT_FREE,STATUS,PARTITIONED
    2 FROM ALL_INDEXES
    3* WHERE TABLE_NAME IN ('PRESCRIP_RETAIL')
    SQL> /
    TABLE_NAME TABLE INDEX_NAME INDEX_TYPE PCT_FREE STATUS PAR
    PRESCRIP_RETAIL TABLE BX6_PRESC_RELID BITMAP N/A YES
    PRESCRIP_RETAIL TABLE BX7_PRESC_ME BITMAP N/A YES
    PRESCRIP_RETAIL TABLE BX1_PRESC_PROD BITMAP N/A YES
    PRESCRIP_RETAIL TABLE BX2_PRESC_PAYER BITMAP N/A YES
    PRESCRIP_RETAIL TABLE BX3_PRESC_PAYERCD BITMAP N/A YES
    PRESCRIP_RETAIL TABLE BX4_PRESC_PRESC BITMAP N/A YES
    PRESCRIP_RETAIL TABLE BX5_PRESC_PFIER BITMAP N/A YES
    7 rows selected.
    SQL> ed
    Wrote file afiedt.buf
    1 SELECT TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,DEFERRABLE
    2 FROM ALL_CONSTRAINTS
    3* WHERE TABLE_NAME IN ('PRESCRIP_RETAIL')
    SQL> /
    TABLE_NAME CONSTRAINT_NAME C STATUS DEFERRABLE
    PRESCRIP_RETAIL SYS_C001219 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001220 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001221 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001222 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001223 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001224 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001225 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001226 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001227 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001228 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001229 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001230 C ENABLED NOT DEFERRABLE
    PRESCRIP_RETAIL SYS_C001231 C ENABLED NOT DEFERRABLE
    13 rows selected.
    In all_tables:
    NUM_ROWS:2806673860
    AVG_SPACE:360
    Here is the data size in the table.
    SQL> select count(*) from PRESCRIP_RETAIL;
    COUNT(*)
    4602980312
    Again, here is the partition information and the amount of data in each partition:
    SQL> ed
    Wrote file afiedt.buf
    1 select
    2 partition_name,SUBPARTITION_COUNT,PARTITION_POSITION,TABLESPACE_NAME,
    3 NUM_ROWS
    4 from all_tab_partitions
    5 where table_name='PRESCRIP_RETAIL'
    6* order by partition_name desc
    SQL> /
    PARTITION_NAME SUBPARTITION_COUNT PARTITION_POSITION TABLESPACE_NAME NUM_ROWS
    PRESC200705 0 36 PRESC_PARTITION_29 141147085
    PRESC200704 0 35 PRESC_PARTITION_28 140299317
    PRESC200703 0 34 PRESC_PARTITION_27 140703128
    PRESC200702 0 33 PRESC_PARTITION_26 132592733
    PRESC200701 0 32 PRESC_PARTITION_25 145832356
    PRESC200612 0 31 PRESC_PARTITION_24 136702837
    PRESC200611 0 30 PRESC_PARTITION_23 137421767
    PRESC200610 0 29 PRESC_PARTITION_22 140836119
    PRESC200609 0 28 PRESC_PARTITION_21 131273578
    PRESC200608 0 27 PRESC_PARTITION_20 134967317
    PRESC200607 0 26 PRESC_PARTITION_19 130785504
    PRESC200606 0 25 PRESC_PARTITION_18 131472696
    PRESC200605 0 24 PRESC_PARTITION_17 138590581
    PRESC200604 0 23 PRESC_PARTITION_16 126849798
    PRESC200603 0 22 PRESC_PARTITION_15 137164667
    PRESC200602 0 21 PRESC_PARTITION_14 126938544
    PRESC200601 0 20 PRESC_PARTITION_13 135408324
    PRESC200512 0 19 PRESC_PARTITION_12 123285100
    PRESC200511 0 18 PRESC_PARTITION_11 121245764
    PRESC200510 0 17 PRESC_PARTITION_10 122112932
    PRESC200509 0 16 PRESC_PARTITION_09 119137399
    PRESC200508 0 15 PRESC_PARTITION_08 123372311
    PRESC200507 0 14 PRESC_PARTITION_07 112905435
    PRESC200506 0 13 PRESC_PARTITION_06 119581406
    PRESC200505 0 12 PRESC_PARTITION_05 123977315
    PRESC200504 0 11 PRESC_PARTITION_04 118975597
    PRESC200503 0 10 PRESC_PARTITION_03 125782688
    PRESC200502 0 9 PRESC_PARTITION_02 117448839
    PRESC200501 0 8 PRESC_PARTITION_01 122214436
    PRESC200412 0 7 PRESC_PARTITION_36 124799998
    PRESC200411 0 6 PRESC_PARTITION_35 125471042
    PRESC200410 0 5 PRESC_PARTITION_34 118457422
    PRESC200409 0 4 PRESC_PARTITION_33 119537488
    PRESC200408 0 3 PRESC_PARTITION_32 121319137
    PRESC200407 0 2 PRESC_PARTITION_31 115226621
    PRESC200406 0 1 PRESC_PARTITION_30 119143031
    36 rows selected.
    Data in induvidual partition of PRESCRIP_RETAIL.
    SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200704);
    COUNT(*)
    140299317
    SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200703);
    COUNT(*)
    140703128
    SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200702);
    COUNT(*)
    132592733
    SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200701);
    COUNT(*)
    145832356
    SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200606);
    COUNT(*)
    131472696
    SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200605);
    COUNT(*)
    138590581
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Other tables info:
    Index of other tables related to PRESCRIP_REATIL:
    SQL> SELECT TABLE_NAME,TABLE_TYPE,INDEX_NAME,INDEX_TYPE,PCT_FREE,STATUS,PARTITIONED
    2 FROM ALL_INDEXES
    3 WHERE TABLE_NAME IN ('RLUP_ASSIGNED_ACCOUNT','TEMP_PRESC_NUM_TEST','SHERLOCK_PRODUCT_MAPPING');
    SQL> /
    TABLE_NAME TABLE INDEX_NAME INDEX_TYPE PCT_FREE STATUS PAR
    SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_PK NORMAL 10 VALID NO
    SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_X1 NORMAL 0 VALID NO
    SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_BX1 BITMAP 0 VALID NO
    SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_BX2 BITMAP 0 VALID NO
    SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_BX3 BITMAP 0 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE BX1_RLUP_ASSIGNED_ACCT_PYR BITMAP 10 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE BX2_RLUP_ASSIGNED_ACCT_TOPLVL BITMAP 10 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE BX3_RLUP_ASSIGNED_ACCT_PBM BITMAP 10 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE BX4_RLUP_ASSIGNED_ACCT_AA_FLAG BITMAP 10 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE BX5_RLUP_ASSIGNED_ACCT_AA_CHD BITMAP 10 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE BX6_RLUP_ASSIGNED_ACCT_PBM_FLG BITMAP 10 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE BX7_RLUP_ASSIGNED_ACCT_ACCTID BITMAP 10 VALID NO
    RLUP_ASSIGNED_ACCOUNT TABLE PK_RLUP_ASSIGNED_ACCOUNT NORMAL 10 VALID NO
    13 rows selected.
    Constraints in other tables:
    SQL> SELECT TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,DEFERRABLE
    2 FROM ALL_CONSTRAINTS
    3 WHERE TABLE_NAME IN ('RLUP_ASSIGNED_ACCOUNT','TEMP_PRESC_NUM_TEST','SHERLOCK_PRODUCT_MAPPING');
    TABLE_NAME CONSTRAINT_NAME C STATUS DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637753 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637754 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637755 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637756 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637757 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637758 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637759 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637760 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637761 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT SYS_C00637762 C ENABLED NOT DEFERRABLE
    RLUP_ASSIGNED_ACCOUNT PK_RLUP_ASSIGNED_ACCOUNT P ENABLED NOT DEFERRABLE
    TEMP_PRESC_NUM_TEST SYS_C00640536 C ENABLED NOT DEFERRABLE
    12 rows selected.
    TEMP_PRESC_NUM_TEST does not contain any constraints or index.

  • [Oracle 8i] Help with query performance

    The following query is running VERY slowly for me:
    SELECT     oord.part_nbr
    ,     sopn.ord_nbr
    ,     sopn.sub_ord_nbr
    ,     sopn.major_seq_nbr
    ,     sopn.wctr_id
    ,     sopn.oper_desc
    ,     SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
    ,     pact.activity_date
    FROM     PACT pact
    ,     SOPN sopn
    ,     OORD oord
    WHERE     pact.order_nbr          = sopn.ord_nbr          AND
         pact.maj_seq_nbr     = sopn.major_seq_nbr     AND
         sopn.sub_ord_nbr     = pact.sub_order_nbr     AND
         sopn.ord_nbr          = oord.ord_nbr          AND
         sopn.sub_ord_nbr     = oord.sub_ord_nbr     AND
              pact.activity_date     >= ?          AND
              sopn.rework_ind          = 'N'          AND
              (oord.part_nbr, sopn.major_seq_nbr, sopn.wctr_id)
              NOT IN     (
                        SELECT     rout.doc_nbr
                        ,     rout.major_seq_nbr
                        ,     rout.wctr_id
                        FROM ROUT rout
                        WHERE     (rout.begn_eff_dt    <=SYSDATE)     AND
                             (rout.end_eff_dt    >SYSDATE)     AND
                             (rout.po_rework_ind    ='N')       
    GROUP BY     oord.part_nbr
    ,          sopn.ord_nbr
    ,          sopn.sub_ord_nbr
    ,          sopn.major_seq_nbr
    ,          sopn.wctr_id
    ,          sopn.oper_desc
    ,          pact.activity_dateI sent a request off to my IT department (specifically asking for the explain plan and tkprof, as described in the [main post on this topic|http://forums.oracle.com/forums/thread.jspa?threadID=501834] ), and they replied with a screen shot of the 'explain plan' the tool they use (Toad) provides.
    !http://temp-sample.webs.com/explain_plan.jpg!
    I don't know if anyone can help me based off this, since I know it's not really what the main post says to provide, but it's all I was given.
    My IT department also made a few changes to my original query (see below) and told me it got rid of one of the full scans of the PACT table, but they aren't sure why it helped, and I have to say I'm suspect of any fixes where it's not understood why it helped.
    SELECT     oord.part_nbr
    ,     sopn.ord_nbr
    ,     sopn.sub_ord_nbr
    ,     sopn.major_seq_nbr
    ,     sopn.wctr_id
    ,     sopn.oper_desc
    ,     SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
    ,     pact.activity_date
    FROM     PACT pact
    ,     SOPN sopn
    ,     OORD oord
    WHERE     sopn.ord_nbr          = pact.order_nbr     AND
         sopn.major_seq_nbr     = pact.maj_seq_nbr     AND
         pact.sub_order_nbr     = sopn.sub_ord_nbr     AND
         oord.ord_nbr           = sopn.ord_nbr          AND
         oord.sub_ord_nbr     = sopn.sub_ord_nbr     AND
         (pact.activity_date >= ?)               AND
         'N'               = sopn.rework_ind     AND
         pact.order_nbr          = oord.ord_nbr          AND
         oord.sub_ord_nbr = pact.sub_order_nbr          AND
         (oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) NOT IN
              SELECT /*+ INDEX_JOIN(ROUT) */     rout.doc_nbr
              ,                    rout.major_seq_nbr
              ,                    rout.wctr_id
              FROM     ROUT rout
              WHERE     rout.begn_eff_dt     <= SYSDATE     AND
                   rout.end_eff_dt      > SYSDATE     AND
                   'N' = rout.po_rework_ind
    GROUP BY     oord.part_nbr
    ,          sopn.ord_nbr
    ,          sopn.sub_ord_nbr
    ,          sopn.major_seq_nbr
    ,          sopn.wctr_id
    ,          sopn.oper_desc
    ,          pact.activity_dateAny help on this would be appreciated... when I run this (right now) for 2-3 months of data, it takes a minimum of 3 hours to complete, and I'll eventually need to run this for up to a year's worth of data.

    Hi,
    Well, let's see.
    You get 156 rows returned using IN and 121 rows using exists.
    You need identify the 'missing records' and conclude if that's correct or not, I'm not able to do that from remote, without knowing your data or system.
    It would be helpful if we could see cost and cardinalities, you (or your IT dept.) can get them easily be running the queries from your SQL*Plus prompt.
    Type
    SET AUTOTRACE TRACEONLYbefore running the queries.
    That gives you the explain plan and additional statistics (sorts in memory and sorts to disk).
    Since you use a group by, and you're on 8i can you also post results of these queries:
    select banner from v$version;
    select name, value, isdefault from v$parameter where name like '%area%';Finally, does below query give you a different plan?
    select oord.part_nbr
    ,      oord.ord_nbr
    ,      oord.sub_ord_nbr
    ,      pact.major_seq_nbr
    ,      sopn.wctr_id
    ,      sopn.oper_desc
    ,      sum(pact.act_dlrs_earned + pact.act_brdn_dls_earned + pact.tool_dlrs_earned + pact.act_fix_brdn_dls_ea)
    ,      pact.activity_date
    from   oord oord 
    ,      pact pact
    ,      sopn sopn
    where  oord.ord_nbr       = pact.order_nbr
    and    oord.sub_ord_nbr   = pact.sub_order_nbr
    and    oord.ord_nbr       = sopn.ord_nbr
    and    oord.sub_ord_nbr   = sopn.sub_ord_nbr
    and    sopn.major_seq_nbr = pact.maj_seq_nbr
    and    (pact.activity_date >= ?)
    and    'N' = sopn.rework_ind
    and    (oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) not in ( select rout.doc_nbr
                                                                    ,      rout.major_seq_nbr
                                                                    ,      rout.wctr_id
                                                                    from   rout rout
                                                                    where  rout.begn_eff_dt <= sysdate
                                                                    and    rout.end_eff_dt > sysdate
                                                                    and    'N' = rout.po_rework_ind)
    group  by oord.part_nbr
    ,         oord.ord_nbr
    ,         oord.sub_ord_nbr
    ,         pact.major_seq_nbr
    ,         sopn.wctr_id
    ,         sopn.oper_desc
    ,         pact.activity_date

  • How do you view the execution plan of a query?

    I want to see if a particular index was used for a specific query....

    Becareful. You are in the Forum of OBIEE. It's much more a database question.
    You can read an plan with a lot of tool. Toad permit it and I assume that Sql Developer also must give it.
    Otherwise, you can use the basic command of Oracle as explain plan :
    http://gerardnico.com/wiki/database/oracle/explain_plan
    Cheers
    Nico

  • Help with tuning query

    Hi All,
    I have the following query which seems to be blowing our temp tablespace.
    Can anyone help me in tuning this?
    The query and explian plan are below.
    Thanks for all your help
    select trim(b.pnr_reference) || ',"' || to_char(b.booking_date, 'DD-MON-YY') || '","' || trim(p.title) || '","' ||
    trim(p.forename) || '","' || trim(p.surname) || '
    ","' || trim(p.email) || '","' || trim(b.home_phone) || '","' || trim(b.address_line_1) || '","' ||
    trim(b.address_line_2) || '","' || trim(b.address_line_3)
    || '","' || trim(b.postcode) || '","' || trim(b.country_code) || '","' || null || '","' || -- frequent flyer number
    trim(b.promo_opt_in) || '","' || trim(bsout.flight_number) || '","' || to_char(bsout.departure_date, 'DD-MON-YY') || '","' ||trim(bsret.flight_number) ||
    '","' || to_char(bsret.departure_date, 'DD-MON-YY') || ' ","' || pax_cnt.num_adults || '","' || pax_cnt.num_children || '","' || pax_cnt.num_infants || '","' ||fares_by_booking.gross_fare_adult || '","' || fares_by_booking.gross_fare_child || '","' ||fares_by_booking.gross_fare_infant || '","' || fares_by_booking.total_gross_fare || '","' || trim(ps.fare_basis) || '","' ||trim(ps1.fare_basis) || '","' || null || '","' || -- user_id null || '","' || -- ip_address
    fares_by_booking.currency || '","' || trim(bsout.dep_airport_code) || '","' ||trim(bsout.dest_airport_code) || '","' ||fares_by_booking.gross_fare_adult*ex.exchange_rate || '","' || null || '","' || -- iata_no
    trim(b.other_opt_in) || '","' || c.returned || '","' || c.not_available ||'","' || c.on_request || '","' || c.matched || '"
    ,"' || trim(c.location_code) || '","' || to_char(c.pickup_date, 'DD-MON-YY') || '","' || to_char(c.return_date, 'DD-MON-YY') || '","' || c.period || '","' ||
    trim(cb.book_ref) || '","' || cb.car_num || '","' ||
    c.avail_warn_code || '","' || c.avail_err_code || '",
    "' || c.res_warn_code || '","' || c.res_err_code |
    | '"' from bookings b, car_hire_transactions c, car_hire_bookings cb, pax p, booking_sectors bsout, booking_sectors bsret, pax_sectors ps, pax_sectors ps1,
    exchange_rates ex, (select b2.booking_id, sum(decode(p2.pax_type,'A',1,0)) num_adults, sum(decode(p2.pax_type,'C',1,0)) num_children, sum(decode(p2.pax_type,'I',1
    ,0)) num_infants from pax p2, bookings b2
    where b2.booking_id = p2.booking_id and b2.booking_date
    between TO_DATE('08-08-2005/00:00', 'DD-MM-YYYY/HH24:MI') and TO_DATE('15-08-2005/00:00', 'DD-MM-YYYY/HH24:MI') group by
    b2.booking_id) pax_cnt, (select booking_id, currency, sum(gross_fare_adult) gross_fare_adult,
    sum(gross_fare_child) gross_fare_child, sum(gross_fare_infant) gross_fare_infant,sum(total_gross_fare) total_gross_fare from (select b3.booking_id booking_id, ps3.sector_seq,
    ps3.currency_code currency, max(decode(p3.pax_type,'A',ps3.gross_fare,0)) gross_fare_adult,
    max(decode(p3.pax_type,'C',ps3.gross_fare,0)) gross_fare_child
    , max(decode(p3.pax_type,'I',ps3.gross_fare,0
    )) gross_fare_infant, sum(ps3.gross_fare) total_gross_fare from pax p3,pax_sectors ps3, bookings b3 where b3.booking_id = p3.booking_id and b3.booking_id = ps3.booking_id and p3.pax_seq = ps3.pax_seq and b3.booking_date between TO_DATE('08-08-2005/00:00', 'DD-MM-Y
    YYY/HH24:MI') and TO_DATE('15-08-2005/00:00', 'DD-MM-YYYY/HH24:M
    I') group by b3.booking_id, ps3
    .currency_code, ps3.sector_seq) fares_by_sector group by booking_id, currency) fares_by_booking where
    b.booking_date between TO_DATE('08-08-2005/00:00', 'DD-MM-YYYY/
    HH24:MI') and TO_DATE('15-08-2005/00:00', 'DD-MM-YYYY/HH24:MI')
    and b.car_hire_id = c.car_hire_id(+) and c.car_hire_id = cb.
    car_hire_id(+) and p.booking_id = b.booking_id and p.pax_seq
    = 1 and b.booking_id = bsout.booking_id and bsout.sector_seq = 1 and b.booking_id = bsret.booking_id(+) and bsret.sector_seq(+) = 2 and p.booking_id = ps.booking_id and p.pax_seq
    = ps.pax_seq and ps.sector_seq = 1 and p.booking_id = ps1.booking_id(+) and p.pax_seq = ps1.pax_seq(+) and ps1.sector_seq(+) = 2 and b.booking_id = pax_cnt.booking_id and b.booking_id = fares_by_booking.booking_id and ex.currency_from = fares_by_booking.currency and ex.currency_to = 'GBP' and ex.date_entered = (select max(ex2.date_entered) from exchange_rates ex2 where currency_from = fares_by_booking.currency and currency_to = 'GBP' and ex2.date_entered < b.booking_date)
    Explain plan
    11:34:28 sqlpplus> /
    Elapsed: 00:00:00.00
    Execution Plan
    0
    SELECT STATEMENT Optimizer=CHOOSE (Cost=16 Card=1 Bytes=973)
    1 0
    HASH JOIN (OUTER) (Cost=16 Card=1 Bytes=973)
    2 1
    HASH JOIN (Cost=9 Card=1 Bytes=958)
    3 2
    NESTED LOOPS (OUTER) (Cost=6 Card=1 Bytes=902)
    4 3
    NESTED LOOPS (Cost=6 Card=1 Bytes=871)
    5 4
    NESTED LOOPS (OUTER) (Cost=6 Card=1 Bytes=812)
    6 5
    NESTED LOOPS (Cost=6 Card=1 Bytes=753)
    7 6
    NESTED LOOPS (Cost=6 Card=1 Bytes=533)
    8 7
    NESTED LOOPS (OUTER) (Cost=6 Card=1 Bytes=475)
    9 8
    NESTED LOOPS (Cost=6 Card=1 Bytes=429)
    10 9
    NESTED LOOPS (Cost=6 Card=1 Bytes=412)
    11 10
    VIEW (Cost=6 Card=1 Bytes=75)
    12 11
    SORT (GROUP BY) (Cost=6 Card=1 Bytes=84)
    13 12
    VIEW (Cost=6 Card=1 Bytes=84)
    14 13
    SORT (GROUP BY) (Cost=6 Card=1 Bytes=118)
    15 14
    FILTER
    16 15
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX_SECTORS'
    17 16
    NESTED LOOPS (Cost=4 Card=1 Bytes=118)
    18 17
    NESTED LOOPS (Cost=4 Card=1 Bytes=60)
    19 18
    VIEW OF 'index$_join$_017' (Cost=4 Card=1
    Bytes=31)
    20 19
    HASH JOIN
    21 20
    INDEX (FAST FULL SCAN) OF 'BOO_PK' (UN
    IQUE) (Cost=1 Card=1 Bytes=31)
    22 20
    INDEX (FAST FULL SCAN) OF 'BOO_SHARES_
    UID_UK' (UNIQUE) (Cost=1 Card=1 Bytes=31)
    23 18
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX'
    24 23
    INDEX (RANGE SCAN) OF 'PAX_PK' (UNIQUE)
    25 17
    INDEX (RANGE SCAN) OF 'PXS_PAX_FK_I' (NON-UN
    IQUE)
    26 10
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKINGS'
    27 26
    INDEX (UNIQUE SCAN) OF 'BOO_PK' (UNIQUE)
    28 9
    TABLE ACCESS (BY INDEX ROWID) OF 'EXCHANGE_RATES'
    29 28
    INDEX (UNIQUE SCAN) OF 'EXR_PK' (UNIQUE)
    30 29
    SORT (AGGREGATE)
    31 30
    FIRST ROW (Cost=2 Card=284 Bytes=3692)
    32 31
    INDEX (RANGE SCAN (MIN/MAX)) OF 'EXR_PK' (UNIQUE) (C
    ost=2 Card=200)
    33 8
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKING_SECTORS'
    34 33
    INDEX (UNIQUE SCAN) OF 'BKS_PK' (UNIQUE)
    35 7
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKING_SECTORS'
    36 35
    INDEX (UNIQUE SCAN) OF 'BKS_PK' (UNIQUE)
    37 6
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX'
    38 37
    INDEX (UNIQUE SCAN) OF 'PAX_PK' (UNIQUE)
    39 5
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX_SECTORS'
    40 39
    INDEX (UNIQUE SCAN) OF 'PXS_UK' (UNIQUE)
    41 4
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX_SECTORS'
    42 41
    INDEX (UNIQUE SCAN) OF 'PXS_UK' (UNIQUE)
    43 3
    TABLE ACCESS (BY INDEX ROWID) OF 'CAR_HIRE_TRANSACTIONS'
    44 43
    INDEX (UNIQUE SCAN) OF 'CHT_PK' (UNIQUE)
    45 2
    VIEW (Cost=3 Card=1 Bytes=56)
    46 45
    SORT (GROUP BY) (Cost=3 Card=1 Bytes=47)
    47 46
    FILTER
    48 47
    TABLE ACCESS (BY INDEX ROWID) OF 'PAX'
    49 48
    NESTED LOOPS (Cost=1 Card=1 Bytes=47)
    50 49
    TABLE ACCESS (BY INDEX ROWID) OF 'BOOKINGS' (Cost=1 Card=1 Bytes
    =31)
    51 50
    INDEX (SKIP SCAN) OF 'BOO_SHARES_UID_UK' (UNIQUE)
    52 49
    INDEX (RANGE SCAN) OF 'PAX_PK' (UNIQUE)
    53 1
    TABLE ACCESS (FULL) OF 'CAR_HIRE_BOOKINGS' (Cost=6 Card=7 Bytes=105)

    Hi Guys,
    As requested here is the formatted sql.
    We are using pga_aggregate_target which is set to 25165824. I dont know if this is relevant but the sort_area_size is set to 524288.
    Thanks
    SQL
    SELECT trim(b.pnr_reference) || ',"' || to_char(b.booking_date, 'DD-MON-YY')
    || '","' || trim(p.title) || '","' || trim(p.forename) || '","' ||
    trim(p.surname) || '","' || trim(p.email) || '","' || trim(b.home_phone)
    || '","' || trim(b.address_line_1) || '","' || trim(b.address_line_2)
    || '","' || trim(b.address_line_3) || '","' || trim(b.postcode) ||
    '","' || trim(b.country_code) || '","' || null || '","' || trim(
    b.promo_opt_in) || '","' || trim(bsout.flight_number) || '","' ||
    to_char(bsout.departure_date, 'DD-MON-YY') || '","' || trim(
    bsret.flight_number) || '","' || to_char(bsret.departure_date,
    'DD-MON-YY') || '","' || pax_cnt.num_adults || '","' ||
    pax_cnt.num_children || '","' || pax_cnt.num_infants || '","' ||
    fares_by_booking.gross_fare_adult || '","' ||
    fares_by_booking.gross_fare_child || '","' ||
    fares_by_booking.gross_fare_infant || '","' ||
    fares_by_booking.total_gross_fare || '","' || trim(ps.fare_basis) ||
    '","' || trim(ps1.fare_basis) || '","' || null || '","' || null || '","'
    || fares_by_booking.currency || '","' || trim(bsout.dep_airport_code)
    || '","' || trim(bsout.dest_airport_code) || '","' ||
    fares_by_booking.gross_fare_adult * ex.exchange_rate || '","' || null
    || '","' || trim(b.other_opt_in) || '","' || c.returned || '","' ||
    c.not_available || '","' || c.on_request || '","' || c.matched || '","'
    || trim(c.location_code) || '","' || to_char(c.pickup_date, 'DD-MON-YY'
    ) || '","' || to_char(c.return_date, 'DD-MON-YY') || '","' || c.period
    || '","' || trim(cb.book_ref) || '","' || cb.car_num || '","' ||
    c.avail_warn_code || '","' || c.avail_err_code || '","' ||
    c.res_warn_code || '","' || c.res_err_code || '"'
    FROM bookings b, car_hire_transactions c, car_hire_bookings cb, pax p,
    booking_sectors bsout, booking_sectors bsret, pax_sectors ps,
    pax_sectors ps1, exchange_rates ex, (SELECT b2.booking_id, sum(
    decode(p2.pax_type, 'A', 1,
    0)) num_adults, sum(
    decode(p2.pax_type, 'C', 1,
    0)) num_children,
    sum(decode(p2.pax_type,
    'I', 1, 0)) num_infants
    FROM pax p2, bookings b2
    WHERE b2.booking_id = p2.booking_id
    AND b2.booking_date BETWEEN to_date('08-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI') AND to_date('15-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI')
    GROUP BY b2.booking_id) pax_cnt, (SELECT booking_id, currency,
    sum(gross_fare_adult)
    gross_fare_adult,
    sum(gross_fare_child)
    gross_fare_child,
    sum(gross_fare_infant)
    gross_fare_infant,
    sum(total_gross_fare)
    total_gross_fare
    FROM (SELECT b3.booking_id booking_id, ps3.sector_seq,
    ps3.currency_code currency, max(decode(p3.pax_type,
    'A', ps3.gross_fare, 0)) gross_fare_adult, max(
    decode(p3.pax_type, 'C', ps3.gross_fare, 0))
    gross_fare_child, max(decode(p3.pax_type, 'I',
    ps3.gross_fare, 0)) gross_fare_infant, sum(
    ps3.gross_fare) total_gross_fare
    FROM pax p3, pax_sectors ps3, bookings b3
    WHERE b3.booking_id = p3.booking_id
    AND b3.booking_id = ps3.booking_id
    AND p3.pax_seq = ps3.pax_seq
    AND b3.booking_date BETWEEN to_date(
    '08-08-2005/00:00', 'DD-MM-YYYY/HH24:MI') AND
    to_date('15-08-2005/00:00', 'DD-MM-YYYY/HH24:MI')
    GROUP BY b3.booking_id, ps3.currency_code,
    ps3.sector_seq) fares_by_sector
    GROUP BY booking_id, currency) fares_by_booking
    WHERE b.booking_date BETWEEN to_date('08-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI') AND to_date('15-08-2005/00:00',
    'DD-MM-YYYY/HH24:MI')
    AND b.car_hire_id = c.car_hire_id (+)
    AND c.car_hire_id = cb.car_hire_id (+)
    AND p.booking_id = b.booking_id
    AND p.pax_seq = 1
    AND b.booking_id = bsout.booking_id
    AND bsout.sector_seq = 1
    AND b.booking_id = bsret.booking_id (+)
    AND bsret.sector_seq (+) = 2
    AND p.booking_id = ps.booking_id
    AND p.pax_seq = ps.pax_seq
    AND ps.sector_seq = 1
    AND p.booking_id = ps1.booking_id (+)
    AND p.pax_seq = ps1.pax_seq (+)
    AND ps1.sector_seq (+) = 2
    AND b.booking_id = pax_cnt.booking_id
    AND b.booking_id = fares_by_booking.booking_id
    AND ex.currency_from = fares_by_booking.currency
    AND ex.currency_to = 'GBP'
    AND ex.date_entered = (SELECT max(ex2.date_entered)
    FROM exchange_rates ex2
    WHERE currency_from = fares_by_booking.currency
    AND currency_to = 'GBP'
    AND ex2.date_entered < b.booking_date)
    explain_plan
    Execution Steps:
    Step # Step Name
    41 SELECT STATEMENT
    40 FILTER
    36 NESTED LOOPS [OUTER]
    33 NESTED LOOPS
    30 HASH JOIN [OUTER]
    28 NESTED LOOPS [OUTER]
    25 HASH JOIN
    23 HASH JOIN [OUTER]
    21 HASH JOIN
    15 HASH JOIN
    5 HASH JOIN
    3 HASH JOIN
    1 CAM_OWNER.PAX_SECTORS TABLE ACCESS [FULL]
    2 CAM_OWNER.PAX TABLE ACCESS [FULL]
    4 CAM_OWNER.BOOKINGS TABLE ACCESS [FULL]
    14 . VIEW
    13 SORT [GROUP BY]
    12 . VIEW
    11 SORT [GROUP BY]
    10 HASH JOIN
    8 HASH JOIN
    6 CAM_OWNER.BOOKINGS TABLE ACCESS [FULL]
    7 CAM_OWNER.PAX_SECTORS TABLE ACCESS [FULL]
    9 CAM_OWNER.PAX TABLE ACCESS [FULL]
    20 . VIEW
    19 SORT [GROUP BY]
    18 HASH JOIN
    16 CAM_OWNER.BOOKINGS TABLE ACCESS [FULL]
    17 CAM_OWNER.PAX TABLE ACCESS [FULL]
    22 CAM_OWNER.PAX_SECTORS TABLE ACCESS [FULL]
    24 CAM_OWNER.EXCHANGE_RATES TABLE ACCESS [FULL]
    27 CAM_OWNER.CAR_HIRE_TRANSACTIONS TABLE ACCESS [BY INDEX ROWID]
    26 CAM_OWNER.CHT_PK INDEX [UNIQUE SCAN]
    29 CAM_OWNER.CAR_HIRE_BOOKINGS TABLE ACCESS [FULL]
    32 CAM_OWNER.BOOKING_SECTORS TABLE ACCESS [BY INDEX ROWID]
    31 CAM_OWNER.BKS_PK INDEX [UNIQUE SCAN]
    35 CAM_OWNER.BOOKING_SECTORS TABLE ACCESS [BY INDEX ROWID]
    34 CAM_OWNER.BKS_PK INDEX [UNIQUE SCAN]
    39 SORT [AGGREGATE]
    38 FIRST ROW
    37 CAM_OWNER.EXR_PK INDEX [RANGE SCAN (MIN/MAX)]

  • Simple SQL Query is not using Bitmap index

    Hello to All,
    We are having Oracle9i Database and using it for the datawarehouse purpose.
    I have created the bitmap index on calledinfo column and I am running the following simple query which takes serveral hours to complete:
    select * from ssp.ssp_2006_q4 where calledinfo='799992515f'
    OR
    select calledinfo from ssp.ssp_2006_q4 where calledinfo='799992515f'
    I don't know why it is not using the bitmap index: Can anybody help me here?
    Thanks in Advance
    Hashim

    I know why and everyone that has read Jonathan Lewis' book on the CBO knows why.
    Why? Because the CBO thinks the cost of using your index will be higher than the cost of ignoring it.
    To see what Oracle is thinking run an explain plan using DBMS_XPLAN for create the output and then rerun it with a hint forcing index usage.
    It is a mistake to believe that an index will always make things better. Issues of cardinality, clustering factor, etc. are very important.
    Post the explain plans if you have any questions about what they show:
    http://www.psoug.org/reference/explain_plan.html

  • Inline views / view merge slowing the query

    I have a tool generated query. This query uses inline views. The individual view return data under a second but final query is taking 10min +. any suggestion.
    I tried /*+ NO_MERGE(D1,D2,D3,D4)*/ but to no help.
    TIA.
    SELECT /*+ NO_MERGE(D1,D2,D3,D4)*/DISTINCT d4.c5 AS c1, d2.c14 AS c2,
    d3.c8 AS c3, d2.c8 AS c4,
    d2.c9 AS c5, d2.c10 AS c6,
    d2.c11 AS c7, d2.c12 AS c8,
    d2.c13 AS c9
    FROM (vv_d1) d1,
    (vv_d2) d2,
    (vv_d3) d3,
    (vv_d4) d4
    WHERE ( NVL (d1.c1, 'q') =
    NVL (d2.c14, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d2.c14, 'z')
    AND NVL (d1.c3, 'q') =
    NVL (d2.c12, 'q')
    AND NVL (d1.c3, 'z') =
    NVL (d2.c12, 'z')
    AND NVL (d1.c6, 'q') =
    NVL (d2.c9, 'q')
    AND NVL (d1.c6, 'z') =
    NVL (d2.c9, 'z')
    AND NVL (d1.c4, 'q') =
    NVL (d2.c10, 'q')
    AND NVL (d1.c4, 'z') =
    NVL (d2.c10, 'z')
    AND NVL (d1.c5, 8) =
    NVL (d2.c13, 8)
    AND NVL (d1.c5, 9) =
    NVL (d2.c13, 9)
    AND NVL (d1.c1, 'q') =
    NVL (d4.c6, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d4.c6, 'z')
    AND NVL (d1.c1, 'q') =
    NVL (d3.c11, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d3.c11, 'z')
    AND NVL (d1.c2, 88.0) =
    NVL (d3.c9, 88.0)
    AND NVL (d1.c2, 99.0) =
    NVL (d3.c9, 99.0)
    AND NVL (d1.c3, 'q') =
    NVL (d3.c10, 'q')
    AND NVL (d1.c3, 'z') =
    NVL (d3.c10, 'z')
    AND NVL (d1.c7, 'q') =
    NVL (d2.c11, 'q')
    AND NVL (d1.c7, 'z') =
    NVL (d2.c11, 'z')
    )

    And the Oracle version number, to three decimal places is?
    Post EXPLAIN PLAN output created using dbms_xplan
    http://www.psoug.org/reference/explain_plan.html

  • How cluster will tune the query

    Hi All,
    Please help me in understanding the autotrace Regarding Clusters.
    I created 2 tables
    tbl_master (col1 number, col2 number) with 800 rows AND unique col1.
    and tbl_detail(col1 number, col2 number) with 80000 with repeated col1.
    Now I created the replica of both tables with cluster on col1. as
    tbl_master1 (col1 number, col2 number) with 800 rows AND unique col1. --selected from tbl_master
    and tbl_detail1(col1 number, col2 number) with 80000 with repeated col1.--selected from tbl_detail
    I traced the out put of the non cluster table joins ans clustered tables joins.
    I set autotrace trace
    and set timing on
    I found that time elapsed is almost same even when COST is less. could anybody pls explain.
    select a.* from tbl_master a, tbl_detail b where a.col1 =b.col1
    80000 rows selected.
    Elapsed: 00:00:00.67
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=98 Card=80000 Byte
    s=1040000)
    1 0 HASH JOIN (Cost=98 Card=80000 Bytes=1040000)
    2 1 TABLE ACCESS (FULL) OF 'TBL_MASTER' (TABLE) (Cost=55 Car
    d=800 Bytes=8000)
    3 1 TABLE ACCESS (FULL) OF 'TBL_DETAIL' (TABLE) (Cost=42 Car
    d=80000 Bytes=240000)
    Statistics
    0 recursive calls
    0 db block gets
    5724 consistent gets
    0 physical reads
    0 redo size
    1066812 bytes sent via SQL*Net to client
    59175 bytes received via SQL*Net from client
    5335 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    80000 rows processed
    select a.* from tbl_master1 a, tbl_detail1 b where a.col1 =b.col1
    80000 rows selected.
    Elapsed: 00:00:00.65
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=980 Card=72000 Byt
    es=1656000)
    1 0 NESTED LOOPS (Cost=980 Card=72000 Bytes=1656000)
    2 1 TABLE ACCESS (FULL) OF 'TBL_MASTER1' (CLUSTER) (Cost=180
    Card=800 Bytes=8000)
    3 1 TABLE ACCESS (CLUSTER) OF 'TBL_DETAIL1' (CLUSTER) (Cost=
    1 Card=90 Bytes=1170)
    Statistics
    0 recursive calls
    0 db block gets
    7749 consistent gets
    0 physical reads
    0 redo size
    1065475 bytes sent via SQL*Net to client
    59175 bytes received via SQL*Net from client
    5335 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    80000 rows processed

    There is a lot of information missing from your question.
    1. What version of Oracle?
    2. Cluster by what? Index or hash? The DDL would have helped.
    and if hash was the number of has buckets determined correctly?
    3. Did you use DBMS_STATS to gather relevant optimizer statistics?
    4. What you posted is not an explain plan. In the future use dbms_xplan.display
    http://www.psoug.org/reference/explain_plan.html
    as demonstrated at the above link
    All of that said ... explain plan says nothing about how long a query takes. The cost is a measure of disk i/o and, if done properly, CPU, based on Oracle's assumption of what it might do if it actually ran the query. It might do what EXPLAIN PLAN indicates and it might not.
    Run a real explain plan and it might help understand what is happening but, quite frankly, with such a small number of rows the timing difference might be invisible.

  • Query Processing

    Hi,
    For large queries which DB parameter need to be increased.
    SGA or PGA (currently 24M)
    In SGA Shared pool is 150M, Java Pool 150M, Buffer Cache 256M, Large Pool 24M.
    Which parameter in SGA need to be tuned to faster performance of the query.

    Are you sure that the query EXECUTION PLAN is the same on both instances?
    try EXPLAIN_PLAN for query on both instances and compare them...

  • Tunned query going back slow

    A query after analyzing tables was running in 2 seconds, but once another query is run, it again goes back to 28 seconds. So, I think, its parsing the query that is taking lot of time. How do we handle this situation?

    I think your analysis of the situation is in error.
    I also think we have wholly insufficient information to help you further.
    1. What hardware, operating system, and storage?
    2. What version of what product (all three decimal places not just the marketing name)
    3. DDL for table and indexes
    4. DML for the statement
    5. Explain plan report generated using dbms_xplan.display
    http://www.morganslibrary.org/reference/explain_plan.html
    http://www.morganslibrary.org/library.html
    Tuning is not something that can be done in a vacuum.

  • Error while running a query-Input for variable 'Posting Period is invalid

    Hi All,
    NOTE: This error is only cropping up when I input 12 in the posting period variable selection. If I put in any other value from 1-11 I am not getting any errors. Any ideas why this might be happening?
    I am getting the following error when I try and run a query - "Input for variable 'Posting Period (Single entry, mandatory)' is invalid" - On further clicking on this error the message displayed is as follows -
    Diagnosis
    Variable Posting Period (Single Value Entry, Mandatory) is used as a lower limit (X) and an upper limit () in an interval selection. This limit has the value #.
    System Response
    Procedure
    Enter a different value for variable Posting Period (Single Value Entry, Mandatory). If the value of the other limit is determined by another variable, you can change its value also.
    Procedure for System Administration

    OK.
    Well, if the variable is not used in any interval selection, then I would say "something happened to it".
    I would make a copy of the query and run it to check if I get the same problem with period 12.
       -> If not, something is wrong in the original query (you can proceed as below, if changes to original are permitted).
    If so, then try removing the variable completely from the query and hardcode restriction to 12.
       -> If problem still persists, I would have to do some thinking.
    If problem is gone, then add the variable again. Check.
       -> If problem is back, then the variable "is sick". Only quick thing to do, is to build an identical variable and use that one.
    If problem also happens with the new variable, then it's time to share this experience with someone else and consider raising an OSS.
    Good luck!
    Jacob
    P.S: what fisc year variant are you using?
    Edited by: Jacob Jansen on Jan 25, 2010 8:36 PM

  • Logical database in adhoc query

    Hello All,
    Can anyone tell me what is the logical database in adhoc query?

    Hi
    When you create a query , you have to select an infoset. Infoset can be considered as a source from which data is populated in the Query Fields.
    Infosets are created from Transaction SQ02.
    There can be four methods through which an Infoset can become a source of data:
    1.  Table join ( By joining two or more tables from Data dictionary)
         example: Joining tables PA0001 and PA0006 on Pernr to get a one resultant dataset
    2. Direct read of Basis Table ( Like PA0001 as a source for data in Infoset )
    3. Logical Database ( A Pre-written Program by SAP that extract data from clusters, tables taking care of authorizations and validity periods)
    Example : Logical database PNP, PNPCE (Concurrent Employement),PCH ( LDB for Personnel Development Data)
    Custom Logical DBs can be created in T_Code SE-36.
    4. Data Retrieval by a Program ( Custom code written by ABAP developers which will collect and process data) . This program has a corresponding Structure in data dictionary and the fields of this structure will be used in query)
    Reward Points, if helpful.
    Regards
    Waseem Imran

  • Query help on Goods Receipt Query with AP Invoice

    Looking for a little help on a query.  I would like to list all the goods receipts for a given date range and then display the AP Invoice information (if its been copied to an AP Invoice).  I think my problem is in my where clause, I plagerized an SAP query to show GR and AP from a PO as a start.  SBO 2005 SP01.  Any help would be great appreciated.  Thanks
    SELECT distinct 'GR',
    D0.DocStatus,
    D0.DocNum ,
    D0.DocDate,
    D0.DocDueDate,
    D0.DocTotal,
    'AP',
    I0.DocStatus,
    I0.DocNum ,
    I0.DocDate,
    I0.DocDueDate,
    I0.DocTotal,
    I0.PaidToDate
    FROM
    ((OPDN  D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry)
    full outer join
    (OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry)
    on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
    WHERE
    (D1.BaseType=22 AND D1.DocDate>='[%0]' AND D1.DocDate<='[%1]')
    OR (I1.BaseType=20 AND I1.BaseEntry IN
    (SELECT Distinct DocEntry
    FROM PDN1 WHERE BaseType=22 AND DocDate>='[%0]' AND DocDate<='[%1]'))

    Hi Dalen ,
    I  believe it is because of the condition
    (D1.BaseType=22 AND D1.DocDate>='%0' AND D1.DocDate<='%1')
    OR (I1.BaseType=20 AND I1.BaseEntry IN
    (SELECT Distinct DocEntry FROM PDN1 WHERE PDN1.BaseType=22 AND DocDate>='%0' AND DocDate<='%1'))
    Try changing
    D1.BaseType=22 OR D1.DocDate>='%0' AND D1.DocDate<='%1
    PDN1.BaseType=22 OR DocDate>='%0' AND DocDate<='%1'))
    Lets see what would be the result . Lets have some fun with troubleshooting
    See what would be the difference in the result .
    Thank you
    Bishal

  • Can you check for data in one table or another but not both in one query?

    I have a situation where I need to link two tables together but the data may be in another (archive) table or different records are in both but I want the latest record from either table:
    ACCOUNT
    AccountID     Name   
    123               John Doe
    124               Jane Donaldson           
    125               Harold Douglas    
    MARKETER_ACCOUNT
    Key     AccountID     Marketer    StartDate     EndDate
    1001     123               10526          8/3/2008     9/27/2009
    1017     123               10987          9/28/2009     12/31/4712    (high date ~ which means currently with this marketer)
    1023     124               10541          12/03/2010     12/31/4712
    ARCHIVE
    Key     AccountID     Marketer    StartDate     EndDate
    1015     124               10526          8/3/2008     12/02/2010
    1033     125               10987         01/01/2011     01/31/2012  
    So my query needs to return the following:
    123     John Doe                        10526     8/3/2008     9/27/2009
    124     Jane Donaldson             10541     12/03/2010     12/31/4712     (this is the later of the two records for this account between archive and marketer_account tables)
    125     Harold Douglas               10987          01/01/2011     01/31/2012     (he is only in archive, so get this record)
    I'm unsure how to proceed in one query.  Note that I am reading in possibly multiple accounts at a time and returning a collection back to .net
    open CURSOR_ACCT
              select AccountID
              from
                     ACCOUNT A,
                     MARKETER_ACCOUNT M,
                     ARCHIVE R
               where A.AccountID = nvl((select max(M.EndDate) from Marketer_account M2
                                                    where M2.AccountID = A.AccountID),
                                                      (select max(R.EndDate) from Archive R2
                                                    where R2.AccountID = A.AccountID)
                   and upper(A.Name) like parameter || '%'
    <can you do a NVL like this?   probably not...   I want to be able to get the MAX record for that account off the MarketerACcount table OR the max record for that account off the Archive table, but not both>
    (parameter could be "DO", so I return all names starting with DO...)

    if I understand your description I would assume that for John Dow we would expect the second row from marketer_account  ("high date ~ which means currently with this marketer"). Here is a solution with analytic functions:
    drop table account;
    drop table marketer_account;
    drop table marketer_account_archive;
    create table account (
        id number
      , name varchar2(20)
    insert into account values (123, 'John Doe');
    insert into account values (124, 'Jane Donaldson');
    insert into account values (125, 'Harold Douglas');
    create table marketer_account (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account values (1001, 123, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('27.09.2009', 'dd.mm.yyyy'));
    insert into marketer_account values (1017, 123, 10987, to_date('28.09.2009', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    insert into marketer_account values (1023, 124, 10541, to_date('03.12.2010', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    create table marketer_account_archive (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account_archive values (1015, 124, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('02.12.2010', 'dd.mm.yyyy'));
    insert into marketer_account_archive values (1033, 125, 10987, to_date('01.01.2011', 'dd.mm.yyyy'), to_date('31.01.2012', 'dd.mm.yyyy'));
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account_archive;
    with
    basedata as (
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account_archive
    basedata_with_max_intervals as (
    select key, AccountId, MktKey, FromDt, ToDate
         , row_number() over(partition by AccountId order by FromDt desc) FromDt_Rank
      from basedata
    filtered_basedata as (
    select key, AccountId, MktKey, FromDt, ToDate from basedata_with_max_intervals where FromDt_Rank = 1
    select a.id
         , a.name
         , b.MktKey
         , b.FromDt
         , b.ToDate
      from account a
      join filtered_basedata b
        on (a.id = b.AccountId)
    ID NAME                     MKTKEY FROMDT     TODATE
    123 John Doe                  10987 28.09.2009 31.12.4712
    124 Jane Donaldson            10541 03.12.2010 31.12.4712
    125 Harold Douglas            10987 01.01.2011 31.01.2012
    If your tables are big it could be necessary to do the filtering (according to your condition) in an early step (the first CTE).
    Regards
    Martin

  • Query help : Query to get values SYSDATE-1 18:00 hrs to SYSDATE 08:00 hrs

    Hi Team
    I want the SQl query to get the data for the following comparison : -
    Order Created is a Date Column , and i want to find out all the values from (SYSDATE-1) 18:00 hours to SYSDATE 08:00 hours
    i.e.
    (SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 08:00:00.
    Regards

    Hi, Rohit,
    942281 wrote:
    If i want the data in the below way i.e.
    from (SYSDATE-1) 18:00 hours to SYSDATE 17:59 hours ---> (SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 07:59:00.If you want to include rows from exactly 18:00:00 yesterday (but no earlier), and exclude rows from exatly 08:00:00 today (or later), then use:
    WHERE   ord_dtl.submit_dt  >= TRUNC (SYSDATE) - (6 / 24)
    AND     ord_dtl.submit_dt  <  TRUNC (SYSDATE) + (8 / 24)
    So can i use the below format : -
    ord_dtl.submit_dt BETWEEN trunc(sysdate)-(6/24) and trunc(sysdate)+(7.59/24) . Please suggest . .59 hours is .59 * 60 * 60 = 2124 seconds (or .59 * 60 = 35.4 minutes), so the last time included in the range above is 07:35:24, not 07:59:59.
    If you really, really want to use BETWEEN (which includes both end points), then you could do it with date arithmentic:
    WHERE   ord_dtl.submit_dt  BETWEEN  TRUNC (SYSDATE) - (6 / 24)
                      AND         TRUNC (SYSDATE) + (8 / 24)
                                               - (1 / (24 * 60 * 60))but it would be simpler and less error prone to use INTERVALs, as Karthick suggested earlier:
    WHERE   ord_dtl.submit_dt  BETWEEN  TRUNC (SYSDATE) - INTERVAL '6' HOUR
                      AND         TRUNC (SYSDATE) + INTERVAL '8' HOUR
                                               - INTERVAL '1' SECONDEdited by: Frank Kulash on Apr 17, 2013 9:36 AM
    Edited by: Frank Kulash on Apr 17, 2013 11:56 AM
    Changed "- (8 /24)" to "+ (8 /24)" in first code fragment (after Blushadown, below)

Maybe you are looking for