SQL Tuning- slow query on GL_BALANCES- Explain plan provided

Hi- I really need some help here.
The following SQL statement has been identified to perform poorly.
It currently takes from 2-3 minutes to execute. I see it is because GL_BALANCES has so many rows.
Is there any way around this? Explain and info below. Thanks gurus!
This is the SQL statement:
SELECT DISTINCT GLB.CODE_COMBINATION_ID CCID
FROM gl_balances GLB, gl_code_combinations GCC
WHERE GLB.ACTUAL_FLAG = 'A'
AND GLB.Last_Update_Date > to_date('11-JAN-2010','DD-MON-YYYY')
AND GLB.code_combination_id = GCC.code_combination_id
AND EXISTS (
              SELECT 1
              FROM fnd_flex_value_sets A, fnd_flex_values B
              WHERE A.flex_value_set_name = 'XXX_XXX'
              AND UPPER(B.ATTRIBUTE3) = 'APPORTIONMENT'
              AND A.flex_value_set_id = b.flex_value_set_id
              AND GCC.segment11 = b.flex_value
           );The version of the database is 11.1.0.7.
These are the parameters relevant to the optimizer:
NAME TYPE VALUE
optimizerautostats_job boolean FALSE
optimizerextended_cursor_sharing_r string NONE
el
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.1.0.7
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean FALSE
optimizer_use_invisible_indexes boolean FALSE
NAME TYPE VALUE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 128
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL> show parameter cursor_sharing
NAME TYPE VALUE
optimizerextended_cursor_sharing_r string NONE
el
cursor_sharing string EXACT
select
2 sname
3 , pname
4 , pval1
5 , pval2
6 from
7 sys.aux_stats$;
SNAME PNAME PVAL1
PVAL2
SYSSTATS_INFO STATUS
COMPLETED
SYSSTATS_INFO DSTART
09-02-2006 14:35
SYSSTATS_INFO DSTOP
09-02-2006 14:35
SNAME PNAME PVAL1
PVAL2
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 451.262136
SYSSTATS_MAIN IOSEEKTIM 10
SNAME PNAME PVAL1
PVAL2
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SNAME PNAME PVAL1
PVAL2
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SNAME PNAME PVAL1
PVAL2
SYSSTATS_MAIN SLAVETHR
13 rows selected.
SQL> explain plan for
2 SELECT DISTINCT GLB.CODE_COMBINATION_ID CCID
3 FROM gl_balances GLB, gl_code_combinations GCC
4 WHERE GLB.code_combination_id = GCC.code_combination_id
5 AND GLB.ACTUAL_FLAG = 'A'
6 AND GLB.Last_Update_Date > '11-JAN-2010'
7 AND EXISTS (SELECT 1
8 FROM fnd_flex_value_sets A, fnd_flex_values B
9 WHERE A.flex_value_set_id = b.flex_value_set_id
10 AND A.flex_value_set_name = 'XXX_XXX'
11 AND UPPER(B.ATTRIBUTE3) = 'APPORTIONMENT'
12 AND GCC.segment11 = b.flex_value);
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 1839014065
| Id | Operation | Name | Rows | By
tes | Cost (%CPU)| Time |
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 4102 |
296K| 955K (3)| 03:11:03 |
| 1 | HASH UNIQUE | | 4102 |
296K| 955K (3)| 03:11:03 |
|* 2 | HASH JOIN | | 4102 |
296K| 955K (3)| 03:11:03 |
| 3 | NESTED LOOPS | | |
| | |
PLAN_TABLE_OUTPUT
| 4 | NESTED LOOPS | | 23907 | 1
354K| 2598 (1)| 00:00:32 |
| 5 | NESTED LOOPS | | 1 |
45 | 5 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID| FND_FLEX_VALUE_SETS | 1 |
28 | 2 (0)| 00:00:01 |
|* 7 | INDEX UNIQUE SCAN | FND_FLEX_VALUE_SETS_U2 | 1 |
PLAN_TABLE_OUTPUT
| 1 (0)| 00:00:01 |
|* 8 | TABLE ACCESS BY INDEX ROWID| FND_FLEX_VALUES | 1 |
17 | 3 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | FND_FLEX_VALUES_N2 | 53 |
| 1 (0)| 00:00:01 |
|* 10 | INDEX RANGE SCAN | GL_CODE_COMBINATIONS_N11 | 25427 |
| 106 (1)| 00:00:02 |
PLAN_TABLE_OUTPUT
| 11 | TABLE ACCESS BY INDEX ROWID | GL_CODE_COMBINATIONS | 18664 |
236K| 2593 (1)| 00:00:32 |
|* 12 | TABLE ACCESS FULL | GL_BALANCES | 1022K|
15M| 952K (3)| 03:10:32 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
2 - access("GLB"."CODE_COMBINATION_ID"="GCC"."CODE_COMBINATION_ID")
7 - access("A"."FLEX_VALUE_SET_NAME"='SSA_SGL')
8 - filter(UPPER("B"."ATTRIBUTE3")='APPORTIONMENT')
9 - access("A"."FLEX_VALUE_SET_ID"="B"."FLEX_VALUE_SET_ID")
10 - access("GCC"."SEGMENT11"="B"."FLEX_VALUE")
12 - filter("GLB"."LAST_UPDATE_DATE">TO_DATE(' 2010-01-11 00:00:00', 'syyyy-mm
-dd hh24:mi:ss') AND
"GLB"."ACTUAL_FLAG"='A')
30 rows selected.

As per the other replies, you've not really given enough information to go on - what are you trying to achieve, versions, etc.
On my old apps 11.5.8 system, the explain plan for your query uses GL_CODE_COMBINATIONS_U1 rather than a full scan of gl_code_combinations.
Check your stats are up to date (select table_name, num_rows, last_analyzed from dba_tables where ...)
See if you can also use period_name and/or period_set_name (or period_num) from GL_Periods rather than period_year (i.e. use P_YEAR to lookup the period_name/period_set_name/period_num from gl_periods). It might be faster to do per period and then consolidate for the whole year, as there are indexes on gl_balances for columns period_name, period_set_name, period_num.
regards, Ivan

Similar Messages

  • Same query with different explain plans

    Hi All,
    I have one of the select query with different explain plans on two separate env, the query fetches the correct index on test env whereas on prod it's not fetching the same index.
    The structure, indices, no. of rows are similar in CRMINFO table with up-to-date statistics.
    Env Details :
    OS - Sun Solaris 5.10
    DB - 10.2.0.4
    Init param:
    Optimizer_mode = ALL_ROWS
    optimizer_dynamic_sampling integer 5
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 90
    optimizer_index_cost_adj integer 30
    Query :*
    SELECT COUNT (*)
    FROM CRMINFO
    WHERE RETAILER = :1
    AND STATUS = 20
    AND EXC = :1
    AND SUBNO IS NULL
    Expain Plan (TST):
    SELECT STATEMENT ALL_ROWSCost: 916 Bytes: 19 Cardinality: 1                
    3 SORT AGGREGATE Bytes: 19 Cardinality: 1           
    2 TABLE ACCESS BY INDEX ROWID TABLE TST.CRMINFO Cost: 916 Bytes: 16,663 Cardinality: 877      
    1 INDEX RANGE SCAN INDEX TST.CRMINFO_X1 Cost: 42 Cardinality: 12,549
    Index (TST):
    CRMINFO_X1(EXC, RETAILER, STATUS)
    Explain Plan (PROD):
    SELECT STATEMENT ALL_ROWSCost: 1,832 Bytes: 19 Cardinality: 1                
    3 SORT AGGREGATE Bytes: 19 Cardinality: 1           
    2 TABLE ACCESS BY INDEX ROWID TABLE PROD.CRMINFO Cost: 1,832 Bytes: 2,052 Cardinality: 108      
    1 INDEX RANGE SCAN INDEX PROD.CRMINFO_X2 Cost: 117 Cardinality: 42,519
    Index (PROD):
    CRMINFO_X2 (RETAILER)
    How does Oracle calculates the cost and decides which index it should fetch ? Why it didn't choose the same index as of test env? How should i approach and which domains i need to dig-in to find the cause?
    I did try playing with the above mentioned init parameters but it didn't help at all.
    Thanks.
    Regards,
    ~Pointer

    Pointer wrote:
    Hmm, my worry is how do i force oracle to grap the proper index on prod i.e (CRMINFO_X1). I certainly believe it's a bad approach on adding a hint in the select statement and to force oralce to fetch that index.Why do you believe that, the index you mention is the "proper" index versus what Oracle is choosing? Can you prove with hinting that the "proper" index results in a faster and more efficient execution plan? If it does, then the next place I would look at is the statistics for the tables and columns of interest. From here you could try and estimate why Oracle thinks the other index is better. Another option is to run a 10053 (CBO) trace and see why Oracle thinks it is better.
    I would not support a hint in a production environment, except in the most extreme cases. Usually the CBO makes the right choice, but it only can if the statistics match the distribution of data.
    Refreshing the data may help me simulating the issue on TST but it wouldn't help me to understand why on prod it uses CRMINFO_X2 instead of CRMINFO_X1 which has all the three columns in the Where clause of the query.It would help because it's a test environment and you wouldn't have to do any queries directly on your production system to achieve the same results.
    >
    A bad thought here :( , if i create a new index by changing the column positioning say like ( RETAILER, STATUS , EXC) instead of (EXC, RETAILER, STATUS) will oracle fetch it ? or would it help in reducing the cost and cardinatlity of the select query.It's not that easy. There is a lot that goes into the cost calculation, some of that is known (through the great work by Jonathan Lewis and Richard Foote), and some of that is purely internal to Oracle. If you are more interested in the internals Cost-Based Oracle Fundamentals by Jonathan Lewis is a great book.
    HTH!

  • TUNNING A SQL QUERY AND UNSERSTAND EXPLAIN PLAN

    I was trying my handing in tunning sql queries -
    Though I have manged to reduce the cost lil ..creating some index, but have genarated a g8 interesting in tunning - Can some experts ( I know there are lots available :-) ) help me on the approch on "HOW TO TUNE A QUERY"
    moreover I also would like to understand - how to debug a explain plan, - please help ...
    Regards..

    Hi,
    Welcome to this forum...
    I would suggest your to read first the official documentations :
    - The concepts of an Oracle DBMS (this is important to know, because Oracle structures, processes, objects (etc) are the building blocks of your database)
    - SQL reference guide
    - PL/SQL reference guide
    and then at a later stage the Performance and tuning guide:
    You can start there:
    http://download.oracle.com/docs/cd/B14117_01/nav/portal_1.htm
    Once it's done maybe read the Performance and tuning guide:
    http://download.oracle.com/docs/cd/B14117_01/server.101/b10752/toc.htm
    (Chapter 19 explain ... how to interpret the explain plan ..)
    I wish you good chance and be patient: I'm working with Oracle for more that 10 years and I'm still learning! ...
    Rem: The Oracle website is full of interesting articles, and examples, just "search" your special points of interests ..

  • Query with same explain-plan but slower in one env

    Hi there
    I have a stored procedure which is executed from a web application. It contains a query (insert-select-from statement). When this stored procedure is called by the web application in PROD, it takes 13sec but it takes 19sec in TEST env. I checked the explain plan for this insert statement in both instances and it is same (see below). Actually, the cost is lower in TEST env.
    ENV: Oracle 10gR2 EE, on ASM - RHEL 64bit
    The TEST server is on a better/faster hardware and will become the new PROD in near future (faster and 16 CPUs  vs 8 in PROD, high performance SAN, 132GB RAM vs 96GB in PROD, etc). The TEST database has exact same init parameter and version/patch level as current PROD. So the application is being tested against it at the moment.
    Here are the explain-plans from both environments:
    From PROD Server
    Plan
    INSERT STATEMENT ALL_ROWS Cost: 143 Bytes: 696 Cardinality: 3
    18 SORT ORDER BY Cost: 143 Bytes: 696 Cardinality: 3
    17 HASH UNIQUE Cost: 142 Bytes: 696 Cardinality: 3
    16 WINDOW SORT Cost: 143 Bytes: 696 Cardinality: 3
    15 HASH JOIN Cost: 141 Bytes: 696 Cardinality: 3
    13 HASH JOIN Cost: 128 Bytes: 519 Cardinality: 3
    11 TABLE ACCESS BY INDEX ROWID TABLE MKTG.SATDATAIMPORT Cost: 125 Bytes: 1,728 Cardinality: 12
    10 NESTED LOOPS Cost: 125 Bytes: 1,992 Cardinality: 12
    3 HASH JOIN Cost: 5 Bytes: 22 Cardinality: 1
    1 TABLE ACCESS FULL TABLE MKTG.TMPG_CLICKS_HDGS Cost: 2 Bytes: 12 Cardinality: 1
    2 TABLE ACCESS FULL TABLE MKTG.TMPG_CLICKS_DIRS Cost: 2 Bytes: 10 Cardinality: 1
    9 BITMAP CONVERSION TO ROWIDS
    8 BITMAP AND
    5 BITMAP CONVERSION FROM ROWIDS
    4 INDEX RANGE SCAN INDEX MKTG.SATDATAIMPORT_HEADINGNO Cost: 19 Cardinality: 4,920
    7 BITMAP CONVERSION FROM ROWIDS
    6 INDEX RANGE SCAN INDEX MKTG.SATDATAIMPORT_DIRNO Cost: 89 Cardinality: 4,920
    12 TABLE ACCESS FULL TABLE MKTG.MONTHS12 Cost: 2 Bytes: 84 Cardinality: 12
    14 TABLE ACCESS FULL TABLE MKTG.REF_WEST_CATEGORY Cost: 12 Bytes: 191,809 Cardinality: 3,251
    From TEST Server
    Plan
    INSERT STATEMENT ALL_ROWS Cost: 107 Bytes: 232 Cardinality: 1
    18 SORT ORDER BY Cost: 107 Bytes: 232 Cardinality: 1
    17 HASH UNIQUE Cost: 106 Bytes: 232 Cardinality: 1
    16 WINDOW SORT Cost: 107 Bytes: 232 Cardinality: 1
    15 HASH JOIN Cost: 105 Bytes: 232 Cardinality: 1
    13 HASH JOIN Cost: 93 Bytes: 173 Cardinality: 1
    11 TABLE ACCESS BY INDEX ROWID TABLE MKTG.SATDATAIMPORT Cost: 89 Bytes: 864 Cardinality: 6
    10 NESTED LOOPS Cost: 89 Bytes: 996 Cardinality: 6
    3 HASH JOIN Cost: 7 Bytes: 22 Cardinality: 1
    1 TABLE ACCESS FULL TABLE MKTG.TMPG_CLICKS_HDGS Cost: 3 Bytes: 12 Cardinality: 1
    2 TABLE ACCESS FULL TABLE MKTG.TMPG_CLICKS_DIRS Cost: 3 Bytes: 10 Cardinality: 1
    9 BITMAP CONVERSION TO ROWIDS
    8 BITMAP AND
    5 BITMAP CONVERSION FROM ROWIDS
    4 INDEX RANGE SCAN INDEX MKTG.SATDATAIMPORT_HEADINGNO Cost: 9 Cardinality: 2,977
    7 BITMAP CONVERSION FROM ROWIDS
    6 INDEX RANGE SCAN INDEX MKTG.SATDATAIMPORT_DIRNO Cost: 59 Cardinality: 2,977
    12 TABLE ACCESS FULL TABLE MKTG.MONTHS12 Cost: 3 Bytes: 84 Cardinality: 12
    14 TABLE ACCESS FULL TABLE MKTG.REF_WEST_CATEGORY Cost: 12 Bytes: 191,868 Cardinality: 3,252
    What else can I check to find out why the query is slower in TEST env?
    Please advise.
    Best regards

    Here is some more info. The query is below:
    select distinct dr.line_num 
                     ,row_number() over (partition by di.HEADINGNO,di.DIRECTORYNO order by reportyear,to_number(di.monthno)) monthposition
                     ,di.SATID,di.REPORTYEAR,di.MONTHNO,di.MONTHEN,di.MONTHFR,di.HEADINGNO,hn.NAME_EN,hn.NAME_FR,di.DIRECTORYNO
                     ,di.SUPERDIRECTORYNO,di.PRINTDIRCODE,di.DIRECTORYNAME,round(to_number(di.IMPTTOTAL)) imptotal
                     ,round(to_number(di.IMPBEST)) impbest ,round(to_number(di.IMPTAVERAGE)) imptaverage
                     ,round(to_number(di.CLICKTOTAL)) clicktotal,round(to_number(di.CLICKBEST)) clickbest
                     ,round(to_number(di.CLICKAVERAGE)) clickaverage
                     ,round(avg(to_number(impttotal)) over(partition by di.HEADINGNO,di.DIRECTORYNO)) avgimp
               from satdataimport di,tmpg_clicks_hdgs hd,tmpg_clicks_dirs dr, months12 m12, ref_west_category hn
               where di.headingno   = hd.id
                 and di.directoryno = dr.id
                 and dr.line_num=hd.line_num
                 and di.reportyear  = m12.year
                 and di.monthno     = m12.month
                 and hn.CATEGORY_CODE = di.headingno
               order by di.headingno, di.directoryno,di.reportyear,to_number(di.monthno)
    The largest table is "satdataimport" in the query has "12274818" rows. Rest of the tables are very small containing few rows to less than 4000 rows.
    I have refreshed the statistics of the larger table but this did not help either. Even a simple query like "select count(*) from satdataimport" is taking 15sec in TEST while it takes 4Sec in PROD when I run it from TOAD.
    The other strange thing is that when I run this stored procedure from TOAD, it takes 200 milli sec to complete. There is a logging table to which the stored procedure records the elapsed time taken by this INSERT statement.
    Since this query is in a stored procedure being called from the web app, the QA team wants quicker response. Current PROD is faster.
    The tables have same indexes, etc and contain identical data as that in PROD (were refreshed from PROD yesterday).
    What else can I check?
    Best regards

  • Query with diff. explain plans

    Hi,
    Our query returns different execution plans in Prod and non-prod. It is slow in PROD. The data size is the same in both DBs and stats are gathered at 50% estimate for both schemas:
    Prod (slow) explain plan:
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 852 | 33 (4)| 00:00:01 |
    |* 1 | FILTER | | | | | |
    | 2 | HASH GROUP BY | | 1 | 852 | 33 (4)| 00:00:01 |
    | 3 | NESTED LOOPS | | 1 | 852 | 32 (0)| 00:00:01 |
    | 4 | NESTED LOOPS | | 1 | 802 | 31 (0)| 00:00:01 |
    | 5 | NESTED LOOPS OUTER | | 1 | 785 | 30 (0)| 00:00:01 |
    | 6 | NESTED LOOPS OUTER | | 1 | 742 | 29 (0)| 00:00:01 |
    | 7 | NESTED LOOPS | | 1 | 732 | 29 (0)| 00:00:01 |
    | 8 | NESTED LOOPS | | 1 | 678 | 26 (0)| 00:00:01 |
    | 9 | NESTED LOOPS | | 1 | 666 | 26 (0)| 00:00:01 |
    | 10 | NESTED LOOPS | | 1 | 623 | 25 (0)| 00:00:01 |
    | 11 | NESTED LOOPS | | 1 | 580 | 24 (0)| 00:00:01 |
    | 12 | NESTED LOOPS | | 1 | 576 | 24 (0)| 00:00:01 |
    | 13 | NESTED LOOPS | | 2 | 1076 | 13 (0)| 00:00:01 |
    | 14 | NESTED LOOPS | | 2 | 1040 | 13 (0)| 00:00:01 |
    | 15 | NESTED LOOPS | | 2 | 1028 | 13 (0)| 00:00:01 |
    | 16 | NESTED LOOPS | | 2 | 996 | 13 (0)| 00:00:01 |
    | 17 | NESTED LOOPS | | 2 | 988 | 13 (0)| 00:00:01 |
    | 18 | NESTED LOOPS | | 2 | 954 | 13 (0)| 00:00:01 |
    | 19 | NESTED LOOPS | | 2 | 944 | 13 (0)| 00:00:01 |
    | 20 | NESTED LOOPS | | 2 | 920 | 13 (0)| 00:00:01 |
    | 21 | NESTED LOOPS | | 2 | 912 | 13 (0)| 00:00:01 |
    | 22 | NESTED LOOPS | | 2 | 826 | 11 (0)| 00:00:01 |
    | 23 | NESTED LOOPS | | 1 | 370 | 9 (0)| 00:00:01 |
    | 24 | NESTED LOOPS | | 1 | 306 | 8 (0)| 00:00:01 |
    | 25 | NESTED LOOPS | | 1 | 263 | 7 (0)| 00:00:01 |
    | 26 | NESTED LOOPS | | 1 | 220 | 6 (0)| 00:00:01 |
    | 27 | NESTED LOOPS | | 1 | 177 | 5 (0)| 00:00:01 |
    | 28 | NESTED LOOPS | | 1 | 129 | 4 (0)| 00:00:01 |
    | 29 | NESTED LOOPS | | 1 | 86 | 3 (0)| 00:00:01 |
    | 30 | TABLE ACCESS BY INDEX ROWID| SYMMETADATA | 1 | 43 | 2 (0)| 00:00:01 |
    |* 31 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 1 (0)| 00:00:01 |
    | 32 | TABLE ACCESS BY INDEX ROWID| SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 33 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 34 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 35 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 36 | TABLE ACCESS BY INDEX ROWID | TPRODUCT | 1 | 48 | 1 (0)| 00:00:01 |
    |* 37 | INDEX UNIQUE SCAN | TPRODUCT_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 38 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 39 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 40 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 41 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 42 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 43 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 44 | TABLE ACCESS BY INDEX ROWID | TPRODUCT | 1 | 64 | 1 (0)| 00:00:01 |
    |* 45 | INDEX UNIQUE SCAN | TPRODUCT_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 46 | INLIST ITERATOR | | | | | |
    | 47 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 2 | 86 | 2 (0)| 00:00:01 |
    |* 48 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 2 | | 1 (0)| 00:00:01 |
    | 49 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 50 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    |* 51 | INDEX UNIQUE SCAN | SYMUSERCOUNT_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 52 | INDEX UNIQUE SCAN | SYMUSERCOUNT_PK | 1 | 12 | 0 (0)| 00:00:01 |
    |* 53 | INDEX UNIQUE SCAN | SYMSKUTYPE_PK | 1 | 5 | 0 (0)| 00:00:01 |
    |* 54 | INDEX UNIQUE SCAN | SYMSKUTYPE_PK | 1 | 17 | 0 (0)| 00:00:01 |
    |* 55 | INDEX UNIQUE SCAN | SYMSKULANGUAGE_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 56 | INDEX UNIQUE SCAN | SYMSKULANGUAGE_PK | 1 | 16 | 0 (0)| 00:00:01 |
    |* 57 | INDEX UNIQUE SCAN | SYMVENDOR_PK | 1 | 6 | 0 (0)| 00:00:01 |
    |* 58 | INDEX UNIQUE SCAN | SYMVENDOR_PK | 1 | 18 | 0 (0)| 00:00:01 |
    | 59 | TABLE ACCESS BY INDEX ROWID | SYMPRODUCTSKU | 1 | 38 | 6 (0)| 00:00:01 |
    |* 60 | INDEX RANGE SCAN | I_PSKU_MERCH_LOOKUP | 1 | | 5 (0)| 00:00:01 |
    |* 61 | INDEX UNIQUE SCAN | SYMMEDIATYPE_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 62 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 63 | INDEX UNIQUE SCAN | SYMMETADATA_PK | 1 | | 0 (0)| 00:00:01 |
    | 64 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 65 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    |* 66 | INDEX UNIQUE SCAN | SYMMEDIATYPE_PK | 1 | 12 | 0 (0)| 00:00:01 |
    | 67 | TABLE ACCESS BY INDEX ROWID | SYMPRODUCTSKU | 1 | 54 | 3 (0)| 00:00:01 |
    |* 68 | INDEX RANGE SCAN | I_PSKU_MERCH_LOOKUP | 1 | | 2 (0)| 00:00:01 |
    |* 69 | INDEX UNIQUE SCAN | SYMPCCOUNT_PK | 1 | 10 | 0 (0)| 00:00:01 |
    | 70 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 43 | 1 (0)| 00:00:01 |
    |* 71 | INDEX UNIQUE SCAN | SYMMETADATA_PK | 1 | | 0 (0)| 00:00:01 |
    |* 72 | TABLE ACCESS BY INDEX ROWID | TPRODUCTSKU | 1 | 17 | 1 (0)| 00:00:01 |
    |* 73 | INDEX UNIQUE SCAN | TPRODUCTSKU_PK | 1 | | 0 (0)| 00:00:01 |
    |* 74 | TABLE ACCESS BY INDEX ROWID | TPRODUCTSKU | 1 | 50 | 1 (0)| 00:00:01 |
    |* 75 | INDEX UNIQUE SCAN | TPRODUCTSKU_PK | 1 | | 0 (0)| 00:00:01 |
    Non Prod (Fast) Plan:
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 383 | 28 (0)| 00:00:01 |
    |* 1 | FILTER | | | | | |
    | 2 | NESTED LOOPS | | 1 | 383 | 17 (0)| 00:00:01 |
    | 3 | NESTED LOOPS OUTER | | 1 | 350 | 16 (0)| 00:00:01 |
    | 4 | NESTED LOOPS | | 1 | 308 | 15 (0)| 00:00:01 |
    | 5 | NESTED LOOPS | | 1 | 266 | 14 (0)| 00:00:01 |
    | 6 | NESTED LOOPS OUTER | | 1 | 262 | 14 (0)| 00:00:01 |
    | 7 | NESTED LOOPS | | 1 | 258 | 14 (0)| 00:00:01 |
    | 8 | NESTED LOOPS | | 2 | 438 | 7 (0)| 00:00:01 |
    | 9 | NESTED LOOPS | | 2 | 428 | 7 (0)| 00:00:01 |
    | 10 | NESTED LOOPS | | 2 | 420 | 7 (0)| 00:00:01 |
    | 11 | NESTED LOOPS | | 2 | 410 | 7 (0)| 00:00:01 |
    | 12 | NESTED LOOPS | | 2 | 402 | 7 (0)| 00:00:01 |
    | 13 | NESTED LOOPS | | 1 | 159 | 5 (0)| 00:00:01 |
    | 14 | NESTED LOOPS | | 1 | 126 | 4 (0)| 00:00:01 |
    | 15 | NESTED LOOPS | | 1 | 84 | 3 (0)| 00:00:01 |
    | 16 | TABLE ACCESS BY INDEX ROWID| SYMMETADATA | 1 | 42 | 2 (0)| 00:00:01 |
    |* 17 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 1 (0)| 00:00:01 |
    | 18 | TABLE ACCESS BY INDEX ROWID| SYMMETADATA | 1 | 42 | 1 (0)| 00:00:01 |
    |* 19 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 20 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 42 | 1 (0)| 00:00:01 |
    |* 21 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 22 | TABLE ACCESS BY INDEX ROWID | TPRODUCT | 1 | 33 | 1 (0)| 00:00:01 |
    |* 23 | INDEX UNIQUE SCAN | TPRODUCT_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 24 | INLIST ITERATOR | | | | | |
    | 25 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 2 | 84 | 2 (0)| 00:00:01 |
    |* 26 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 2 | | 1 (0)| 00:00:01 |
    |* 27 | INDEX UNIQUE SCAN | SYMUSERCOUNT_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 28 | INDEX UNIQUE SCAN | SYMSKUTYPE_PK | 1 | 5 | 0 (0)| 00:00:01 |
    |* 29 | INDEX UNIQUE SCAN | SYMSKULANGUAGE_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 30 | INDEX UNIQUE SCAN | SYMVENDOR_PK | 1 | 5 | 0 (0)| 00:00:01 |
    | 31 | TABLE ACCESS BY INDEX ROWID | SYMPRODUCTSKU | 1 | 39 | 4 (0)| 00:00:01 |
    |* 32 | INDEX RANGE SCAN | I_PSKU_MERCH_LOOKUP | 1 | | 3 (0)| 00:00:01 |
    |* 33 | INDEX UNIQUE SCAN | SYMPCCOUNT_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 34 | INDEX UNIQUE SCAN | SYMMEDIATYPE_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 35 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 42 | 1 (0)| 00:00:01 |
    |* 36 | INDEX UNIQUE SCAN | SYMMETADATA_PK | 1 | | 0 (0)| 00:00:01 |
    | 37 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 42 | 1 (0)| 00:00:01 |
    |* 38 | INDEX UNIQUE SCAN | SYMMETADATA_PK | 1 | | 0 (0)| 00:00:01 |
    |* 39 | TABLE ACCESS BY INDEX ROWID | TPRODUCTSKU | 1 | 33 | 1 (0)| 00:00:01 |
    |* 40 | INDEX UNIQUE SCAN | TPRODUCTSKU_PK | 1 | | 0 (0)| 00:00:01 |
    | 41 | SORT AGGREGATE | | 1 | 252 | | |
    | 42 | NESTED LOOPS | | 1 | 252 | 11 (0)| 00:00:01 |
    | 43 | NESTED LOOPS | | 1 | 240 | 10 (0)| 00:00:01 |
    | 44 | NESTED LOOPS | | 1 | 205 | 7 (0)| 00:00:01 |
    | 45 | NESTED LOOPS | | 1 | 200 | 7 (0)| 00:00:01 |
    | 46 | NESTED LOOPS | | 1 | 196 | 7 (0)| 00:00:01 |
    | 47 | NESTED LOOPS | | 1 | 191 | 7 (0)| 00:00:01 |
    | 48 | NESTED LOOPS | | 1 | 187 | 7 (0)| 00:00:01 |
    | 49 | NESTED LOOPS | | 1 | 183 | 7 (0)| 00:00:01 |
    | 50 | NESTED LOOPS | | 1 | 150 | 6 (0)| 00:00:01 |
    | 51 | NESTED LOOPS | | 1 | 120 | 5 (0)| 00:00:01 |
    | 52 | NESTED LOOPS | | 1 | 90 | 4 (0)| 00:00:01 |
    | 53 | NESTED LOOPS | | 1 | 60 | 3 (0)| 00:00:01 |
    | 54 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 30 | 2 (0)| 00:00:01 |
    |* 55 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 1 (0)| 00:00:01 |
    | 56 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 30 | 1 (0)| 00:00:01 |
    |* 57 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 58 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 30 | 1 (0)| 00:00:01 |
    |* 59 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 60 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 30 | 1 (0)| 00:00:01 |
    |* 61 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 62 | TABLE ACCESS BY INDEX ROWID | SYMMETADATA | 1 | 30 | 1 (0)| 00:00:01 |
    |* 63 | INDEX UNIQUE SCAN | SYMMETADATA_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    | 64 | TABLE ACCESS BY INDEX ROWID | TPRODUCT | 1 | 33 | 1 (0)| 00:00:01 |
    |* 65 | INDEX UNIQUE SCAN | TPRODUCT_UNIQUE | 1 | | 0 (0)| 00:00:01 |
    |* 66 | INDEX UNIQUE SCAN | SYMUSERCOUNT_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 67 | INDEX UNIQUE SCAN | SYMMEDIATYPE_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 68 | INDEX UNIQUE SCAN | SYMSKUTYPE_PK | 1 | 5 | 0 (0)| 00:00:01 |
    |* 69 | INDEX UNIQUE SCAN | SYMSKULANGUAGE_PK | 1 | 4 | 0 (0)| 00:00:01 |
    |* 70 | INDEX UNIQUE SCAN | SYMVENDOR_PK | 1 | 5 | 0 (0)| 00:00:01 |
    | 71 | TABLE ACCESS BY INDEX ROWID | SYMPRODUCTSKU | 1 | 35 | 3 (0)| 00:00:01 |
    |* 72 | INDEX RANGE SCAN | I_PSKU_MERCH_LOOKUP | 1 | | 2 (0)| 00:00:01 |
    |* 73 | TABLE ACCESS BY INDEX ROWID | TPRODUCTSKU | 1 | 12 | 1 (0)| 00:00:01 |
    |* 74 | INDEX UNIQUE SCAN | TPRODUCTSKU_PK | 1 | | 0 (0)| 00:00:01 |
    Database version is 10.2.0.4. Can anyone help me understand what else to be looking for to make it work faster?

    Please see the following threads for the ideal information required:
    How to post a sql tuning request:
    HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long:
    When your query takes too long ...

  • Query returns different Explain Plan

    Hi,
    I have two databases that are identical to each other. But I have a query that runs on both and returns different explain plans in both. It runs slower in one than other. How can I troubleshoot this further to get faster times in the slower database?
    THanks,
    Prachi

    Query:
    =====
    SELECT sum(total_contacts), sum(email_partner_news), sum(email_tech_news),
    sum(email_enduser_news), sum(email), sum(email_gmo), sum(gmo_nophone),
    sum(email_gmo_noaddress), sum(email_gmo_address), sum(
    email_gmo_nocertaddr), sum(email_gmo_certaddress), sum(
    email_gmo_nophone_noaddr), sum(phone_number), sum(gmo_with_phone),
    sum(phone_number_email_gmo_noaddr), sum(phone_number_email_gmo_nocert),
    sum(phone_number_address), sum(phone_number_address_noemail), sum(
    phone_address_email_nogmo), sum(phone_number_address_email), sum(
    phone_number_certaddr), sum(phone_number_certaddr_noemail), sum(
    phone_certaddr_email_nogmo), sum(phone_number_address_gmo), sum(
    phone_certaddr_email_gmo), sum(address), sum(
    address_nophone_number_nogmo), sum(address_certified), sum(
    certaddr_nophone_nogmo), sum(address_email_nophone_gmo), sum(
    certaddr_email_nophone_gmo), sum(phone_gmo), sum(smail_gmo), sum(fax_gmo
    ), sum(email_wcast), sum(email_inews), sum(email_salrt), sum(
    phone_gmo_phone), sum(smail_gmo_address), sum(fax_gmo_fax)
    FROM contact_values_vw_tc_2 cv, ((SELECT gcd_contact_id
    FROM contact_values)
    INTERSECT
    ((SELECT gcd_contact_id
    FROM gcddata.contact_country s, gcd.country c,
    segmentation_query_values v
    WHERE s.country_id = c.country_id
    AND c.region_id = v.query_value
    AND v.selection_type = 'I'
    AND v.query_id = 2088
    AND v.query_sequence = 1)
    INTERSECT
    (SELECT gcd_contact_id
    FROM gcddata.contact_country s, gcd.country c,
    segmentation_query_values v
    WHERE s.country_id = c.country_id
    AND c.sub_region_id = v.query_value
    AND v.selection_type = 'I'
    AND v.query_id = 2088
    AND v.query_sequence = 2)) ) sl
    WHERE cv.gcd_contact_id = sl.gcd_contact_id
    AND cv.country_id IN (SELECT cm.country_id
    FROM segmentation_user_country_map cm
    WHERE cm.user_name = 'E30590')
    ========================================
    Execution Plan - FAST
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=32931 Card=1 Bytes=73)
    1 0 SORT (AGGREGATE)
    2 1 HASH JOIN (Cost=32931 Card=386388 Bytes=28206324)
    3 2 VIEW (Cost=29617 Card=1142043 Bytes=14846559)
    4 3 INTERSECTION
    5 4 SORT (UNIQUE)
    6 5 INDEX (FAST FULL SCAN) OF 'CONTACT_VALUES1_PK' (UNIQUE) (Cost=5 Card=1907737 Bytes=11446422)
    7 4 INTERSECTION
    8 7 SORT (UNIQUE)
    9 8 HASH JOIN (Cost=655 Card=1998575 Bytes=57958675)
    10 9 HASH JOIN (Cost=6 Card=110 Bytes=2200)
    11 10 TABLE ACCESS (BY INDEX ROWID) OF 'SEGMENTATION_QUERY_VALUES' (Cost=3 Card=7 Bytes=91)
    12 11 INDEX (RANGE SCAN) OF 'SEG_QUERY_VALUES_ PK' (UNIQUE) (Cost=2 Card=15)
    13 10 TABLE ACCESS (FULL) OF 'COUNTRY' (Cost=2 Card=120 Bytes=840)
    14 9 TABLE ACCESS (FULL) OF 'CONTACT_COUNTRY1' (Cost=643 Card=2199855 Bytes=19798695)
    15 7 SORT (UNIQUE)
    16 15 HASH JOIN (Cost=655 Card=1142043 Bytes=33119247)
    17 16 HASH JOIN (Cost=6 Card=63 Bytes=1260)
    18 17 TABLE ACCESS (BY INDEX ROWID) OF 'SEGMENTATION_QUERY_VALUES' (Cost=3 Card=7 Bytes=91)
    19 18 INDEX (RANGE SCAN) OF 'SEG_QUERY_VALUES_PK' (UNIQUE) (Cost=2 Card=15)
    20 17 TABLE ACCESS (FULL) OF 'COUNTRY' (Cost=2 Card=120 Bytes=840)
    21 16 TABLE ACCESS (FULL) OF 'CONTACT_COUNTRY1' (Cost=643 Card=2199855 Bytes=19798695)
    22 2 HASH JOIN (Cost=2174 Card=645445 Bytes=38726700)
    23 22 SORT (UNIQUE)
    24 23 TABLE ACCESS (FULL) OF 'SEGMENTATION_USER_COUNTRY_MAP' (Cost=5 Card=43 Bytes=473)
    25 22 TABLE ACCESS (FULL) OF 'CONTACT_VALUES1' (Cost=2151 Card=1907737 Bytes=93479113)
    =====================================================
    Execution Plan -SLOW
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=8751 Card=1 Bytes=73 )
    1 0 SORT (AGGREGATE)
    2 1 HASH JOIN (SEMI) (Cost=8751 Card=14477 Bytes=1056821)
    3 2 MERGE JOIN (Cost=8583 Card=89527 Bytes=5550674)
    4 3 TABLE ACCESS (BY INDEX ROWID) OF 'CONTACT_VALUES1' ( Cost=826 Card=1852109 Bytes=90753341)
    5 4 INDEX (FULL SCAN) OF 'CONTACT_VALUES1_PK' (UNIQUE) (Cost=26 Card=1852109)
    6 3 SORT (JOIN) (Cost=7757 Card=89527 Bytes=1163851)
    7 6 VIEW (Cost=7454 Card=89527 Bytes=1163851)
    8 7 INTERSECTION
    9 8 SORT (UNIQUE)
    10 9 INDEX (FAST FULL SCAN) OF 'CONTACT_VALUES1_PK' (UNIQUE) (Cost=5 Card=1852109 Bytes=11112654)
    11 8 INTERSECTION
    12 11 SORT (UNIQUE)
    13 12 HASH JOIN (Cost=640 Card=250676 Bytes=7269604)
    14 13 HASH JOIN (Cost=6 Card=28 Bytes=560)
    15 14 TABLE ACCESS (BY INDEX ROWID) OF 'SEGMENTATION_QUERY_VALUES' (Cost=3 Card=1 Bytes=13)
    16 15 INDEX (RANGE SCAN) OF 'SEG_QUERY_VALUES_PK' (UNIQUE) (Cost=2 Card=2)
    17 14 TABLE ACCESS (FULL) OF 'COUNTRY' (Cost =2 Card=120 Bytes=840)
    18 13 TABLE ACCESS (FULL) OF 'CONTACT_COUNTRY1 ' (Cost=628 Card=2135370 Bytes=19218330)
    19 11 SORT (UNIQUE)
    20 19 HASH JOIN (Cost=640 Card=89527 Bytes=25962 83)
    21 20 HASH JOIN (Cost=6 Card=10 Bytes=200)
    22 21 TABLE ACCESS (BY INDEX ROWID) OF 'SEGMENTATION_QUERY_VALUES' (Cost=3 Card=1 Bytes=13)
    23 22 INDEX (RANGE SCAN) OF 'SEG_QUERY_VALUES_PK' (UNIQUE) (Cost=2 Card=2)
    24 21 TABLE ACCESS (FULL) OF 'COUNTRY' (Cost =2 Card=120 Bytes=840)
    25 20 TABLE ACCESS (FULL) OF 'CONTACT_COUNTRY1 ' (Cost=628 Card=2135370 Bytes=19218330)
    26 2 TABLE ACCESS (FULL) OF 'SEGMENTATION_USER_COUNTRY_MAP'
    (Cost=5 Card=45 Bytes=495)

  • Tuning The Query By Using Xplain Plan

    Hi Guys,
    This particular query is taking a long time in the production reported by The SPE team .
    SELECT
    CASE
    WHEN TPJRCSHDRW1.CASH_DRAWER_ID = 5000555
    THEN 1
    WHEN TPTRJO1.OTHER_CASH_DRAWER_ID = 5000555
    THEN 2
    END TRADE_TYPE,
    TPDECO1.DENOMINATION_COUNT_ID,
    TPDECO1.DENOMINATION_CATEGORY,
    TPDECO1.DENOMINATION_VALUE,
    TPDECO1.DENOMINATION_COUNT,
    TPDECO1.DENOMINATION_TYPE,
    TPDECO1.DENOMINATION_NAME,
    TPTRJO1.TRANSACTION_ID,
    TPTRJO1.TOTAL_VALUE,
    TPTRJO1.TOTAL_VALUE_CCODE,
    TPTRJO1.JOURNAL_ENTRY_ID,
    TPJRCSHDRW1.CASH_DRAWER_ID,
    TPTRJO1.OTHER_CASH_DRAWER_ID
    FROM TRANSACTION_JOURNAL TPTRJO1
    INNER JOIN JOURNAL_CASH_DRAWER TPJRCSHDRW1
    ON TPTRJO1.JOURNAL_ENTRY_ID = TPJRCSHDRW1.JOURNAL_ENTRY_ID
    LEFT OUTER JOIN DENOMINATION_COUNT TPDECO1
    ON TPDECO1.JOURNAL_ENTRY_ID = TPJRCSHDRW1.JOURNAL_ENTRY_ID
    WHERE ((TPJRCSHDRW1.CASH_DRAWER_ID = 5000555)
    OR (TPTRJO1.OTHER_CASH_DRAWER_ID = 5000555))
    AND (TPTRJO1.TRANSACTION_ID IN (563,590,1362,605,562,589,604))
    AND (TPTRJO1.STATUS NOT IN ('I','V','R'))
    AND ((TPTRJO1.REVERSED_BY) IS NULL) AND (TPJRCSHDRW1.CASH_DRAWER_DATE >= to_date('2009-07-24','yyyy-mm-dd') )
    AND (TPTRJO1.TOTAL_VALUE <> 0)
    AND ((TPTRJO1.OFFSET_ID) IS NULL);
    When I am analysing the query by xplain_plan , I am getting this plan
    Plan hash value: 3371088438
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 36557 | 3391K| 1445 (1)| 00:00:18 |
    | 1 | CONCATENATION | | | | | |
    | 2 | NESTED LOOPS OUTER | | 1 | 95 | 3 (0)| 00:00:01 |
    | 3 | NESTED LOOPS | | 1 | 63 | 2 (0)| 00:00:01 |
    |* 4 | TABLE ACCESS BY INDEX ROWID| TRANSACTION_JOURNAL | 1 | 40 | 1 (0)| 00:00:01 |
    |* 5 | INDEX RANGE SCAN | I26_TRANSACTION_JOURNAL | 1 | | 1 (0)| 00:00:01 |
    |* 6 | TABLE ACCESS BY INDEX ROWID| JOURNAL_CASH_DRAWER | 1 | 23 | 1 (0)| 00:00:01 |
    |* 7 | INDEX RANGE SCAN | PKC_JOURNAL_CASH_D | 1 | | 1 (0)| 00:00:01 |
    | 8 | TABLE ACCESS BY INDEX ROWID | DENOMINATION_COUNT | 12 | 384 | 1 (0)| 00:00:01 |
    |* 9 | INDEX RANGE SCAN | PKC_DENOMINATION_COUNT | 20 | | 1 (0)| 00:00:01 |
    | 10 | NESTED LOOPS OUTER | | 36556 | 3391K| 1442 (1)| 00:00:18 |
    | 11 | NESTED LOOPS | | 1817 | 111K| 715 (0)| 00:00:09 |
    | 12 | TABLE ACCESS BY INDEX ROWID| JOURNAL_CASH_DRAWER | 1817 | 41791 | 351 (0)| 00:00:05 |
    |* 13 | INDEX RANGE SCAN | SPE099_JOURNALCASHDRWR | 1817 | | 7 (0)| 00:00:01 |
    |* 14 | TABLE ACCESS BY INDEX ROWID| TRANSACTION_JOURNAL | 1 | 40 | 1 (0)| 00:00:01 |
    |* 15 | INDEX UNIQUE SCAN | PKC_TRANSACTION_JOURNAL | 1 | | 1 (0)| 00:00:01 |
    | 16 | TABLE ACCESS BY INDEX ROWID | DENOMINATION_COUNT | 20 | 640 | 1 (0)| 00:00:01 |
    |* 17 | INDEX RANGE SCAN | PKC_DENOMINATION_COUNT | 20 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    4 - filter("TPTRJO1"."TOTAL_VALUE"<>0 AND "TPTRJO1"."REVERSED_BY" IS NULL AND
    "TPTRJO1"."OFFSET_ID" IS NULL)
    5 - access("TPTRJO1"."OTHER_CASH_DRAWER_ID"=5000555)
    filter("TPTRJO1"."STATUS"<>U'I' AND "TPTRJO1"."STATUS"<>U'V' AND "TPTRJO1"."STATUS"<>U'R'
    AND ("TPTRJO1"."TRANSACTION_ID"=562 OR "TPTRJO1"."TRANSACTION_ID"=563 OR
    "TPTRJO1"."TRANSACTION_ID"=589 OR "TPTRJO1"."TRANSACTION_ID"=590 OR
    "TPTRJO1"."TRANSACTION_ID"=604 OR "TPTRJO1"."TRANSACTION_ID"=605 OR
    "TPTRJO1"."TRANSACTION_ID"=1362))
    6 - filter("TPJRCSHDRW1"."DRAWER_SEQ" IS NOT NULL)
    7 - access("TPTRJO1"."JOURNAL_ENTRY_ID"="TPJRCSHDRW1"."JOURNAL_ENTRY_ID" AND
    "TPJRCSHDRW1"."CASH_DRAWER_DATE">=TO_DATE(' 2009-07-24 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
    filter("TPJRCSHDRW1"."CASH_DRAWER_DATE">=TO_DATE(' 2009-07-24 00:00:00', 'syyyy-mm-dd
    hh24:mi:ss'))
    9 - access("TPDECO1"."JOURNAL_ENTRY_ID"(+)="TPJRCSHDRW1"."JOURNAL_ENTRY_ID")
    13 - access("TPJRCSHDRW1"."CASH_DRAWER_ID"=5000555 AND
    "TPJRCSHDRW1"."CASH_DRAWER_DATE">=TO_DATE(' 2009-07-24 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
    filter("TPJRCSHDRW1"."DRAWER_SEQ" IS NOT NULL)
    14 - filter("TPTRJO1"."STATUS"<>U'I' AND "TPTRJO1"."STATUS"<>U'V' AND "TPTRJO1"."STATUS"<>U'R'
    AND ("TPTRJO1"."TRANSACTION_ID"=562 OR "TPTRJO1"."TRANSACTION_ID"=563 OR
    "TPTRJO1"."TRANSACTION_ID"=589 OR "TPTRJO1"."TRANSACTION_ID"=590 OR
    "TPTRJO1"."TRANSACTION_ID"=604 OR "TPTRJO1"."TRANSACTION_ID"=605 OR
    "TPTRJO1"."TRANSACTION_ID"=1362) AND "TPTRJO1"."TOTAL_VALUE"<>0 AND "TPTRJO1"."REVERSED_BY" IS
    NULL AND "TPTRJO1"."OFFSET_ID" IS NULL AND LNNVL("TPTRJO1"."OTHER_CASH_DRAWER_ID"=5000555))
    15 - access("TPTRJO1"."JOURNAL_ENTRY_ID"="TPJRCSHDRW1"."JOURNAL_ENTRY_ID")
    17 - access("TPDECO1"."JOURNAL_ENTRY_ID"(+)="TPJRCSHDRW1"."JOURNAL_ENTRY_ID")
    --There is an index  SPE099_JOURNALCASHDRWR which is on
    CASH_DRAWER_ID
    CASH_DRAWER_DATE
    DRAWER_SEQ
    But I am wondering why there is TABLE ACCESS BY INDEX ROWID| JOURNAL_CASH_DRAWER when this col is availabe in the indexed table .
    Can anyone Please suggest what improvements can be done on this query.WIll change in the table order will have some performance boost.
    Please suggest ..
    Thanks
    Prafulla

    Could you please execute your query reported here below (pay attention to the gather_plan_statistics hint)
    select /*+ gather_plan_statistics */
          case
            when tpjrcshdrw1.cash_drawer_id = 5000555
            then 1
            when tptrjo1.other_cash_drawer_id = 5000555
            then 2
          end trade_type,
          tpdeco1.denomination_count_id,
          tpdeco1.denomination_category,
          tpdeco1.denomination_value,
          tpdeco1.denomination_count,
          tpdeco1.denomination_type,
          tpdeco1.denomination_name,
          tptrjo1.transaction_id,
          tptrjo1.total_value,
          tptrjo1.total_value_ccode,
          tptrjo1.journal_entry_id,
          tpjrcshdrw1.cash_drawer_id,
          tptrjo1.other_cash_drawer_id
    from
          transaction_journal tptrjo1
    inner join journal_cash_drawer tpjrcshdrw1
            on tptrjo1.journal_entry_id = tpjrcshdrw1.journal_entry_id
    left outer join denomination_count tpdeco1
            on tpdeco1.journal_entry_id        = tpjrcshdrw1.journal_entry_id
    where ((tpjrcshdrw1.cash_drawer_id = 5000555)
          or (tptrjo1.other_cash_drawer_id   = 5000555))
    and (tptrjo1.transaction_id       in (563,590,1362,605,562,589,604))
    and (tptrjo1.status not           in ('I','V','R'))
    and ((tptrjo1.reversed_by)        is null)
    and (tpjrcshdrw1.cash_drawer_date >= to_date('2009-07-24','yyyy-mm-dd') )
    and (tptrjo1.total_value 0)
    and ((tptrjo1.offset_id) is null);and post the formatted explain plan you will get using
    select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));IS one of the following indexed columns NULLABLE?
    CASH_DRAWER_ID
    CASH_DRAWER_DATE
    DRAWER_SEQ
    Best Regards
    Mohamed Houri
    www.hourim.wordpress.com
    Edited by: Mohamed Houri on 14-juin-2012 7:07

  • SQL performance problem.. here is explain plan

    This takes 12 seconds... and give 100 K rows in return..
    I need to do pagination and start and end index should be any rang like 200 TO 300
    So when I get that it never comes back..
    select rownum rn , X.*
       from  v_online_item X,             
       (SELECT c.category_seq AS seq_no, c.assoc_seq, c.assoc_table_name             
              FROM v_online_category_assoc c,
                   (SELECT     assoc_seq
                          FROM v_online_category_assoc a
                         WHERE a.assoc_table_name = 'V_ONLINE_CATEGORY'               
                    CONNECT BY category_seq = PRIOR assoc_seq
                           AND assoc_table_name = 'V_ONLINE_CATEGORY'
                    START WITH category_seq = 170101
                           AND assoc_table_name = 'V_ONLINE_CATEGORY'
                   UNION
                   SELECT to_number(170101)
                     FROM DUAL
                      ) v
             WHERE c.category_seq = v.assoc_seq
               AND assoc_table_name = 'V_ONLINE_ITEM'
       ) Y
       where X.item_seq = Y.assoc_seq 
    Plan
    SELECT STATEMENT  ALL_ROWSCost: 1,484,076  Bytes: 76,566,065,969  Cardinality: 4,868,447                                                              
         17 FILTER                                                         
              16 VIEW VZW_ADMIN. Cost: 1,484,076  Bytes: 76,566,065,969  Cardinality: 4,868,447                                                    
                   15 COUNT                                               
                        14 HASH JOIN  Cost: 1,484,076  Bytes: 5,588,977,156  Cardinality: 4,868,447                                          
                             12 NESTED LOOPS  Cost: 31,929  Bytes: 189,869,433  Cardinality: 4,868,447                                     
                                  10 VIEW VZW_ADMIN. Cost: 8  Bytes: 416  Cardinality: 32                                
                                       9 SORT UNIQUE  Cost: 8  Bytes: 806  Cardinality: 32                           
                                            8 UNION-ALL                      
                                                 6 FILTER                 
                                                      5 CONNECT BY WITH FILTERING            
                                                           1 INDEX RANGE SCAN INDEX (UNIQUE) VZW_ADMIN.UDX1_ONLINE_CATEGORY_ASSOC Cost: 4  Bytes: 735  Cardinality: 15       
                                                           4 NESTED LOOPS       
                                                                2 CONNECT BY PUMP 
                                                                3 INDEX RANGE SCAN INDEX (UNIQUE) VZW_ADMIN.UDX1_ONLINE_CATEGORY_ASSOC Cost: 4  Bytes: 806  Cardinality: 31 
                                                 7 FAST DUAL  Cost: 2  Cardinality: 1                 
                                  11 INDEX RANGE SCAN INDEX (UNIQUE) VZW_ADMIN.UDX1_ONLINE_CATEGORY_ASSOC Cost: 998  Bytes: 3,955,614  Cardinality: 152,139                                
                             13 TABLE ACCESS FULL TABLE VZW_ADMIN.V_ONLINE_ITEM Cost: 670,275  Bytes: 16,092,289,779  Cardinality: 14,510,631                                     
    select * from
             (select rownum rn , X.*
       from  v_online_item X,             
       (SELECT c.category_seq AS seq_no, c.assoc_seq, c.assoc_table_name             
              FROM v_online_category_assoc c,
                   (SELECT     assoc_seq
                          FROM v_online_category_assoc a
                         WHERE a.assoc_table_name = 'V_ONLINE_CATEGORY'               
                    CONNECT BY category_seq = PRIOR assoc_seq
                           AND assoc_table_name = 'V_ONLINE_CATEGORY'
                    START WITH category_seq = 170101
                           AND assoc_table_name = 'V_ONLINE_CATEGORY'
                   UNION
                   SELECT to_number(170101)
                     FROM DUAL
                      ) v
             WHERE c.category_seq = v.assoc_seq
               AND assoc_table_name = 'V_ONLINE_ITEM'
       ) Y
       where X.item_seq = Y.assoc_seq 
        where  rn between :s_index and :e_index    ;
    Plan
    SELECT STATEMENT  ALL_ROWSCost: 1,484,076  Bytes: 76,566,065,969  Cardinality: 4,868,447                                                              
         17 FILTER                                                         
              16 VIEW VZW_ADMIN. Cost: 1,484,076  Bytes: 76,566,065,969  Cardinality: 4,868,447                                                    
                   15 COUNT                                               
                        14 HASH JOIN  Cost: 1,484,076  Bytes: 5,588,977,156  Cardinality: 4,868,447                                          
                             12 NESTED LOOPS  Cost: 31,929  Bytes: 189,869,433  Cardinality: 4,868,447                                     
                                  10 VIEW VZW_ADMIN. Cost: 8  Bytes: 416  Cardinality: 32                                
                                       9 SORT UNIQUE  Cost: 8  Bytes: 806  Cardinality: 32                           
                                            8 UNION-ALL                      
                                                 6 FILTER                 
                                                      5 CONNECT BY WITH FILTERING            
                                                           1 INDEX RANGE SCAN INDEX (UNIQUE) VZW_ADMIN.UDX1_ONLINE_CATEGORY_ASSOC Cost: 4  Bytes: 735  Cardinality: 15       
                                                           4 NESTED LOOPS       
                                                                2 CONNECT BY PUMP 
                                                                3 INDEX RANGE SCAN INDEX (UNIQUE) VZW_ADMIN.UDX1_ONLINE_CATEGORY_ASSOC Cost: 4  Bytes: 806  Cardinality: 31 
                                                 7 FAST DUAL  Cost: 2  Cardinality: 1                 
                                  11 INDEX RANGE SCAN INDEX (UNIQUE) VZW_ADMIN.UDX1_ONLINE_CATEGORY_ASSOC Cost: 998  Bytes: 3,955,614  Cardinality: 152,139                                
                             13 TABLE ACCESS FULL TABLE VZW_ADMIN.V_ONLINE_ITEM Cost: 670,275  Bytes: 16,092,289,779  Cardinality: 14,510,631                                     

    user550024 wrote:
    This takes 12 seconds... and give 100 K rows in return..
    I need to do pagination and start and end index should be any rang like 200 TO 300
    So when I get that it never comes back..Refer to the Tom Kyte column mentioned, but just a few comments: Your query seems to be missing an explicit ORDER BY, so it's unsure what order you're actually thinking of when performing your pagination.
    Second, using "rn between :s_index and :e_index" doesn't activate the FIRST_ROWS_n mode of the optimizer. You should use either an explicit FIRST_ROWS(n) hint, or even better, use the more convoluted double-inline view syntax as shown by Tom (... where rownum <= :M ... where rnum >= :N).
    If you don't have a supporting index for the ORDER requested, you should see at least a SORT ORDER BY STOPKEY operation. At least one of the columns of the index needs to be defined as NOT NULL to be supported by a normal b*tree index. If you have character-based columns in the ORDER BY/index definition you need to make sure that you're using NLS_SORT = binary on the clients involved, otherwise again a normal b*tree index can't be used for returning the result set in the order requested.
    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/

  • Book advise for explain plan

    Hi guys,
    I have 2 questions. The first one is as you know before, I would like to learn all secrets behind explain plan and how how oracle works behind the scenery. I have researched some books. I found Oracle SQL Tuning: A Close Look at Explain Plans by Dan Hotka. Do you recommend this book? I have just read one page of this books, I thnik the language of this book is simple and it explains the situation from the beginning. I think, it is usefull for beginners like me. Because the things become hard to learn in first time for beginners. As a result I just would like to learn that do you recommend this book?
    My second question is, I want to buy this book but I couldn't find in England (as paperback, not e book). But, appereantly I have to buy it online as ebook. Do you know any trusted web site that I can buy this book's ebook version?
    Thanks a lot for your help.

    944258 wrote:
    Hi guys,
    I have 2 questions. The first one is as you know before, I would like to learn all secrets behind explain plan and how how oracle works behind the scenery. I have researched some books. I found Oracle SQL Tuning: A Close Look at Explain Plans by Dan Hotka. Do you recommend this book? I have just read one page of this books, I thnik the language of this book is simple and it explains the situation from the beginning. I think, it is usefull for beginners like me. Because the things become hard to learn in first time for beginners. As a result I just would like to learn that do you recommend this book?Hi, why not start here first: http://www.orafaq.com/node/1420. There is probably as much information about execution plans found online, as there is in the books. At least the part you would like to know and try to remember will be online available :-)
    >
    My second question is, I want to buy this book but I couldn't find in England (as paperback, not e book). But, appereantly I have to buy it online as ebook. Do you know any trusted web site that I can buy this book's ebook version?
    http://www.amazon.com/Oracle-SQL-Tuning-Close-Explain/dp/1453804196
    Cheers
    FJFranken

  • How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?

    1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
    When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed  in the stat plan  ?
    2. Does rowsource statistics gives some kind of  understanding of Extended stats ?

    You can get Row Source Statistics only *after* the SQL has been executed.  An Explain Plan midway cannot give you row source statistics.
    To get row source statistics either set STATISTICS_LEVEL='ALL'  in the session that executes theSQL OR use the Hint "gather_plan_statistics"  in the SQL being executed.
    Then use dbms_xplan.display_cursor
    Hemant K Chitale

  • Explain plan is not visible for a Spatial Query

    Hi Everybody
    I'm traying to optimze an spatial query, So for that I'm trying to get the explain plan but its seems I can't get it, Somebady can tell me whay?
    This is my query by the way
    SELECT /*+ ORDERED */ TELEMATICS_PARK_SUMMARY.TELEMATICS_UNIT_ID, TELEMATICS_PARK_SUMMARY.TRIP_START_DATE_TIME,
    TELEMATICS_PARK_SUMMARY.CORP_CODE, TELEMATICS_PARK_SUMMARY.FLEET_NUMBER, TELEMATICS_PARK_SUMMARY.LEVEL2_CODE,
    TELEMATICS_PARK_SUMMARY.LEVEL3_CODE, TELEMATICS_PARK_SUMMARY.LEVEL4_CODE, TELEMATICS_PARK_SUMMARY.LEVEL5_CODE,
    TELEMATICS_PARK_SUMMARY.LEVEL6_CODE, TELEMATICS_PARK_SUMMARY.LEVEL_NUMBER, TELEMATICS_PARK_SUMMARY.PARKING_NUMBER,
    STRUCTURE_POI.STRUCTURE_POI_ID, STRUCTURE_POI.CORP_CODE, STRUCTURE_POI.FLEET_NUMBER, STRUCTURE_POI.LEVEL2_CODE,
    STRUCTURE_POI.LEVEL3_CODE, STRUCTURE_POI.LEVEL4_CODE, STRUCTURE_POI.LEVEL5_CODE, STRUCTURE_POI.LEVEL6_CODE,
    STRUCTURE_POI.LEVEL_NUMBER, STRUCTURE_POI.EFFECTIVE_START_DATE, STRUCTURE_POI.EFFECTIVE_END_DATE, STRUCTURE_POI.IS_FLEET_POI_SW
    FROM
    STRUCTURE_POI, TELEMATICS_PARK_SUMMARY WHERE
    (SDO_WITHIN_DISTANCE(TELEMATICS_PARK_SUMMARY.SHAPE, STRUCTURE_POI.SHAPE, 'distance='||TO_CHAR(180*STRUCTURE_POI.GEO_FENCE_BUFFER_DIST/(6378137*3.14159265)))) = 'TRUE'
    Regards
    Jesus Gutierrez

    You can get Row Source Statistics only *after* the SQL has been executed.  An Explain Plan midway cannot give you row source statistics.
    To get row source statistics either set STATISTICS_LEVEL='ALL'  in the session that executes theSQL OR use the Hint "gather_plan_statistics"  in the SQL being executed.
    Then use dbms_xplan.display_cursor
    Hemant K Chitale

  • Explain plan for running query

    Hi everyone,
    I come to know how to generate explain plan for a given query by giving
    Explain plan for select * fro emp;
    Consider a query running for 5 hrs in a session and i want to genrate explain plan for that current query in its 4th hour i dont know the sql as well
    all the steps by step would be much apppreciated
    like finding Current SQL then so on
    Thanks
    Shareef

    912856 wrote:
    Hi everyone,
    I come to know how to generate explain plan for a given query by giving
    Explain plan for select * fro emp;
    Consider a query running for 5 hrs in a session and i want to genrate explain plan for that current query in its 4th hour i dont know the sql as well
    all the steps by step would be much apppreciated
    like finding Current SQL then so on
    Thanks
    ShareefYOu can also use dbms_xplain to generate plan used in v$sql. like for example
    SQL>SELECT  SQL_ID,  CHILD_NUMBER FROM  V$SQL WHERE  SQL_TEXT LIKE 'select * from em%';
    SQL_ID        CHILD_NUMBER
    6kd5fkqdjb8fu            0
    SQL>SELECT  * FROM  TABLE(DBMS_XPLAN.DISPLAY_CURSOR('6kd5fkqdjb8fu',0,'ALLSTATS'));If you need the actual tuntime statistics used by sql statement then you need to put hint /*+ gather_plan_statistics */ in sql ststement, something like
    select /*+ gather_plan_statistics */ * from emp;
    and then generate the explain plan for this
    Have a look
    http://hoopercharles.wordpress.com/2010/03/01/dbms_xplan-format-parameters/
    select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));

  • Unable to Execute Explain Plan for the selected SQL

    When working with several SQL statements in one SQL Worksheet you execute the specific statement by selecting it and pressing F9.
    The same is not possible for the explain plan though.
    If you select the first SQL statement and press F6, the explain plan is executed correctly. If you try the same for any other statement, all you get is 'No SQL statement entered.' on the status bar.
    Maciej

    It is available.
    Type this in.
    create table xx (yy number(10));
    create table zz (aa number(10));
    select * from xx;
    select * from zz;Run all these statements by pressing f5.
    Place the cursor on 'select * from xx;'.
    Press f6 gives you a plan.
    Place the cursor on 'select * from zz;'
    press f6 gives you a different plan.
    The problem seems to be that F6 is still suffering from a statement selection bug which is already fixed for f9. That is selecting a whole statement results in failure to recognise a statement and the 'No statement entered' message.

  • How to use Tuning Pack for SQL tuning

    We're just getting started with 10g, and I'm more familiar with 9i. In OEM 9i, there was something called Oracle SQL Analyze. It allowed you to work on a problem SQL statement, adding hints, making other changes, etc., and then you could easily compare the plan for two versions of a query. You could also execute right from there and it'd let you click on a tab to view the statistics. You could compare the statistics for two versions of the same statement.
    I don't see anything like this in 10.1 GC, and that's with both the Diagnostic and Tuning Packs activated. There are a number of ways you can identify an SQL for analysis, then get an explain plan, then get some recommendations. But I don't see anything that allows you to add hints, compare different versions of the explain plan, or compare the statistics for different versions of a statement.
    Am I missing something?
    Thanks.
    Dave

    Rodney,
    Thanks for the reply. Yes, I agree, the Java console which runs directly on Windows is quite limited. Change Manager is there, as you indicated. However, MetaLink note 277066.1 indicates that "Tuning Pack Functionality" is also available in the Java version, and I don't see any of it there.
    What I'm looking for is a framework for testing different versions of an SQL statement. I want to be able to execute the current version of a statement and, for example, a modified version with a hint added. I want to be able to see at least the basic statisitics comparing the two exections (e.g., elapsed time, logical reads, physical reads). This was possible with SQL Analyze in 9i, but I can't find anything like it in 10g.
    I have found both the 10g advisors you mentioned and they do seem to work, but they don't provide the same flexibility and power for working on statement tuning apart from what the advisors recommend.
    Thanks for all the suggestions/ideas...
    Dave

  • Facing Merge Join Cartersian in the explain plan after adding gl periods

    Hi All
    I have added gl periods table to the below query , checked the explain plan and it shows merge join cartesian. This query is taking long time to fetch the results.
    Need help ASAP , Please let me know where i am going wrong . Any suggestions will be appreciated.
    SELECT gljh.period_name, gljh.ledger_id, gljh.je_source,
    glcc.segment2,
    SUM ( NVL (gljl.accounted_dr, 0)
    - NVL (gljl.accounted_cr, 0)
    ) total_amt,
    gljh.currency_code
    FROM gl_je_headers gljh,
    gl_je_lines gljl,
    gl_code_combinations glcc,
    gl_periods gps
    WHERE 1=1
    AND gljh.period_name = gps.period_name
    AND gljl.period_name = gps.period_name
    AND gps.period_set_name = 'MCD_MONTH_'
    AND gps.start_date >= :p_from_date
    AND gps.start_date <= :p_to_date
    AND gljh.ledger_id = :p_ledger_id
    AND gljh.je_header_id = gljl.je_header_id
    AND gljl.code_combination_id = glcc.code_combination_id
    AND glcc.segment2 = '10007'--get_segment2_rec.flex_value
    AND gljh.currency_code <> 'STAT'
    GROUP BY gljh.je_source,
    gljh.period_name,
    glcc.segment2,
    gljh.ledger_id,
    gljh.currency_code
    HAVING SUM ( NVL (gljl.accounted_dr, 0)
    - NVL (gljl.accounted_cr, 0)
    ) <> 0;
    Plan
    SELECT STATEMENT ALL_ROWSCost: 73,146 Bytes: 2,266 Cardinality: 22                                              
         15 FILTER                                         
              14 HASH GROUP BY Cost: 73,146 Bytes: 2,266 Cardinality: 22                                    
                   13 FILTER                               
                        12 NESTED LOOPS Cost: 73,145 Bytes: 61,079 Cardinality: 593                          
                             9 NESTED LOOPS Cost: 31,603 Bytes: 1,452,780 Cardinality: 20,754                     
                                  6 MERGE JOIN CARTESIAN Cost: 2,108 Bytes: 394,181 Cardinality: 9,167                
                                       2 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_PERIODS Cost: 4 Bytes: 31 Cardinality: 1           
                                            1 INDEX RANGE SCAN INDEX (UNIQUE) GL.GL_PERIODS_U2 Cost: 1 Cardinality: 64      
                                       5 BUFFER SORT Cost: 2,104 Bytes: 683,988 Cardinality: 56,999           
                                            4 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_CODE_COMBINATIONS Cost: 2,104 Bytes: 683,988 Cardinality: 56,999      
                                                 3 INDEX RANGE SCAN INDEX GL.GL_CODE_COMBINATIONS_N2 Cost: 155 Cardinality: 56,999
                                  8 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_JE_LINES Cost: 18 Bytes: 54 Cardinality: 2                
                                       7 INDEX RANGE SCAN INDEX GL.GL_JE_LINES_N1 Cost: 3 Cardinality: 37           
                             11 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_JE_HEADERS Cost: 2 Bytes: 33 Cardinality: 1                     
                                  10 INDEX UNIQUE SCAN INDEX (UNIQUE) GL.GL_JE_HEADERS_U1 Cost: 1 Cardinality: 1                
    Thanks
    Chandra

    Lots of things come into play when you're tuning a query.
    An (unformatted) execution plan isn't enough.
    Tuning takes time and understanding how (a lot of) things work, there is no ASAP in the world of tuning.
    Please post other important details, like your database version, optimizer settings, how/when are table statistics gathered etc.
    So, read the following informative threads (and please take your time, this really is important stuff), and adust your thread as needed.
    That way you'll have a bigger chance of getting help that makes sense...
    Your DBA should/ought to be able to help you in this as well.
    Re: HOW TO: Post a SQL statement tuning request - template posting
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html

Maybe you are looking for