Query select 1 row Explain plan shows different no of rows

SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> set autot on
SQL> select session_id from dba_fga_audit_trail;
SESSION_ID
     24001
1 row selected.
Elapsed: 00:00:00.00
Execution Plan
Plan hash value: 1613626607
| Id  | Operation         | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT  |          | 41678 |   203K|   507   (1)| 00:00:07 |
|   1 |  TABLE ACCESS FULL| FGA_LOG$ | 41678 |   203K|   507   (1)| 00:00:07 |
------------------------------------------------------------------------------In the above query it is selecting only one row
but in E Plan it is showing 41678 rows selected.
Am i wrong somewhere ?
Regards
Singh

The number of rows processed to get your one record

Similar Messages

  • Why can the explain plan be different from 2 exact set of structures

    hi,
    i have from a view some base tables let's say A , B, C & D
    this query is running very slow . so from the same database , i created tables A1 , B1, C1,& D1 from the above tables.
    i created some new indexes on A1 to D1 tables and the results returned to me is fast.
    i did an exlain plan
    so i drop the indexes on the original A to D table and created the new indexes as per A1 to D1 and analyzed them. and i also did an explain plan
    but the query is still running slow and also the explain plan is different to the one from A1 to D1 (the one that running fast)
    pls help me to understand how/why can this happen ?
    tks & rdgs

    hi,
    precisely i could have been providing insufficient information but i am too inexperienced to be able to give you the required information and i am also not very sure where i could get the info so that you all can advise me further.
    but this is from the user_tables , the only difference i see is that
    under LOGGING table A to E is 'YES'
    TABLE_NAME     TABLESPACE_NAME     PCT_FREE     LOGGING     BACKED_UP     NUM_ROWS     BLOCKS     CACHE     TABLE_LOCK     PARTITIONED
    A1          OWNER1          10          NO          N     37332          883         N     ENABLED     NO
    B1          OWNER1          10          NO          N     43458          861         N     ENABLED     NO
    C1          OWNER1          10          NO          N     823828          7826         N     ENABLED     NO
    D1          OWNER1          10          NO          N     881176          14646         N     ENABLED     NO
    E1          OWNER1          10          NO          N     18868          223         N     ENABLED     NO
    A          OWNER1          10          YES          N     37040          880         N     ENABLED     NO
    B          OWNER1          10          YES          N     43386          880         N     ENABLED     NO
    C          OWNER1          10          YES          N     823820          7684         N     ENABLED     NO
    D          OWNER1          50          YES          N     880948          26624         N     ENABLED     NO
    E          OWNER1          10          YES          N     18690          244         N     ENABLED     NOtks & rdgs

  • Explain Plan shows Nested Loops, Is it good or bad?

    Hi All,
    I have a doubt in the explain plan, I would like to know if the Nested Loops , will it degrade the query performance?
    Note: I have pasted only few output that I had taken from the expalin plan.
    Do let me know if there is any article I could read to get clear understanding about the same.
    17 NESTED LOOPS ANTI Cost: 125 Bytes: 186 Cardinality: 1                                                                  
    15 NESTED LOOPS ANTI Cost: 124 Bytes: 166 Cardinality: 1                                                             
    12 NESTED LOOPS Cost: 122 Bytes: 140 Cardinality: 1                                                        
         9 NESTED LOOPS Cost: 121 Bytes: 117 Cardinality: 1           
    Thanks

    Hi,
    there is absolutely nothing wrong about nested loops (NL). It's a very efficient way of combining data from two rowsources. It works pretty much like a regular loop: it takes all rows from one rowsource (the "outer" one) and for each of them it looks up a row matching the join condition in the other rowsource (the "inner" one).
    Note that there are not so many alternatives in Oracle: there are only 3 ways to join data in Oracle, and one of them is used in rather special circumstances (merge join). So normally the choice is between a NL and a hash join. Hash join (HJ) takes the smaller dataset and builds an in-memory lookup table using a hash function on join column(s). Then it goes through the other dataset and as it goes, it applies the hashing function to join column(s) and picks the matching rows from the smaller dataset.
    Actually, hash joins and nested loops are not all that different. The basic mechanism is same: you go through one datasource and as you go, you pick matching rows from the other and do the join. The main difference is that a HJ requires some preparation work (it costs resources to build the in-memory table) and thus HJ are typically associated with less-selective queries and full table scans.
    In your particular case it's nor possible to tell whether or not NL is in order based on just a few rows from the explain plan. We need to know the structure of your tables (the DDL), what kind of data they hold (optimizer stats) and what query you are running to be able to tell.
    Best regards,
    Nikolay

  • Explain plan shows 300T of TempSpc and 999 hours - tuning request

    Hi,
    I have a query which obtains summary statistics. There is an items table which contains the dictionary of items which can be recorded. There is an events table which contains the item ID, timestamp and a value. The query summarizes the data for each item. e.g. Mean, stddev, sample values, length. I have trimmed the query down as simply as possible and am having a problem with large temp space and runtime estimates in the explain plan. Here is the query:
    WITH ChartItems AS (
        SELECT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          COUNT(*),
          COUNT(distinct subject_id)
        FROM mimic2v26.d_chartitems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
        --WHERE ci.itemid = 51
        GROUP BY ci.itemid,
                 ci.label,
                 ci.category,
                 ci.description
    --select * from ChartItems;
    , RawData AS (
        SELECT DISTINCT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          last_value(ce.value1) ignore nulls over (partition BY ci.itemid order by
          ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS
          value1_last
        FROM ChartItems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
    select * from RawData;Which gives this explain plan:
    Plan hash value: 642453121
    | Id  | Operation                    | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                |  4811G|  1238T|       |  3686M (13)|999:59:59 |
    |   1 |  VIEW                        |                |  4811G|  1238T|       |  3686M (13)|999:59:59 |
    |   2 |   HASH UNIQUE                |                |  4811G|   258T|       |  3686M (13)|999:59:59 |
    |   3 |    WINDOW BUFFER             |                |  4811G|   258T|       |  3686M (13)|999:59:59 |
    |   4 |     SORT GROUP BY            |                |  4811G|   258T|   317T|  3686M (13)|999:59:59 |
    |*  5 |      HASH JOIN               |                |  4811G|   258T|  4943M|    25M (90)| 85:14:28 |
    |   6 |       VIEW                   | VW_DAG_0       |   152M|  3199M|       |  1366K  (1)| 04:33:18 |
    |   7 |        HASH GROUP BY         |                |   152M|  4216M|  5839M|  1366K  (1)| 04:33:18 |
    |*  8 |         HASH JOIN            |                |   152M|  4216M|       |   147K  (2)| 00:29:36 |
    |   9 |          TABLE ACCESS FULL   | D_CHARTITEMS   |  4832 | 96640 |       |     7   (0)| 00:00:01 |
    |  10 |          INDEX FAST FULL SCAN| CHARTEVENTS_O2 |   196M|  1683M|       |   147K  (1)| 00:29:25 |
    |  11 |       TABLE ACCESS FULL      | CHARTEVENTS    |   196M|  6922M|       |   616K  (1)| 02:03:19 |
    Predicate Information (identified by operation id):
       5 - access("CE"."ITEMID"="ITEM_2")300T of temp space! Ouch.
    TKPROF output (I let the query run for a short while. I let it run for ages earlier, but wasn't tracing the session. Should I let it run for longer?):
    TKPROF: Release 11.2.0.3.0 - Development on Tue Jul 10 16:54:27 2012
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    Trace file: /oracle/11gr2/app/oracle/diag/rdbms/mimic2/mimic2/trace/mimic2_ora_6507.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    WITH ChartItems AS (
        SELECT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          COUNT(*),
          COUNT(distinct subject_id)
        FROM mimic2v26.d_chartitems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
        GROUP BY ci.itemid,
                 ci.label,
                 ci.category,
                 ci.description
    , RawData AS (
        SELECT DISTINCT
          ci.itemid,                                                                                                                                                                                           
          ci.label,                                                                                                                                                                                            
          ci.category,                                                                                                                                                                                         
          ci.description,                                                                                                                                                                                      
          last_value(ce.value1) ignore nulls over (partition BY ci.itemid order by                                                                                                                             
          ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS                                                                                                                            
          value1_last                                                                                                                                                                                          
        FROM ChartItems ci                                                                                                                                                                                     
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid                                                                                                                                                 
    select * from RawData                                                                                                                                                                                      
    call     count       cpu    elapsed       disk      query    current        rows                                                                                                                           
    Parse        1      0.02       0.02          0          0          0           0                                                                                                                           
    Execute      1      0.00       0.00          0          0          0           0                                                                                                                           
    Fetch        1    582.40     712.23     705238     737351          0           0                                                                                                                           
    total        3    582.43     712.25     705238     737351          0           0                                                                                                                           
    Misses in library cache during parse: 1                                                                                                                                                                    
    Optimizer mode: ALL_ROWS                                                                                                                                                                                   
    Parsing user id: 85 
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             0          0          0  VIEW  (cr=0 pr=0 pw=0 time=184 us cost=3686387254 size=1361581801333882 card=4811243114254)
             0          0          0   HASH UNIQUE (cr=0 pr=0 pw=0 time=180 us cost=3686387254 size=283863343740986 card=4811243114254)
             0          0          0    WINDOW BUFFER (cr=0 pr=0 pw=0 time=74 us cost=3686387254 size=283863343740986 card=4811243114254)
             0          0          0     SORT GROUP BY (cr=0 pr=0 pw=0 time=59 us cost=3686387254 size=283863343740986 card=4811243114254)
    178073889  178073889  178073889      HASH JOIN  (cr=737351 pr=705238 pw=124635 time=476372451 us cost=25572251 size=283863343740986 card=4811243114254)
       6211631    6211631    6211631       VIEW  VW_DAG_0 (cr=613768 pr=581413 pw=35805 time=286546567 us cost=1366486 size=3354399576 card=152472708)
       6211631    6211631    6211631        HASH GROUP BY (cr=613768 pr=581413 pw=35805 time=281271878 us cost=1366486 size=4421708532 card=152472708)
    196182740  196182740  196182740         HASH JOIN  (cr=613768 pr=545608 pw=0 time=557485047 us cost=147987 size=4421708532 card=152472708)
          4832       4832       4832          TABLE ACCESS FULL D_CHARTITEMS (cr=18 pr=16 pw=0 time=13666 us cost=7 size=96640 card=4832)
    196182740  196182740  196182740          INDEX FAST FULL SCAN CHARTEVENTS_O2 (cr=613750 pr=545592 pw=0 time=148428499 us cost=147046 size=1765644660 card=196182740)(object id 96501)
      10683044   10683044   10683044       TABLE ACCESS FULL CHARTEVENTS (cr=123583 pr=123825 pw=0 time=25175510 us cost=616507 size=7258761380 card=196182740)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
      db file sequential read                         2        0.01          0.01
      db file scattered read                          3        0.02          0.03
      direct path read                             5265        0.75         77.13
      asynch descriptor resize                        1        0.00          0.00
      direct path write temp                      15077        0.71         45.54
      direct path read temp                        2387        0.29         13.54
      SQL*Net break/reset to client                   1        0.66          0.66
      SQL*Net message from client                     1        0.00          0.00
    SQL ID: 7jby2dxrpkkm9 Plan Hash: 1388734953
    select SYS_CONTEXT('USERENV','SESSIONID')
    from
    dual
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.01          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.01          0          0          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 85 
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  FAST DUAL  (cr=0 pr=0 pw=0 time=4 us cost=2 size=0 card=1)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.02       0.04          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch        2    582.40     712.23     705238     737351          0           1
    total        6    582.43     712.27     705238     737351          0           1
    Misses in library cache during parse: 2
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       4        0.00          0.00
      db file sequential read                         2        0.01          0.01
      db file scattered read                          3        0.02          0.03
      direct path read                             5265        0.75         77.13
      asynch descriptor resize                        1        0.00          0.00
      direct path write temp                      15077        0.71         45.54
      direct path read temp                        2387        0.29         13.54
      SQL*Net break/reset to client                   1        0.66          0.66
      SQL*Net message from client                     3       14.99         15.01
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        2  user  SQL statements in session.
        0  internal SQL statements in session.
        2  SQL statements in session.
    Trace file: /oracle/11gr2/app/oracle/diag/rdbms/mimic2/mimic2/trace/mimic2_ora_6507.trc
    Trace file compatibility: 11.1.0.7
    Sort options: default
           1  session in tracefile.
           2  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           2  SQL statements in trace file.
           2  unique SQL statements in trace file.
       24245  lines in trace file.
         728  elapsed seconds in trace file.Optimizer parameters:
    NAME                                               TYPE        VALUE                                                                                               
    optimizer_capture_sql_plan_baselines               boolean     FALSE                                                                                               
    optimizer_dynamic_sampling                         integer     2                                                                                                   
    optimizer_features_enable                          string      11.2.0.3                                                                                            
    optimizer_index_caching                            integer     0                                                                                                   
    optimizer_index_cost_adj                           integer     100                                                                                                 
    optimizer_mode                                     string      ALL_ROWS                                                                                            
    optimizer_secure_view_merging                      boolean     TRUE                                                                                                
    optimizer_use_invisible_indexes                    boolean     FALSE                                                                                               
    optimizer_use_pending_statistics                   boolean     FALSE                                                                                               
    optimizer_use_sql_plan_baselines                   boolean     TRUE                                                                                                 Can anyone help me figure out what's wrong?
    This is a data warehouse, with up to date statistics. The DB is version 11.2.0.3.0
    Thanks,
    Dan

    rp0428 wrote:
    >
    I trimmed the query down to the simplest that I could which still exhibited the problem
    >
    The DISTINCT isn't the issue. The issue is that the query you posted isn't necessary and doesn't appear to be represented in the plan that you posted.
    That makes it hard to tell where the cardinality misestimates are coming from. How many records does the actual first query (the one with the group by) return? You have a SELECT * commented out - how many rows?No, it's not necessary, but then it isn't the full query. The estimates are still wrong when I pass the count columns through to the second query. The full query contains many more analytic functions in the second query, and some additions to the first. It could probably be cleaned up a little, but the current structure makes logical sense. Should I change the aggregates to analytics and move them into the second query? In any case, there definitely seems to be something wrong with the plan.
    I don't know what you mean when you say "doesn't appear to be represented in the plan that you posted".
    I just checked the first query and while the temp space has dropped to a reasonable amount, the number of rows in the hash join is still way off (I didn't notice before because I was looking at the temp space). The rows for d_chartitems and the index on chartevents are correct:
    Plan hash value: 1249235674
    | Id  | Operation               | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT        |                |   152M|    35G|       |  1366K  (1)| 04:33:18 |
    |   1 |  VIEW                   |                |   152M|    35G|       |  1366K  (1)| 04:33:18 |
    |   2 |   WINDOW SORT           |                |   152M|  4216M|  5839M|  1366K  (1)| 04:33:18 |
    |*  3 |    HASH JOIN            |                |   152M|  4216M|       |   147K  (2)| 00:29:36 |
    |   4 |     TABLE ACCESS FULL   | D_CHARTITEMS   |  4832 | 96640 |       |     7   (0)| 00:00:01 |
    |   5 |     INDEX FAST FULL SCAN| CHARTEVENTS_O2 |   196M|  1683M|       |   147K  (1)| 00:29:25 |
    Predicate Information (identified by operation id):
       3 - access("CE"."ITEMID"="CI"."ITEMID")Edited by: danscott on Jul 10, 2012 5:43 PM
    Edited by: danscott on Jul 11, 2012 6:28 AM

  • Query regarding Partition table Explain plan

    Hello,
    We are amidst a tuning activity, wherein a large table has been partitioned for better administration. During testing, I was analyzing the explain plans for long running sql's and found a piece that I was unable to understand. The PSTART and PSTOP columns show ROWID as its value, which in normal partition pruning scenario be the Partition number or the KEY. I tried to look around for this issue but did not get enough information. Can anybody help me of what it means? Also, if there is a good explanation of the same, it will be extremely helpful.
    The snippet from explain plan looks like:
    | Id  | Operation                                | Name                          | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    7 |        TABLE ACCESS BY GLOBAL INDEX ROWID| XXXXXXXXXXXXXXXXXXXX             | 43874 |  9083K|       |  1386   (1)| 00:00:17 | ROWID | ROWID |
    On another similar query it looks like:
    | Id  | Operation                             | Name                         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   6 |     TABLE ACCESS BY GLOBAL INDEX ROWID| XXXXXXXXXXXXXX               | 22455 |  4648K|       |   456   (1)| 00:00:06 |     9 |     9 |
    I have another query with regards to the Partition tables. Does it, require/benefit if, the Indexes to be in partitioned mode? I tried to read about it but did not get a conclusive evidence. I am trying to test it and post here the outcome, but if anybody has experience of working with it, it would be great to have some advice.
    Oracle Version:- 10.2.0.4
    Regards,
    Purvesh.

    Hi Purvesh.
    Great explanation and example on this this topic...
    Ask Tom "explain plan on range-partitioned table"
    Hope this help.

  • Explain plan is different for same query

    Hi all,
    I have a query, which basically selects some columns from a remote database view. The query is as follows:
    select * from tab1@remotedb, tab2@remotedb
    where tab1.cash_id = tab2.id
    and tab1.date = '01-JAN-2003'
    and tab2.country_code = 'GB';
    Now, i am working on two environments, one is production and other is development. Production environment has following specification:
    1. Remotedb = Oracle9i, Linux OS
    2. Database on which query is running = Oracle10g, Linux OS
    Development environment has following specification:
    1. Remotedb = Oracle10g, Windows OS
    2. Database on which query is running = Oracle10g, Linux OS
    Both databases in development and production environments are on different machines.
    when i execute the above query on production, i see full table scans on both tables in execution plan(TOAD), but when i execute the query in development, i see that both remote database tables are using index.
    Why am i getting different execution plans on both databases? is there is any difference of user rights/priviliges or there is a difference of statistics on both databases. I have checked the statistics for both tables on Production and Development databases, they are updated.
    This issue is creating a performance disaster in our Production system. Any kind of help or knowledge sharing is appreciated.
    Thank you and Best Regards.

    select * from tab1@remotedb, tab2@remotedb
    where tab1.cash_id = tab2.id
    and tab1.date = '01-JAN-2003'
    and tab2.country_code = 'GB';
    I assume that tab1.date is a date column. You are doing an implizit type conversion here. I think the way how those conversions are done, was changed from 9i to 10g. So that in 10g index usage is possible, while in 9i is not (not very sure about this).
    Change your query to this:
    select * from tab1@remotedb, tab2@remotedb
    where tab1.cash_id = tab2.id
    and tab1.date = to_date('01-JAN-2003','DD-MON-YYYY')
    and tab2.country_code = 'GB';
    But compare and consider the results. Especially if the column tab1.date holds time values too.
    and tab1.date = to_date('01-JAN-2003','DD-MON-YYYY')is not the same as
    and to_char(tab1.date) = '01-JAN-2003'maybe you must change to
    and tab1.date >= to_date('01-JAN-2003','DD-MON-YYYY')
          and tab1.date < to_date('01-JAN-2003','DD-MON-YYYY') + 1Depends on your data.

  • Upgrade on Family Share Plan Shows Different Dates ?

    I upgraded both phones on my plan exactly 2 years ago this month. My phone (which is the main line) says it's been eligible for an upgrade since September 21 on the other hand the other phone on the plan says it's not eligible for an upgrade until June though they were both upgraded at the same time ? I have an LG EN-V 2 and the other line is a LG Versa. What's the reason for the different dates ?

    The primary line on a Family Share plan is eligible for an annual upgrade after completing 12 months of its 2 year contract.  Secondary lines are only eligible for an upgrade after completing 20 months of the 2 year contract.

  • SQL query - select one row from each date group

    Hi,
    I have data as follows.
    Visit_Date Visit_type Consultant
    05/09/2009 G name1
    05/09/2009 G name2
    05/09/2009 G name3
    06/09/2009 I name4
    07/09/2009 G name5
    07/09/2009 G name6
    How to select data as follows
    05/09/2009 G name1
    06/09/2009 G name4
    07/09/2009 G name5
    i.e one row from every visit_date
    Thanks,
    MK Nathan
    Edited by: k_murali on Oct 7, 2009 10:44 PM

    Are you after this (one row per date per visit_type)
    with dd as (select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name1' Consultant from dual
                union all
                select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name2' Consultant from dual
                union all
                select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name3' Consultant from dual
                union all
                select to_date('06/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name4' Consultant from dual
                union all
                select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name5' Consultant from dual
                union all
                select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name6' Consultant from dual
                union all
                select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'F' Visit_type, 'name7' Consultant from dual)
    select trunc(visit_date) visit_date, visit_type, min(consultant)
    from   dd
    group by trunc(visit_date), visit_type
    order by trunc(visit_date);
    VISIT_DAT V MIN(C
    09/MAY/09 G name1
    09/JUN/09 G name4
    09/JUL/09 G name5
    09/JUL/09 F name7or are you after only one row per date?:
    with dd as (select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name1' Consultant from dual
                union all
                select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name2' Consultant from dual
                union all
                select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name3' Consultant from dual
                union all
                select to_date('06/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name4' Consultant from dual
                union all
                select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name5' Consultant from dual
                union all
                select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name6' Consultant from dual
                union all
                select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'F' Visit_type, 'name7' Consultant from dual)
    select trunc(visit_date) visit_date, min(visit_type) visit_type, min(consultant)
    from   dd
    group by trunc(visit_date)
    order by trunc(visit_date);
    VISIT_DAT V MIN(C
    09/MAY/09 G name1
    09/JUN/09 G name4
    09/JUL/09 F name5

  • Sub Partitioning does not have considerable impact Explain Plan

    Hi Guys,
    I have a table that is list - list sub partitioned on Oracle 11g - 11.2.0.3.
    The first partition is on the CIRCLE_ID column and the second sub partition is on the LOAD_DTTM.
    Now i have tried 2 queries on the database
    1 - select MOBILENUMBER, CLOSING_BAL from GSM_PRR_SUM a1
    where A1.CIRCLE_ID ='AK'
    AND a1.LOAD_DTTM BETWEEN '28-MAR-2012' AND '03-APR-2012';
    2 - select MOBILENUMBER, CLOSING_BAL from GSM_PRR_SUM a1
    where A1.CIRCLE_ID ='AK'
    AND to_char(a1.LOAD_DTTM) like '%MAR%'
    Ideally the 2nd query should take a much higher time than the first query.
    But the explain plan shows a difference of less than 1%.
    Can you pls provide some insights as why Oracle is not understanding that subpartitioning will be faster?
    Thanks,
    Manish

    Hi Dom
    Thanks for your reply.
    Is the first query using partition pruning? - Yes
    Have you gathered stats, etc, etc? - No. All our queries always need to access the entire table and not a particular subset and the where criteria always uses partition and sub partition columns. so we dont see the need to collect stats. Can you pls advise what stats need to be collected and what will be the advantage of those?
    Below are the output of the Explain Plan and Trace Output -
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> show parameter optimizer;
    NAME TYPE VALUE
    optimizer_capture_sql_plan_baselines boolean FALSE
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 11.2.0.3
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 100
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    optimizer_use_invisible_indexes boolean FALSE
    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 cursor_sharing
    NAME TYPE VALUE
    cursor_sharing string EXACT
    SQL> column sname format a20
    SQL> column pname foramt 20
    SP2-0158: unknown COLUMN option "foramt"
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL> select
    2 sname
    3 , pname
    4 , pval1
    5 ,pval2
    6 from sys.aux_stats$;
    from sys.aux_stats$
    ERROR at line 6:
    ORA-00942: table or view does not exist
    SQL> explain plan for
    select MOBILENUMBER, CLOSING_BAL from GSM_PRR_SUM_NEW a1
    where A1.CIRCLE_ID ='KA'
    AND a1.LOAD_DTTM BETWEEN '28-MAR-2012' AND '03-APR-2012'
    SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3032220315
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)
    | Time | Pstart| Pstop |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 41M| 1643M| 548M(100)
    |999:59:59 | | |
    | 1 | PARTITION LIST SINGLE | | 41M| 1643M| 548M(100)
    |999:59:59 | KEY | KEY |
    | 2 | PARTITION LIST ITERATOR| | 41M| 1643M| 548M(100)
    |999:59:59 | KEY | KEY |
    | 3 | TABLE ACCESS FULL | GSM_PRR_SUM_NEW | 41M| 1643M| 548M(100)
    |999:59:59 | KEY | KEY |
    PLAN_TABLE_OUTPUT
    Note
    - dynamic sampling used for this statement (level=2)
    14 rows selected.
    SQL> explain plan for
    select MOBILENUMBER, CLOSING_BAL from GSM_PRR_SUM_NEW a1
    where A1.CIRCLE_ID ='KA'
    AND to_char(a1.LOAD_DTTM) like '%MAR%';
    2 3 4
    Explained.
    SQL> SQL> SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT
    Plan hash value: 189546713
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
    ime | Pstart| Pstop |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 62M| 2521M| 5435M(100)|99
    9:59:59 | | |
    | 1 | PARTITION LIST SINGLE| | 62M| 2521M| 5435M(100)|99
    9:59:59 | KEY | KEY |
    | 2 | PARTITION LIST ALL | | 62M| 2521M| 5435M(100)|99
    9:59:59 | 1 | 305 |
    |* 3 | TABLE ACCESS FULL | GSM_PRR_SUM_NEW | 62M| 2521M| 5435M(100)|99
    9:59:59 | KEY | KEY |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    3 - filter(TO_CHAR(INTERNAL_FUNCTION("A1"."LOAD_DTTM")) LIKE '%MAR%')
    Note
    PLAN_TABLE_OUTPUT
    - dynamic sampling used for this statement (level=2)
    19 rows selected.
    SQL>
    SQL> SET AUTOTRACE TRACEONLY ARRAYSIZE 100
    SQL> select MOBILENUMBER, CLOSING_BAL from GSM_PRR_SUM_NEW a1
    where A1.CIRCLE_ID ='KA'
    AND a1.LOAD_DTTM BETWEEN '28-MAR-2012' AND '03-APR-2012' 2 3 ;
    49637012 rows selected.
    Execution Plan
    Plan hash value: 3032220315
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)
    | Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 41M| 1643M| 546M(100)
    |999:59:59 | | |
    | 1 | PARTITION LIST SINGLE | | 41M| 1643M| 546M(100)
    |999:59:59 | KEY | KEY |
    | 2 | PARTITION LIST ITERATOR| | 41M| 1643M| 546M(100)
    |999:59:59 | KEY | KEY |
    | 3 | TABLE ACCESS FULL | GSM_PRR_SUM_NEW | 41M| 1643M| 546M(100)
    |999:59:59 | KEY | KEY |
    Note
    - dynamic sampling used for this statement (level=2)
    Statistics
    0 recursive calls
    7 db block gets
    530220 consistent gets
    33636 physical reads
    0 redo size
    644311477 bytes sent via SQL*Net to client
    5460594 bytes received via SQL*Net from client
    496372 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    49637012 rows processed
    SQL> SET AUTOTRACE TRACEONLY ARRAYSIZE 100
    SQL> select MOBILENUMBER, CLOSING_BAL from GSM_PRR_SUM_NEW a1
    where A1.CIRCLE_ID ='KA'
    AND to_char(a1.LOAD_DTTM) like '%MAR%' 2 3
    4 ;
    219166976 rows selected.
    Execution Plan
    Plan hash value: 189546713
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
    ime | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 228M| 9155M| 3552M(100)|99
    9:59:59 | | |
    | 1 | PARTITION LIST SINGLE| | 228M| 9155M| 3552M(100)|99
    9:59:59 | KEY | KEY |
    | 2 | PARTITION LIST ALL | | 228M| 9155M| 3552M(100)|99
    9:59:59 | 1 | 274 |
    |* 3 | TABLE ACCESS FULL | GSM_PRR_SUM_NEW | 228M| 9155M| 3552M(100)|99
    9:59:59 | KEY | KEY |
    Predicate Information (identified by operation id):
    3 - filter(TO_CHAR(INTERNAL_FUNCTION("A1"."LOAD_DTTM")) LIKE '%MAR%')
    Note
    - dynamic sampling used for this statement (level=2)
    Statistics
    38 recursive calls
    107 db block gets
    2667792 consistent gets
    561765 physical reads
    0 redo size
    2841422984 bytes sent via SQL*Net to client
    24108883 bytes received via SQL*Net from client
    2191671 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    219166976 rows processed
    SQL>
    Thanks,
    Manish

  • Hi when i run this in toad for explain plan  its showing an error ORA_22905

    hi when i run this query in toad for explain plan its showing an error ORA_22905 cannot accesss rows from an non nested table item can anyone help me out
    SELECT
    DISTINCT SERVICE_TBL.SERVICE_ID , SERVICE_TBL.CON_TYPE, SERVICE_TBL.S_DESC || '(' || SERVICE_TBL.CON_TYPE || ')' AS SERVICE_DESC ,SERVICE_TBL.CON_STAT
    FROM
    TABLE(:B1 )SERVICE_TBL
    WHERE
    CON_NUM = :B2
    thanks

    Note the name of this forum is SQL Developer *(Not for general SQL/PLSQL questions)* (so for issues with the SQL Developer tool). Please post these questions under the dedicated SQL And PL/SQL forum.
    Regards,
    K.

  • Explain Plan Differing

    The below same query runs fast at PL/SQL , while the same query run from front end (EBS R 12.0.4) using concurrent request runs verl slow , both has diffrent plan , please share some thought.
    Below query when i run from backend (PL/SQL Developer) it returns row within a second
    SELECT /*+ gather_plan_statistics product_item_2.txt */ OH.ORG_ID,BUNIT.BU_ID,OL.INVENTORY_ITEM_ID,CUST.account_number,CUST.ACCOUNT_NAME,CUST.CUSTOMER_CLASS_CODE,
    NVL(SUM(OL.FULFILLED_QUANTITY),0) as sale_qty
    FROM
    OE_ORDER_HEADERS_ALL OH,OE_ORDER_LINES_ALL OL,
    HZ_CUST_ACCOUNTS CUST,mtl_categories_vl CAT,
    mtl_item_categories IC,(select FLEX_VALUE BU_ID,DESCRIPTION B_NAME from fnd_flex_values_vl t
         where t.FLEX_VALUE_SET_ID ='1012990') BUNIT
    WHERE OH.HEADER_ID = OL.HEADER_ID
    AND CUST.CUST_ACCOUNT_ID  =
    (SELECT DISTINCT ACCT.CUST_ACCOUNT_ID
    FROM HZ_CUST_ACCOUNTS ACCT,HZ_CUST_ACCT_SITES_ALL ACCT_SITE,
    HZ_LOCATIONS LOC,HZ_PARTY_SITES PARTY_SITE,
    HZ_CUST_SITE_USES_ALL SUSE,HZ_PARTIES P
    WHERE ACCT.PARTY_ID = PARTY_SITE.PARTY_ID
    AND   ACCT.CUST_ACCOUNT_ID = ACCT_SITE.CUST_ACCOUNT_ID
    AND   SUSE.CUST_ACCT_SITE_ID = ACCT_SITE.CUST_ACCT_SITE_ID
    AND   ACCT_SITE.PARTY_SITE_ID  = PARTY_SITE.PARTY_SITE_ID
    AND   LOC.LOCATION_ID = PARTY_SITE.LOCATION_ID
    AND   SUSE.SITE_USE_ID = OL.SHIP_TO_ORG_ID
    AND  P.PARTY_ID = ACCT.PARTY_ID
    AND P.PARTY_ID = PARTY_SITE.PARTY_ID
    AND   SUSE.SITE_USE_CODE = 'SHIP_TO'
    AND ACCT_SITE.ORG_ID = &P_ORG_ID
    AND OH.ORG_ID = &P_ORG_ID
    AND OL.ACTUAL_SHIPMENT_DATE BETWEEN &P_FROM_DATE AND &P_TO_DATE
    AND OL.UNIT_SELLING_PRICE != 0
    AND OL.LINE_CATEGORY_CODE = 'ORDER'
    AND OL.ORDERED_ITEM = NVL(&ITEM_HIGH, OL.ORDERED_ITEM)
    AND BUNIT.BU_ID = nvl(&p_business_unit,bunit.bu_id)
    AND CAT.CATEGORY_ID   =   IC.CATEGORY_ID
    AND CAT.STRUCTURE_ID = 50289
    AND IC.INVENTORY_ITEM_ID = OL.INVENTORY_ITEM_ID
    AND IC.ORGANIZATION_ID   = OH.SHIP_FROM_ORG_ID     
    and     cat.SEGMENT3  =  BUNIT.BU_ID 
    GROUP BY                            
    OH.ORG_ID,BUNIT.BU_ID,OL.INVENTORY_ITEM_ID,CUST.account_number,CUST.ACCOUNT_NAME,CUST.CUSTOMER_CLASS_CODE
    ORDER BY 1Plan for above query is as follows
    SQL> set pagesize 1000
    SQL> /
    PLAN_TABLE_OUTPUT                                                                                                                                                                                      
    SQL_ID  5g71mvqaat8x3, child number 0                                                                                                                                                                  
    Plan hash value: 610424373                                                                                                                                                                             
    | Id  | Operation                             | Name                   | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   1 |  HASH GROUP BY                        |                        |      1 |      1 |      2 |00:00:00.64 |     144K|       |       |          |
    |   2 |   NESTED LOOPS                        |                        |      1 |      1 |     71 |00:00:00.30 |     144K|       |       |          |
    |   3 |    NESTED LOOPS                       |                        |      1 |      1 |   1704 |00:00:00.26 |     138K|       |       |          |
    |*  4 |     HASH JOIN                         |                        |      1 |      1 |   3312 |00:00:00.05 |     132K|   887K|   887K| 1236K (0)|
    |   5 |      TABLE ACCESS BY INDEX ROWID      | MTL_ITEM_CATEGORIES    |      1 |    506 |   1075 |00:00:00.02 |     361 |       |       |          |
    |   6 |       NESTED LOOPS                    |                        |      1 |      1 |   1077 |00:00:00.04 |      24 |       |       |          |
    |   7 |        NESTED LOOPS                   |                        |      1 |      1 |      1 |00:00:00.01 |      19 |       |       |          |
    |   8 |         NESTED LOOPS                  |                        |      1 |      1 |      1 |00:00:00.01 |      18 |       |       |          |
    |   9 |          NESTED LOOPS                 |                        |      1 |      1 |      1 |00:00:00.01 |      15 |       |       |          |
    |* 10 |           TABLE ACCESS BY INDEX ROWID | FND_FLEX_VALUES        |      1 |      1 |      1 |00:00:00.01 |      13 |       |       |          |
    |* 11 |            INDEX RANGE SCAN           | IDX$$_65860003         |      1 |     22 |     52 |00:00:00.01 |       2 |       |       |          |
    |* 12 |           INDEX UNIQUE SCAN           | FND_FLEX_VALUES_TL_U1  |      1 |      1 |      1 |00:00:00.01 |       2 |       |       |          |
    |* 13 |          TABLE ACCESS BY INDEX ROWID  | MTL_CATEGORIES_B       |      1 |      1 |      1 |00:00:00.01 |       3 |       |       |          |
    |* 14 |           INDEX RANGE SCAN            | IDX$$_79530001         |      1 |      1 |      2 |00:00:00.01 |       1 |       |       |          |
    |* 15 |         INDEX UNIQUE SCAN             | MTL_CATEGORIES_TL_U1   |      1 |      1 |      1 |00:00:00.01 |       1 |       |       |          |
    |* 16 |        INDEX RANGE SCAN               | IDX$$_78250002         |      1 |   1528 |   1075 |00:00:00.01 |       5 |       |       |          |
    |* 17 |      TABLE ACCESS BY INDEX ROWID      | OE_ORDER_LINES_ALL     |      1 |     51 |    138 |00:00:00.01 |     132K|       |       |          |
    |* 18 |       INDEX SKIP SCAN                 | OE_ORDER_LINES_N26     |      1 |  14977 |    113K|00:00:00.57 |    1208 |       |       |          |
    |  19 |     TABLE ACCESS BY INDEX ROWID       | HZ_CUST_ACCOUNTS       |   3312 |      1 |   1704 |00:00:00.09 |    5188 |       |       |          |
    |* 20 |      INDEX UNIQUE SCAN                | HZ_CUST_ACCOUNTS_U1    |   3312 |      1 |   1704 |00:00:00.04 |    3484 |       |       |          |
    |  21 |       NESTED LOOPS                    |                        |      8 |      1 |      2 |00:00:00.01 |      76 |       |       |          |
    |  22 |        NESTED LOOPS                   |                        |      8 |      1 |      2 |00:00:00.01 |      72 |       |       |          |
    |  23 |         NESTED LOOPS                  |                        |      8 |      1 |      2 |00:00:00.01 |      66 |       |       |          |
    |  24 |          NESTED LOOPS                 |                        |      8 |      1 |      2 |00:00:00.01 |      62 |       |       |          |
    |  25 |           NESTED LOOPS                |                        |      8 |      1 |      2 |00:00:00.01 |      56 |       |       |          |
    |* 26 |            TABLE ACCESS BY INDEX ROWID| HZ_CUST_SITE_USES_ALL  |      8 |      1 |      8 |00:00:00.01 |      32 |       |       |          |
    |* 27 |             INDEX UNIQUE SCAN         | HZ_CUST_SITE_USES_U1   |      8 |      1 |      8 |00:00:00.01 |      24 |       |       |          |
    |* 28 |            TABLE ACCESS BY INDEX ROWID| HZ_CUST_ACCT_SITES_ALL |      8 |  25087 |      2 |00:00:00.01 |      24 |       |       |          |
    |* 29 |             INDEX UNIQUE SCAN         | HZ_CUST_ACCT_SITES_U1  |      8 |      1 |      8 |00:00:00.01 |      16 |       |       |          |
    |  30 |           TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCOUNTS       |      2 |    176K|      2 |00:00:00.01 |       6 |       |       |          |
    |* 31 |            INDEX UNIQUE SCAN          | HZ_CUST_ACCOUNTS_U1    |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |* 32 |          INDEX UNIQUE SCAN            | HZ_PARTIES_U1          |      2 |    176K|      2 |00:00:00.01 |       4 |       |       |          |
    |* 33 |         TABLE ACCESS BY INDEX ROWID   | HZ_PARTY_SITES         |      2 |    188K|      2 |00:00:00.01 |       6 |       |       |          |
    |* 34 |          INDEX UNIQUE SCAN            | HZ_PARTY_SITES_U1      |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |* 35 |        INDEX UNIQUE SCAN              | HZ_LOCATIONS_U1        |      2 |    174K|      2 |00:00:00.01 |       4 |       |       |          |
    |* 36 |    TABLE ACCESS BY INDEX ROWID        | OE_ORDER_HEADERS_ALL   |   1704 |      1 |     71 |00:00:00.05 |    6816 |       |       |          |
    |* 37 |     INDEX UNIQUE SCAN                 | OE_ORDER_HEADERS_U1    |   1704 |      1 |   1704 |00:00:00.03 |    5112 |       |       |          |
    Predicate Information (identified by operation id):
       4 - access("IC"."INVENTORY_ITEM_ID"="OL"."INVENTORY_ITEM_ID")
      10 - filter("B"."FLEX_VALUE"=NVL('02',"B"."FLEX_VALUE"))
      11 - access("B"."FLEX_VALUE_SET_ID"=1012990)
      12 - access("B"."FLEX_VALUE_ID"="T"."FLEX_VALUE_ID" AND "T"."LANGUAGE"=USERENV('LANG'))
      13 - filter("B"."STRUCTURE_ID"=50289)
      14 - access("B"."SEGMENT3"="B"."FLEX_VALUE")
           filter("B"."SEGMENT3" IS NOT NULL)
      15 - access("B"."CATEGORY_ID"="T"."CATEGORY_ID" AND "T"."LANGUAGE"=USERENV('LANG'))
      16 - access("B"."CATEGORY_ID"="IC"."CATEGORY_ID")
      17 - filter(("OL"."ORDERED_ITEM"=NVL('101468',"OL"."ORDERED_ITEM") AND "OL"."UNIT_SELLING_PRICE"<>0))
      18 - access("OL"."LINE_CATEGORY_CODE"='ORDER' AND "OL"."ACTUAL_SHIPMENT_DATE">=TO_DATE('2012-02-20 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND
                  "OL"."ACTUAL_SHIPMENT_DATE"<=TO_DATE('2012-02-23 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))
           filter(("OL"."ACTUAL_SHIPMENT_DATE">=TO_DATE('2012-02-20 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND "OL"."LINE_CATEGORY_CODE"='ORDER'
                  AND "OL"."ACTUAL_SHIPMENT_DATE"<=TO_DATE('2012-02-23 00:00:00', 'yyyy-mm-dd hh24:mi:ss')))
      20 - access("CUST"."CUST_ACCOUNT_ID"=)
      26 - filter("SUSE"."SITE_USE_CODE"='SHIP_TO')
      27 - access("SUSE"."SITE_USE_ID"=:B1)
      28 - filter("ACCT_SITE"."ORG_ID"=142)
      29 - access("SUSE"."CUST_ACCT_SITE_ID"="ACCT_SITE"."CUST_ACCT_SITE_ID")
      31 - access("ACCT"."CUST_ACCOUNT_ID"="ACCT_SITE"."CUST_ACCOUNT_ID")
      32 - access("P"."PARTY_ID"="ACCT"."PARTY_ID")
      33 - filter(("ACCT"."PARTY_ID"="PARTY_SITE"."PARTY_ID" AND "P"."PARTY_ID"="PARTY_SITE"."PARTY_ID"))
      34 - access("ACCT_SITE"."PARTY_SITE_ID"="PARTY_SITE"."PARTY_SITE_ID")
      35 - access("LOC"."LOCATION_ID"="PARTY_SITE"."LOCATION_ID")
      36 - filter(("OH"."ORG_ID"=142 AND "IC"."ORGANIZATION_ID"="OH"."SHIP_FROM_ORG_ID"))
      37 - access("OH"."HEADER_ID"="OL"."HEADER_ID")
    85 rows selected.Below plan for the above same query when i run from front end concurrent request it completed within an hour.
    SQL> select * from table(dbms_xplan.display_cursor('1gnb26b0q2vxx',NULL,'ALLSTATS LAST'))
      2  /
    PLAN_TABLE_OUTPUT
    SQL_ID  1gnb26b0q2vxx, child number 0
    Plan hash value: 408306916
    | Id  | Operation                              | Name                           | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   1 |  HASH GROUP BY                         |                                |      1 |      1 |      2 |00:36:41.83 |     379M|       |       |          |
    |   2 |   CONCATENATION                        |                                |      1 |        |     71 |00:09:30.14 |     379M|       |       |          |
    |*  3 |    FILTER                              |                                |      1 |        |      0 |00:00:00.01 |       0 |       |       |          |
    |   4 |     NESTED LOOPS                       |                                |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |   5 |      NESTED LOOPS                      |                                |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |*  6 |       HASH JOIN                        |                                |      0 |      4 |      0 |00:00:00.01 |       0 |   715K|   715K|          |
    |   7 |        TABLE ACCESS BY INDEX ROWID     | MTL_ITEM_CATEGORIES            |      0 |    506 |      0 |00:00:00.01 |       0 |       |       |          |
    |   8 |         NESTED LOOPS                   |                                |      0 |     26 |      0 |00:00:00.01 |       0 |       |       |          |
    |   9 |          NESTED LOOPS                  |                                |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |  10 |           NESTED LOOPS                 |                                |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |  11 |            NESTED LOOPS                |                                |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 12 |             TABLE ACCESS BY INDEX ROWID| FND_FLEX_VALUES                |      0 |     22 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 13 |              INDEX RANGE SCAN          | IDX$$_65860003                 |      0 |     22 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 14 |             TABLE ACCESS BY INDEX ROWID| MTL_CATEGORIES_B               |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 15 |              INDEX RANGE SCAN          | MTL_CATEGORIES_B_N3            |      0 |      2 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 16 |            INDEX UNIQUE SCAN           | FND_FLEX_VALUES_TL_U1          |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 17 |           INDEX UNIQUE SCAN            | MTL_CATEGORIES_TL_U1           |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 18 |          INDEX RANGE SCAN              | IDX$$_78250002                 |      0 |   1528 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 19 |        TABLE ACCESS FULL               | OE_ORDER_LINES_ALL             |      0 |     97 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 20 |       TABLE ACCESS BY INDEX ROWID      | OE_ORDER_HEADERS_ALL           |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 21 |        INDEX UNIQUE SCAN               | OE_ORDER_HEADERS_U1            |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |  22 |      TABLE ACCESS BY INDEX ROWID       | HZ_CUST_ACCOUNTS               |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |* 23 |       INDEX UNIQUE SCAN                | HZ_CUST_ACCOUNTS_U1            |      0 |      1 |      0 |00:00:00.01 |       0 |       |       |          |
    |  24 |        NESTED LOOPS                    |                                |      2 |      1 |      2 |00:00:00.01 |      34 |       |       |          |
    |  25 |         NESTED LOOPS                   |                                |      2 |      1 |      2 |00:00:00.01 |      30 |       |       |          |
    |  26 |          NESTED LOOPS                  |                                |      2 |      1 |      2 |00:00:00.01 |      24 |       |       |          |
    |  27 |           NESTED LOOPS                 |                                |      2 |      1 |      2 |00:00:00.01 |      20 |       |       |          |
    |  28 |            NESTED LOOPS                |                                |      2 |      1 |      2 |00:00:00.01 |      14 |       |       |          |
    |* 29 |             TABLE ACCESS BY INDEX ROWID| HZ_CUST_SITE_USES_ALL          |      2 |      1 |      2 |00:00:00.01 |       8 |       |       |          |
    |* 30 |              INDEX UNIQUE SCAN         | HZ_CUST_SITE_USES_U1           |      2 |      1 |      2 |00:00:00.01 |       6 |       |       |          |
    |* 31 |             TABLE ACCESS BY INDEX ROWID| HZ_CUST_ACCT_SITES_ALL         |      2 |   9420 |      2 |00:00:00.01 |       6 |       |       |          |
    |* 32 |              INDEX UNIQUE SCAN         | HZ_CUST_ACCT_SITES_U1          |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |  33 |            TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCOUNTS               |      2 |    176K|      2 |00:00:00.01 |       6 |       |       |          |
    |* 34 |             INDEX UNIQUE SCAN          | HZ_CUST_ACCOUNTS_U1            |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |* 35 |           INDEX UNIQUE SCAN            | HZ_PARTIES_U1                  |      2 |    176K|      2 |00:00:00.01 |       4 |       |       |          |
    |* 36 |          TABLE ACCESS BY INDEX ROWID   | HZ_PARTY_SITES                 |      2 |    188K|      2 |00:00:00.01 |       6 |       |       |          |
    |* 37 |           INDEX UNIQUE SCAN            | HZ_PARTY_SITES_U1              |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |* 38 |         INDEX UNIQUE SCAN              | HZ_LOCATIONS_U1                |      2 |    174K|      2 |00:00:00.01 |       4 |       |       |          |
    |* 39 |    FILTER                              |                                |      1 |        |     71 |00:09:30.14 |     379M|       |       |          |
    |  40 |     NESTED LOOPS                       |                                |      1 |      1 |     71 |00:09:30.14 |     379M|       |       |          |
    |  41 |      NESTED LOOPS                      |                                |      1 |      1 |     71 |00:09:30.11 |     379M|       |       |          |
    |  42 |       NESTED LOOPS                     |                                |      1 |     18 |     16M|00:03:49.48 |      34M|       |       |          |
    |  43 |        NESTED LOOPS                    |                                |      1 |      1 |   1075 |00:00:00.03 |     351 |       |       |          |
    |  44 |         NESTED LOOPS                   |                                |      1 |      1 |      1 |00:00:00.01 |       9 |       |       |          |
    |  45 |          NESTED LOOPS                  |                                |      1 |      1 |      1 |00:00:00.01 |       8 |       |       |          |
    |  46 |           NESTED LOOPS                 |                                |      1 |      1 |      1 |00:00:00.01 |       6 |       |       |          |
    |  47 |            TABLE ACCESS BY INDEX ROWID | FND_FLEX_VALUES                |      1 |      1 |      1 |00:00:00.01 |       3 |       |       |          |
    |* 48 |             INDEX RANGE SCAN           | FND_FLEX_VALUES_N4             |      1 |      1 |      1 |00:00:00.01 |       2 |       |       |          |
    |* 49 |            TABLE ACCESS BY INDEX ROWID | MTL_CATEGORIES_B               |      1 |      1 |      1 |00:00:00.01 |       3 |       |       |          |
    |* 50 |             INDEX RANGE SCAN           | IDX$$_79530001                 |      1 |      1 |      2 |00:00:00.01 |       1 |       |       |          |
    |* 51 |           INDEX UNIQUE SCAN            | FND_FLEX_VALUES_TL_U1          |      1 |      1 |      1 |00:00:00.01 |       2 |       |       |          |
    |* 52 |          INDEX UNIQUE SCAN             | MTL_CATEGORIES_TL_U1           |      1 |      1 |      1 |00:00:00.01 |       1 |       |       |          |
    |  53 |         TABLE ACCESS BY INDEX ROWID    | MTL_ITEM_CATEGORIES            |      1 |    506 |   1075 |00:00:00.02 |     342 |       |       |          |
    |* 54 |          INDEX RANGE SCAN              | IDX$$_78250002                 |      1 |   1528 |   1075 |00:00:00.01 |       5 |       |       |          |
    |* 55 |        TABLE ACCESS BY INDEX ROWID     | OE_ORDER_HEADERS_ALL           |   1075 |   6485 |     16M|00:12:38.97 |      34M|       |       |          |
    |* 56 |         INDEX RANGE SCAN               | OE_ORDER_HEADER_ALL_ORG_ID_NDX |   1075 |    141K|    394M|00:19:52.50 |    2141K|       |       |          |
    |* 57 |       TABLE ACCESS BY INDEX ROWID      | OE_ORDER_LINES_ALL             |     16M|      1 |     71 |00:23:47.72 |     345M|       |       |          |
    |* 58 |        INDEX RANGE SCAN                | OE_ORDER_LINES_N21             |     16M|      6 |    108M|00:08:35.98 |      32M|       |       |          |
    |  59 |      TABLE ACCESS BY INDEX ROWID       | HZ_CUST_ACCOUNTS               |     71 |      1 |     71 |00:00:00.01 |     247 |       |       |          |
    |* 60 |       INDEX UNIQUE SCAN                | HZ_CUST_ACCOUNTS_U1            |     71 |      1 |     71 |00:00:00.01 |     176 |       |       |          |
    |  61 |        NESTED LOOPS                    |                                |      2 |      1 |      2 |00:00:00.01 |      34 |       |       |          |
    |  62 |         NESTED LOOPS                   |                                |      2 |      1 |      2 |00:00:00.01 |      30 |       |       |          |
    |  63 |          NESTED LOOPS                  |                                |      2 |      1 |      2 |00:00:00.01 |      24 |       |       |          |
    |  64 |           NESTED LOOPS                 |                                |      2 |      1 |      2 |00:00:00.01 |      20 |       |       |          |
    |  65 |            NESTED LOOPS                |                                |      2 |      1 |      2 |00:00:00.01 |      14 |       |       |          |
    |* 66 |             TABLE ACCESS BY INDEX ROWID| HZ_CUST_SITE_USES_ALL          |      2 |      1 |      2 |00:00:00.01 |       8 |       |       |          |
    |* 67 |              INDEX UNIQUE SCAN         | HZ_CUST_SITE_USES_U1           |      2 |      1 |      2 |00:00:00.01 |       6 |       |       |          |
    |* 68 |             TABLE ACCESS BY INDEX ROWID| HZ_CUST_ACCT_SITES_ALL         |      2 |   9420 |      2 |00:00:00.01 |       6 |       |       |          |
    |* 69 |              INDEX UNIQUE SCAN         | HZ_CUST_ACCT_SITES_U1          |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |  70 |            TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCOUNTS               |      2 |    176K|      2 |00:00:00.01 |       6 |       |       |          |
    |* 71 |             INDEX UNIQUE SCAN          | HZ_CUST_ACCOUNTS_U1            |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |* 72 |           INDEX UNIQUE SCAN            | HZ_PARTIES_U1                  |      2 |    176K|      2 |00:00:00.01 |       4 |       |       |          |
    |* 73 |          TABLE ACCESS BY INDEX ROWID   | HZ_PARTY_SITES                 |      2 |    188K|      2 |00:00:00.01 |       6 |       |       |          |
    |* 74 |           INDEX UNIQUE SCAN            | HZ_PARTY_SITES_U1              |      2 |      1 |      2 |00:00:00.01 |       4 |       |       |          |
    |* 75 |         INDEX UNIQUE SCAN              | HZ_LOCATIONS_U1                |      2 |    174K|      2 |00:00:00.01 |       4 |       |       |          |
    Predicate Information (identified by operation id):
       3 - filter((:P_FROM_DATE<=:P_TO_DATE AND :P_BUSINESS_UNIT IS NULL))
       6 - access("IC"."INVENTORY_ITEM_ID"="OL"."INVENTORY_ITEM_ID")
      12 - filter("B"."FLEX_VALUE" IS NOT NULL)
      13 - access("B"."FLEX_VALUE_SET_ID"=1012990)
      14 - filter("B"."STRUCTURE_ID"=50289)
      15 - access("B"."SEGMENT3"="B"."FLEX_VALUE")
           filter("B"."SEGMENT3" IS NOT NULL)
      16 - access("B"."FLEX_VALUE_ID"="T"."FLEX_VALUE_ID" AND "T"."LANGUAGE"=USERENV('LANG'))
      17 - access("B"."CATEGORY_ID"="T"."CATEGORY_ID" AND "T"."LANGUAGE"=USERENV('LANG'))
      18 - access("B"."CATEGORY_ID"="IC"."CATEGORY_ID")
      19 - filter(("OL"."ACTUAL_SHIPMENT_DATE">=:P_FROM_DATE AND "OL"."ACTUAL_SHIPMENT_DATE"<=:P_TO_DATE AND
                  "OL"."ORDERED_ITEM"=NVL(:ITEM_HIGH,"OL"."ORDERED_ITEM") AND "OL"."LINE_CATEGORY_CODE"='ORDER' AND "OL"."UNIT_SELLING_PRICE"<>0))
      20 - filter(("OH"."ORG_ID"=:P_ORG_ID AND "IC"."ORGANIZATION_ID"="OH"."SHIP_FROM_ORG_ID"))
      21 - access("OH"."HEADER_ID"="OL"."HEADER_ID")
      23 - access("CUST"."CUST_ACCOUNT_ID"=)
      29 - filter("SUSE"."SITE_USE_CODE"='SHIP_TO')
      30 - access("SUSE"."SITE_USE_ID"=:B1)
      31 - filter("ACCT_SITE"."ORG_ID"=:P_ORG_ID)
      32 - access("SUSE"."CUST_ACCT_SITE_ID"="ACCT_SITE"."CUST_ACCT_SITE_ID")
      34 - access("ACCT"."CUST_ACCOUNT_ID"="ACCT_SITE"."CUST_ACCOUNT_ID")
      35 - access("P"."PARTY_ID"="ACCT"."PARTY_ID")
      36 - filter(("ACCT"."PARTY_ID"="PARTY_SITE"."PARTY_ID" AND "P"."PARTY_ID"="PARTY_SITE"."PARTY_ID"))
      37 - access("ACCT_SITE"."PARTY_SITE_ID"="PARTY_SITE"."PARTY_SITE_ID")
      38 - access("LOC"."LOCATION_ID"="PARTY_SITE"."LOCATION_ID")
      39 - filter((:P_FROM_DATE<=:P_TO_DATE AND :P_BUSINESS_UNIT IS NOT NULL))
      48 - access("B"."FLEX_VALUE"=:P_BUSINESS_UNIT AND "B"."FLEX_VALUE_SET_ID"=1012990)
      49 - filter("B"."STRUCTURE_ID"=50289)
      50 - access("B"."SEGMENT3"="B"."FLEX_VALUE")
           filter("B"."SEGMENT3" IS NOT NULL)
      51 - access("B"."FLEX_VALUE_ID"="T"."FLEX_VALUE_ID" AND "T"."LANGUAGE"=USERENV('LANG'))
      52 - access("B"."CATEGORY_ID"="T"."CATEGORY_ID" AND "T"."LANGUAGE"=USERENV('LANG'))
      54 - access("B"."CATEGORY_ID"="IC"."CATEGORY_ID")
      55 - filter("IC"."ORGANIZATION_ID"="OH"."SHIP_FROM_ORG_ID")
      56 - access("OH"."ORG_ID"=:P_ORG_ID)
      57 - filter(("OL"."ACTUAL_SHIPMENT_DATE">=:P_FROM_DATE AND "OL"."ACTUAL_SHIPMENT_DATE"<=:P_TO_DATE AND
                  "OL"."ORDERED_ITEM"=NVL(:ITEM_HIGH,"OL"."ORDERED_ITEM") AND "OL"."LINE_CATEGORY_CODE"='ORDER' AND "OL"."UNIT_SELLING_PRICE"<>0 AND
                  "IC"."INVENTORY_ITEM_ID"="OL"."INVENTORY_ITEM_ID"))
      58 - access("OH"."HEADER_ID"="OL"."HEADER_ID")
      60 - access("CUST"."CUST_ACCOUNT_ID"=)
      66 - filter("SUSE"."SITE_USE_CODE"='SHIP_TO')
      67 - access("SUSE"."SITE_USE_ID"=:B1)
      68 - filter("ACCT_SITE"."ORG_ID"=:P_ORG_ID)
      69 - access("SUSE"."CUST_ACCT_SITE_ID"="ACCT_SITE"."CUST_ACCT_SITE_ID")
      71 - access("ACCT"."CUST_ACCOUNT_ID"="ACCT_SITE"."CUST_ACCOUNT_ID")
      72 - access("P"."PARTY_ID"="ACCT"."PARTY_ID")
      73 - filter(("ACCT"."PARTY_ID"="PARTY_SITE"."PARTY_ID" AND "P"."PARTY_ID"="PARTY_SITE"."PARTY_ID"))
      74 - access("ACCT_SITE"."PARTY_SITE_ID"="PARTY_SITE"."PARTY_SITE_ID")
      75 - access("LOC"."LOCATION_ID"="PARTY_SITE"."LOCATION_ID")                                                                                                                                                                                                       
    145 rows selected.one thing looking strange at predicate section at line 23 and 60 access("CUST"."CUST_ACCOUNT_ID"=),Plan is also differing why?

    Just look at filter predicates 3 and 39 which I highlighted previously.
    With a query using bind variable, p_business_unit might be supplied with a null value and therefore two possible paths exist in the CONCATENTATION plan to cope with those possibilities (and the possibility that P_FROM_DATE is not <= P_TO_DATE).
    If instead of using bind variable you supply a literal - i.e. '101468' - then the optimizer doesn't not have to worry about the fact that '101468' might be null. As far as this piece of SQL is concerned, it's a constant.
    Therefore you shouldn't compare SQL that runs with binds with SQl that runs with literals, particularly where the sql involves conditional predicates.
    To use a simplification, consider the difference here:
    SQL> explain plan for
      2  select 1 from dual where 1 = nvl(1,1);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1388734953
    | Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     1 |     2   (0)| 00:00:01 |
    |   1 |  FAST DUAL       |      |     1 |     2   (0)| 00:00:01 |
    8 rows selected.
    SQL>  explain plan for
      2   select 1 from dual where 1 = nvl(:1,1);
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 4034615273
    | Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     1 |     2   (0)| 00:00:01 |
    |*  1 |  FILTER          |      |       |            |          |
    |   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(NVL(:1,1)=1)
    14 rows selected.Furthermore, to emphasis my point about substition variables (&variable_name) consider this:
    SQL> explain plan for
      2  select 1 from dual where 1 = nvl(&1,1);
    Enter value for 1: 1
    Explained.
    SQL>  select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1388734953
    | Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     1 |     2   (0)| 00:00:01 |
    |   1 |  FAST DUAL       |      |     1 |     2   (0)| 00:00:01 |
    8 rows selected.
    SQL> Does the substitution variable behave like a bind variable or like a literal?
    A literal, because that's what it is. Substituted in before the statement is sent to the database and parsed.

  • 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

  • 'Identical' schemas on different servers - different explain plan costs

    Hello,
    I have two servers, 1 development and 1 production. I have a query which produces wildly different explain plan costs on the two servers:
    The development server provides a cost of just over 800 and the production servers is over 100000. I have 2-3 different versions of the schema (These are data warehouse schemas) on both servers and the cost numbers are similar regardless of the version used. Whenever I run the query on development, it's around 800. On production the same query is over 100000.
    The data on both servers is (should be) identical - I used impdp and expdp to transfer the data between the servers. I have run:
    DBMS_STATS.GATHER_SCHEMA_STATS ('SCHEMAV26', cascade=>TRUE);
    on the production server after importing the data. As far as I can see, the indices are identical on both servers. The difference in the execution plan is one additional line:
    Filter Predicates CE.ID < 5
    Can anyone help me figure out why the explain plans are different? The servers have similar hardware specs, and are running the same version of Oracle (11.2.0.2.0)
    Thanks,
    Dan Scott
    http://danieljamesscott.org
    Edited by: danscott on Mar 4, 2011 11:43 AM

    Thanks for all the help/suggestions - as you've probably guessed, I'm a little new to all this.
    A little background first:
    We have an items table and events table. itemid is the primary key for the items table and a foreign key in the events table. The events table contains itemids, timestamps and data values (along with a few other IDs) The query I'm running is used to create a materialized view which provides statistics for each itemid to assist users in finding a particular itemid containing the data they're interested in. Generally, we create the view on the full list of itemids (and so the indices are not used, as expected). However, we occasionally run the query for a small number of itemids, and the index on events.itemid is used on one server, but not on the other.
    Here's the SQL (Apologies for the length).
    WITH ChartItems as (
      select distinct ci.itemid, ci.label, ci.category, ci.description,
             case
                when
                   (count(distinct ce.value1) over (partition by ci.itemid) > 0 OR
                    count(distinct ce.value2) over (partition by ci.itemid) > 0)
                   AND
                   (count(distinct ce.value1num) over (partition by ci.itemid) > 0 OR
                    count(distinct ce.value2num) over (partition by ci.itemid) > 0)
                then 'H'
                when
                   count(distinct ce.value1num) over (partition by ci.itemid) > 0 OR
                   count(distinct ce.value2num) over (partition by ci.itemid) > 0
                then 'N'
                when
                   count(distinct ce.value1) over (partition by ci.itemid) > 0 OR
                   count(distinct ce.value2) over (partition by ci.itemid) > 0
                then 'S'
                else
                    'X'
             end as value_type,
             -- The value column
             case
                when
                   (count(distinct ce.value1) over (partition by ci.itemid) > 0 OR
                    count(distinct ce.value1num) over (partition by ci.itemid) > 0)
                   and
                   (count(distinct ce.value2) over (partition by ci.itemid) > 0 OR
                    count(distinct ce.value2num) over (partition by ci.itemid) > 0)
                then 'both'
                when
                   count(distinct ce.value1) over (partition by ci.itemid) > 0 OR
                   count(distinct ce.value1num) over (partition by ci.itemid) > 0
                then 'value1'
                when
                   count(distinct ce.value2) over (partition by ci.itemid) > 0 OR
                   count(distinct ce.value2num) over (partition by ci.itemid) > 0
                then 'value2'
                else
                    'none'
             end as value_column
        from items ci,
             events ce
       where ce.itemid = ci.itemid
         and ci.itemid < 5
    , RawData as (
        select distinct ci.itemid, ci.label, ci.category, ci.description,
              ci.value_type, ci.value_column,
              count(*)
                over (partition by ci.itemid) as rows_num,
              count(distinct ce.subject_id)
                over (partition by ci.itemid) as subjects_num,
              avg(abs(cast(ce.realtime as date) - cast(ce.charttime as date)) * 24 * 60)
                over (partition by ci.itemid) as chart_vs_realtime_delay_mean,
              stddev(abs(cast(ce.realtime as date) - cast(ce.charttime as date)) * 24 * 60)
                over (partition by ci.itemid) as chart_vs_realtime_delay_stddev,
              case
                when ci.value_column in ('value1', 'both') then
                    case
                      when (last_value(ce.value1uom)
                                over (partition by ci.itemid
                                      order by ce.value1uom nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          count(distinct ce.value1uom)
                            over (partition by ci.itemid) + 1
                      else
                          count(distinct ce.value1uom)
                            over (partition by ci.itemid)
                    end
                else
                    0
              end as value1_uom_num,
              case
                when ci.value_column in ('value1', 'both') then
                    case
                      when (last_value(ce.value1uom)
                                over (partition by ci.itemid
                                      order by ce.value1uom nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          'Y'
                      else
                          'N'
                    end
                else
                    null
              end as value1_uom_has_nulls,
              first_value(ce.value1uom) ignore nulls
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value1_uom_sample1,
              last_value(ce.value1uom) ignore nulls
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value1_uom_sample2,
              case
                when ci.value_column in ('value1', 'both') then
                    case
                      when (last_value(ce.value1)
                                over (partition by ci.itemid
                                      order by ce.value1 nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          count(distinct ce.value1)
                            over (partition by ci.itemid) + 1
                      else
                          count(distinct ce.value1)
                            over (partition by ci.itemid)
                    end
                else
                    0
              end as value1_distinct_num,
              case
                when ci.value_column in ('value1', 'both') then
                    case
                      when (last_value(ce.value1)
                                over (partition by ci.itemid
                                      order by ce.value1 nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          'Y'
                      else
                          'N'
                    end
                else
                    null
              end as value1_has_nulls,
             first_value(ce.value1) ignore nulls
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value1_sample1,
             last_value(ce.value1) ignore nulls
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value1_sample2,
             min(length(ce.value1))
                 over (partition by ci.itemid) as value1_length_min,
             max(length(ce.value1))
                 over (partition by ci.itemid) as value1_length_max,
             avg(length(ce.value1))
                 over (partition by ci.itemid) as value1_length_mean,
             min(ce.value1num)
                 over (partition by ci.itemid) as value1num_min,
             max(ce.value1num)
                 over (partition by ci.itemid) as value1num_max,
             avg(ce.value1num)
                 over (partition by ci.itemid) as value1num_mean,
             stddev(ce.value1num)
                 over (partition by ci.itemid) as value1num_stddev,
              case
                when ci.value_column in ('value2', 'both') then
                    case
                      when (last_value(ce.value2uom)
                                over (partition by ci.itemid
                                      order by ce.value2uom nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          count(distinct ce.value2uom)
                            over (partition by ci.itemid) + 1
                      else
                          count(distinct ce.value2uom)
                            over (partition by ci.itemid)
                    end
                else
                    0
              end as value2_uom_num,
              case
                when ci.value_column in ('value2', 'both') then
                    case
                      when (last_value(ce.value2uom)
                                over (partition by ci.itemid
                                      order by ce.value2uom nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          'Y'
                      else
                          'N'
                    end
                else
                    null
              end as value2_uom_has_nulls,
             first_value(ce.value2uom) ignore nulls
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value2_uom_sample1,
             last_value(ce.value2uom) ignore nulls
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value2_uom_sample2,
              case
                when ci.value_column in ('value2', 'both') then
                    case
                      when (last_value(ce.value2)
                                over (partition by ci.itemid
                                      order by ce.value2 nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          count(distinct ce.value2)
                            over (partition by ci.itemid) + 1
                      else
                          count(distinct ce.value2)
                            over (partition by ci.itemid)
                    end
                else
                    0
              end as value2_distinct_num,
              case
                when ci.value_column in ('value2', 'both') then
                    case
                      when (last_value(ce.value2)
                                over (partition by ci.itemid
                                      order by ce.value2 nulls last
                                      ROWS BETWEEN UNBOUNDED PRECEDING AND
                                      UNBOUNDED FOLLOWING)
                           ) is null then
                          'Y'
                      else
                          'N'
                    end
                else
                    null
              end as value2_has_nulls,
             first_value(ce.value2)
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN  UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value2_sample1,
             last_value(ce.value2)
                 over (partition by ci.itemid
                       order by ce.charttime ROWS BETWEEN  UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as value2_sample2,
             min(length(ce.value2))
                 over (partition by ci.itemid) as value2_length_min,
             max(length(ce.value2))
                 over (partition by ci.itemid) as value2_length_max,
             avg(length(ce.value2))
                 over (partition by ci.itemid) as value2_length_mean,
             min(ce.value2num)
                 over (partition by ci.itemid) as value2num_min,
             max(ce.value2num)
                 over (partition by ci.itemid) as value2num_max,
             avg(ce.value2num)
                 over (partition by ci.itemid) as value2num_mean,
             stddev(ce.value2num)
                 over (partition by ci.itemid) as value2num_stddev
        from ChartItems ci,
             events ce
       where ce.itemid = ci.itemid
    --   order by ci.itemid, ci.label
    select label, trim(lower(label)) label_lower, itemid, category, description,
           value_type, value_column,
           rows_num, subjects_num,
           round(chart_vs_realtime_delay_mean, 2) as chart_vs_realtime_delay_mean,
           round(chart_vs_realtime_delay_stddev, 2) as chart_vs_realtime_delay_stddev,
           value1_uom_num, value1_uom_has_nulls,
           value1_uom_sample1, value1_uom_sample2,
           value1_distinct_num, value1_has_nulls,
           value1_sample1, value1_sample2,
           value1_length_min, value1_length_max,
           round(value1_length_mean, 2) as value1_length_mean,
           round(value1num_min, 2) as value1num_min,
           round(value1num_max, 2) as value1num_max,
           round(value1num_mean, 2) as value1num_mean,
           round(value1num_stddev, 2) as value1num_stddev,
           value2_uom_num, value2_uom_has_nulls,
           value2_uom_sample1, value2_uom_sample2,
           value2_distinct_num, value2_has_nulls,
           value2_sample1, value2_sample2,
           value2_length_min, value2_length_max,
           round(value2_length_mean, 2) as value2_length_mean,
           round(value2num_min, 2) as value2num_min,
           round(value2num_max, 2) as value2num_max,
           round(value2num_mean, 2) as value2num_mean,
           round(value2num_stddev, 2) as value2num_stddev
      from RawData
    order by label, itemid;

  • Will a explain plan consider a function in a select statement.

    Hi gurus,
    I have a question regarding explain plan.
    I ran a query, which returns me explain plan with multiple CPU costs around 300K.
    now i use a function, and the number of lines displayed in explain plan reduces from 12 to 8 lines.
    What i dont understand is.. Is the explain plan considering the function in the select statement ?
    ex.
    explain plan for
    select column1,
             column2,
             function(value1)
    from case
    where case_no = 1will a explain plan consider the functions in a select statement ?
    Thank you.

    What i dont understand is.. Is the explain plan considering the function in the select statement ?Maybe there are tweaks which reveal more information from the explain plan, but a straightforward way won't necessarily expose any function call:
    SQL> create or replace function get_dname (i_deptno integer)
       return varchar2
    as
       l_dname   dept.dname%type;
    begin
       select   dname
         into   l_dname
         from   dept
        where   deptno = i_deptno;
       return l_dname;
    end get_dname;
    Function created.
    SQL> explain plan
       for
          select   ename, deptno, get_dname (deptno) dname
            from   emp
           where   deptno = 10
    Explain complete.
    SQL> select   * from table (dbms_xplan.display ())
    PLAN_TABLE_OUTPUT                                                                                                                                    
    Plan hash value: 3956160932                                                                                                                          
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |                                                                           
    |   0 | SELECT STATEMENT  |      |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    |*  1 |  TABLE ACCESS FULL| EMP  |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    Predicate Information (identified by operation id):                                                                                                  
       1 - filter("DEPTNO"=10)                                                                                                                           
    13 rows selected.
    SQL> truncate table plan_table
    Table truncated.
    SQL> explain plan
       for
          select   ename, deptno
            from   emp
           where   deptno = 10
    Explain complete.
    SQL> select   * from table (dbms_xplan.display ())
    PLAN_TABLE_OUTPUT                                                                                                                                    
    Plan hash value: 3956160932                                                                                                                          
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |                                                                           
    |   0 | SELECT STATEMENT  |      |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    |*  1 |  TABLE ACCESS FULL| EMP  |     5 |    45 |     3   (0)| 00:00:01 |                                                                           
    Predicate Information (identified by operation id):                                                                                                  
       1 - filter("DEPTNO"=10)                                                                                                                           
    13 rows selected.

  • Explain Plan not showing correct results.

    Hi Gurus,
    Please help me to understand below issue.
    Whenever I am doing explain plan on any of the sql statements it says as explained but when retriving the explain plan output it shows same results again and again.
    DB - 11gR2 Stand alone
    ASM - Configured.
    OS - RHEL 6.2.
    SQL> select count(*) from t2114;
    COUNT(*)
    639292
    SQL> explain plan for select count(*) from t2114;
    Explained.
    SQL> @?/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 1497650422
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 6634 | 524K| 2993 (19)| 00:00:01 |
    | 1 | SORT ORDER BY | | 6634 | 524K| 2993 (19)| 00:00:01 |
    | 2 | TABLE ACCESS BY INDEX ROWID| T2210 | 6634 | 524K| 2947 (17)| 00:00:01 |
    |* 3 | INDEX RANGE SCAN | T2210_T | 6842 | | 108 (22)| 00:00:01 |
    Predicate Information (identified by operation id):
    3 - access("T2210"."C490008000"=:SYS_B_0 AND "T2210"."C490009100"=:SYS_B_2
    AND "T2210"."C301363300"=TO_NUMBER(:SYS_B_1))
    16 rows selected.
    SQL> explain plan for
    2 SELECT T2114.C1 FROM T2114 WHERE ((T2114.C1000000001 = :"SYS_B_0") AND (T2114.C536871442 = :"SYS_B_1") AND (T2114.C536871477 = :"SYS_B_2") AND ((:"SYS_B_3" - T2114.C3) >= :"SYS_B_4") AND ((:"SYS_B_5" - T2114.C3) <= :"SYS_B_6") AND (T2114.C1000000217 LIKE :"SYS_B_7") AND (T2114.C536871478 < :"SYS_B_8")) ORDER BY C1000000161 DESC, :"SYS_B_9" ASC;
    Explained.
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1497650422
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 6634 | 524K| 2993 (19)| 00:00:01 |
    | 1 | SORT ORDER BY | | 6634 | 524K| 2993 (19)| 00:00:01 |
    | 2 | TABLE ACCESS BY INDEX ROWID| T2210 | 6634 | 524K| 2947 (17)| 00:00:01 |
    |* 3 | INDEX RANGE SCAN | T2210_T | 6842 | | 108 (22)| 00:00:01 |
    Predicate Information (identified by operation id):
    3 - access("T2210"."C490008000"=:SYS_B_0 AND "T2210"."C490009100"=:SYS_B_2
    AND "T2210"."C301363300"=TO_NUMBER(:SYS_B_1))
    16 rows selected.

    Hi Dom,
    Thanks for your immediate response.
    I am getting two values for PLAN_TABLE. Please let me know if we need to drop any of them??
    SQL> SELECT *
    FROM all_objects
    WHERE object_name = 'PLAN_TABLE'; 2 3
    OWNER OBJECT_NAME SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE CREATED LAST_DDL_TIME TIMESTAMP STATUS T G S NAMESPACE EDITION_NAME
    PUBLIC PLAN_TABLE 5127 SYNONYM 17-SEP-11 17-SEP-11 2011-09-17:09:47:47 VALID N N N 1
    ARADMIN PLAN_TABLE 219426 219426 TABLE 07-APR-13 07-APR-13 2013-04-07:23:01:12 VALID N N N 1

Maybe you are looking for