Different execution plans for the same sql

Hi,
Im testing our new 10gR2 database on Linux and I can't understand why the same query use different plan.
Here are the details.
Table name: invoice_detail
Records: About 10,670,900
Columns:
No
seq (the primary key is No+Seq). Each invoices contains +/- 10 invoice_details.
category ( <- 10 different values )
State ( <- 3 different values )
Basically, I have an index on the primary key and another index on Category + State.
My request:
select *
from invoice_detail
where no=123456 <- Best index to use
and state <> 'CANCEL'
and category = 'INVOICE'
If i run this query from Toad or sql+, that's fine.
The same query (i'm watching it from EM) executed via Forms use the category+state index.
When I first import the database, the last thing I do is to run DBMS_STATS.GATHER_DATABASE_STATS.
At this point, Forms use the right index.
The day after (after the database has been analyzed with the predefined job via EM) Forms use the wrong index.
I re-analyzed everything with exec DBMS_STATS.GATHER_DATABASE_STATS but the problem is still there.
Thanks in advance

I'm already using bind variables.
I changed the "Estimated Percentage" to 100% in "Gather Optimizer Statistics Default Options" and now it seems to use the correct index. I'm stressed because I dont understand why it chooses different plan for the same sql.
Actually, my users test the migration 1 day after I load all the data (drop schema-create schema-load data-analyze database) and at this point everythings go fine. After the second analyze of the database, the DB choose the wrong indexes.
I really cannot migrate until I understand why it happens.
Any ideas?
TIA

Similar Messages

  • Different execution plans for the same SQL query

    Good afternoon,
    My customer is sending an SQL query that goes slower after some time.
    He has verified the exection plan, and this seems to change after some time.
    At first (when the database has just been restarted), it looks like this:
    Rows Row Source Operation
    3 TABLE ACCESS BY GLOBAL INDEX ROWID <TABLE1> PARTITION: 1 1
    22 NESTED LOOPS
    3 VIEW
    3 MINUS
    14215 SORT UNIQUE
    14215 NESTED LOOPS
    14215 TABLE ACCESS FULL <TABLE1> PARTITION: 1 1
    14215 TABLE ACCESS BY GLOBAL INDEX ROWID <TABLE2> PARTITION: 1 1
    14215 INDEX UNIQUE SCAN <INDEX2> (object id 26024)
    14212 SORT UNIQUE
    14212 REMOTE
    18 INDEX RANGE SCAN <INDEX1> (object id 25911)
    After a while, this becomes:
    Rows Row Source Operation
    8 NESTED LOOPS
    14218 TABLE ACCESS FULL <TABLE1> PARTITION: 1 1
    8 VIEW
    113744 MINUS
    202151524 SORT UNIQUE
    14218 NESTED LOOPS
    14218 TABLE ACCESS FULL <TABLE1> PARTITION: 1 1
    14218 TABLE ACCESS BY GLOBAL INDEX ROWID <TABLE2> PARTITION: 1 1
    14218 INDEX UNIQUE SCAN <INDEX_2> (object id 26024)
    202037780 SORT UNIQUE
    14210 REMOTE
    At regular intervals a "coalesce" of the <INDEX2> is scheduled.
    Do you have any idea what might cause this different plans? (it's heavily impacting performance, because the second execution plan takes 5 times more time)
    Thanks
    Dominique
    Edited by: scampsd on May 17, 2011 1:42 PM

    scampsd wrote:
    Good afternoon,
    My customer is sending an SQL query that goes slower after some time.
    He has verified the exection plan, and this seems to change after some time.
    At first (when the database has just been restarted), it looks like this:
    At regular intervals a "coalesce" of the <INDEX2> is scheduled.
    Do you have any idea what might cause this different plans? (it's heavily impacting performance, because the second execution plan takes 5 times more time)Something on your system is changing. Unfortunately if finding out what were easy you would have done it already
    You have isolated a couple of things. What happends of you disable the index maintenance?
    It is odd that performance as you described it degrands merely because of time the database has been up

  • Multiple Executions Plans for the same SQL statement

    Dear experts,
    awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.
    Below is the awrsqrpt's output for your reference.
    WORKLOAD REPOSITORY SQL Report
    Snapshot Period Summary
    DB Name         DB Id    Instance     Inst Num Release     RAC Host
    TESTDB          2157605839 TESTDB1               1 10.2.0.3.0  YES testhost1
                  Snap Id      Snap Time      Sessions Curs/Sess
    Begin Snap:     32541 11-Oct-08 21:00:13       248     141.1
      End Snap:     32542 11-Oct-08 21:15:06       245     143.4
       Elapsed:               14.88 (mins)
       DB Time:               12.18 (mins)
    SQL Summary                            DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
                    Elapsed
       SQL Id      Time (ms)
    51szt7b736bmg     25,131
    Module: SQL*Plus
    UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(ACCT_DR_BAL,
    0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND TEST_ACC_NB = ACCT_ACC_NB(+)) WHERE
    TEST_BATCH_DT = (:B1 )
    SQL ID: 51szt7b736bmg                  DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> 1st Capture and Last Capture Snap IDs
       refer to Snapshot IDs witin the snapshot range
    -> UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(AC...
        Plan Hash           Total Elapsed                 1st Capture   Last Capture
    #   Value                    Time(ms)    Executions       Snap ID        Snap ID
    1   2960830398                 25,131             1         32542          32542
    2   3834848140                      0             0         32542          32542
    Plan 1(PHV: 2960830398)
    Plan Statistics                        DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> % Total DB Time is the Elapsed Time of the SQL statement divided
       into the Total Database Time multiplied by 100
    Stat Name                                Statement   Per Execution % Snap
    Elapsed Time (ms)                            25,131       25,130.7     3.4
    CPU Time (ms)                                23,270       23,270.2     3.9
    Executions                                        1            N/A     N/A
    Buffer Gets                               2,626,166    2,626,166.0    14.6
    Disk Reads                                      305          305.0     0.3
    Parse Calls                                       1            1.0     0.0
    Rows                                        371,735      371,735.0     N/A
    User I/O Wait Time (ms)                         564            N/A     N/A
    Cluster Wait Time (ms)                            0            N/A     N/A
    Application Wait Time (ms)                        0            N/A     N/A
    Concurrency Wait Time (ms)                        0            N/A     N/A
    Invalidations                                     0            N/A     N/A
    Version Count                                     2            N/A     N/A
    Sharable Mem(KB)                                 26            N/A     N/A
    Execution Plan
    | Id  | Operation                    | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT             |                 |       |       |  1110 (100)|          |
    |   1 |  UPDATE                      | TEST            |       |       |            |          |
    |   2 |   TABLE ACCESS FULL          | TEST            |   116K|  2740K|  1110   (2)| 00:00:14 |
    |   3 |   TABLE ACCESS BY INDEX ROWID| ACCT            |     1 |    26 |     5   (0)| 00:00:01 |
    |   4 |    INDEX RANGE SCAN          | ACCT_DT_ACC_IDX |     1 |       |     4   (0)| 00:00:01 |
    Plan 2(PHV: 3834848140)
    Plan Statistics                        DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> % Total DB Time is the Elapsed Time of the SQL statement divided
       into the Total Database Time multiplied by 100
    Stat Name                                Statement   Per Execution % Snap
    Elapsed Time (ms)                                 0            N/A     0.0
    CPU Time (ms)                                     0            N/A     0.0
    Executions                                        0            N/A     N/A
    Buffer Gets                                       0            N/A     0.0
    Disk Reads                                        0            N/A     0.0
    Parse Calls                                       0            N/A     0.0
    Rows                                              0            N/A     N/A
    User I/O Wait Time (ms)                           0            N/A     N/A
    Cluster Wait Time (ms)                            0            N/A     N/A
    Application Wait Time (ms)                        0            N/A     N/A
    Concurrency Wait Time (ms)                        0            N/A     N/A
    Invalidations                                     0            N/A     N/A
    Version Count                                     2            N/A     N/A
    Sharable Mem(KB)                                 26            N/A     N/A
    Execution Plan
    | Id  | Operation                    | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT             |              |       |       |     2 (100)|          |
    |   1 |  UPDATE                      | TEST         |       |       |            |          |
    |   2 |   TABLE ACCESS BY INDEX ROWID| TEST         |     1 |    28 |     2   (0)| 00:00:01 |
    |   3 |    INDEX RANGE SCAN          | TEST_DT_IND  |     1 |       |     1   (0)| 00:00:01 |
    |   4 |   TABLE ACCESS BY INDEX ROWID| ACCT         |     1 |    26 |     4   (0)| 00:00:01 |
    |   5 |    INDEX RANGE SCAN          | INDX_ACCT_DT |     1 |       |     3   (0)| 00:00:01 |
    Full SQL Text
    SQL ID       SQL Text
    51szt7b736bm UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL, 0) +
                  NVL(ACCT_DR_BAL, 0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND PB
                 RN_ACC_NB = ACCT_ACC_NB(+)) WHERE TEST_BATCH_DT = (:B1 )Your input is highly appreciated.
    Thanks for taking your time in answering my question.
    Regards

    Oracle Lover3 wrote:
    Dear experts,
    awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.If you're using bind variables and you've histograms on your columns which can be created by default in 10g due to the "SIZE AUTO" default "method_opt" parameter of DBMS_STATS.GATHER__STATS it is quite normal that you get different execution plans for the same SQL statement. Depending on the values passed when the statement is hard parsed (this feature is called "bind variable peeking" and enabled by default since 9i) an execution plan is determined and re-used for all further executions of the same "shared" SQL statement.
    If now your statement ages out of the shared pool or is invalidated due to some DDL or statistics gathering activity it will be re-parsed and again the values passed in that particular moment will determine the execution plan. If you have skewed data distribution and a histogram in place that reflects that skewness you might get different execution plans depending on the actual values used.
    Since this "flip-flop" behaviour can sometimes be counter-productive if you're unlucky and the values used to hard parse the statement leading to a plan that is unsuitable for the majority of values used afterwards, 11g introduced the "adaptive" cursor sharing that attempts to detect such a situation and can automatically re-evaluate the execution plan of the statement.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Explain plan changing for the same sql

    Hi All,
    In a E Business suite application, we have the 10.2.0.4 Database.
    One of the program is running a select stmt which is using different explain plan one in a month which is causing issue in the program running for longer time.
    Ex : When it uses the index A, it is running fine. When it uses the index B, it is running for longer time.
    Can you please advice on the possible reasons for the same sql to choose index B instead of index A some times.
    Thanks,
    Rakesh

    It could be that the SQL is question got aged out of the shared pool and when it came to be reparsed - the values in the bind variables were such that access via index b was more attractive than access via index a.
    Could you please send the query and the good and bad plans and all other information that might help diagnose the problem..
    Note: we had a similiar case where plans suddenly changed for no apperant reason (on 10.2.0.2) - we found that under certain circumstances the optimizer would not peek into the bind varaibles to derive the execution path.

  • Is it possible to have Different Interval Ranges for the same Doc Type

    Dear All,
    Here is the issue.Is it possible to have different interval ranges for the same document type according to certain condition.Like my client , wants his interval ranges  be divided according to region(which are many)
    Regards,
    Sameer Jalees

    Hello,
    As you know we can only assign one number range for External and one number range group for internal in the sales document type.
    If you want different number ranges based on the regions, then as Jignesh suggested, you need to go for an enhancement.
    Use the exit USEREXIT_NUMBER_RANGE in program MVA45AFZZ, include a Z table with region as a critera and number range group for different numbers based on the regions. Talk to the business and get more details, get the help of ABAP team for technical details.
    Regards,
    SAM

  • HT1390 Why do I get a different movie price for the same movie on my iPad and iPhone. And 1 device says I can rent it but the other doesn't ,.?

    Why do I get a different movie price for the same movie on my iPad and iPhone. And 1 device says I can rent it but the other doesn't ,.?

    Adding Open DNS codes to your Network Preferences, should give good results in terms of speed-up as well as added security, (including anti-phishing and redirects) (Full information about Open DNS is here: http://www.opendns.com/home/nobloat ) and further independent information can be read here:
    http://reviews.cnet.com/8301-13727_7-57338784-263/free-dnscrypt-tool-enhances-ma c-web-security/?tag=mncol;txt
    and here:
    http://www.macworld.com/article/1146064/troubleshootdns.html?t=234
    Open System Preferences/Network. Double click on your connection type, or select it in the drop-down menu, and in the box marked 'DNS Servers' add the following two numbers:
    208.67.222.222
    208.67.220.220
    (You can also enter them if you click on Advanced and then DNS)
    Sometimes reversing the order of the DNS numbers can be beneficial in cases where there is a long delay before web pages start to load, and then suddenly load at normal speed:
    http://support.apple.com/kb/TS2296

  • My account asks me to change my password every week for no reason and i have different security questions for the same account

    My account asks me to change my password every week for no reason and i have different security questions for the same account

    Does the iPod connect to other networks?
    Does the iPod see the network?
    Any error messages?
    Do other devices now connect?
    Did the iPod connect before?
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on the router
    - Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Try changing the security on the router. Start with no securty as a test.
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • Different execution plan for same query but for different condition value

    Hi All,
    I'm facing a strange situation where same query for different condition not working.
    1--
    Select  top 10 * from revenuefact(nolock) 
    where feecode ='OW4'
    2--
    Select  top 10 * from revenuefact(nolock)
    where feecode ='BTE'
    1st query is returning result easily but 2nd query is taking too long. Column
    feecode has already Non-clustered index and Clustered index is also available for another col RevenueSID.
    I was surprised when checked the query execution plan for both the above queries  which is quite different (as per attached below). Can anyone suggest me the reason behind it.
    And solution for the same. One more thing that data for feecode BTE is inserting through different source instead of others feecode and table contains more than 300 million rows.

    When I speak with people inside Microsoft who work with the optimizer, the refuse to accept the work "bug" when a query produces the correct result, but with a suboptimal plan. They prefer to use the word "limitation".
    The limitation here is that when the optimizer compares two plans, it only looks at the estimated cost. As far as I know, it does not perform any analysis from the perspective "what if the statistics are wrong"? They do provide the hint OPTIMIZE
    FOR UNKNOWN, but that does not work then there is a constant as in this case.
    The optimizer will surely distinguish between TOP 10 and TOP 10000000. With the latter, you have all reason to expect a Clustered Index Scan no matter which value you search for - unless you pick a value for which the histogram indicates that there are no
    rows.
    Interesting enough, I was able to reproduce the situation in my Northgale database, which is an inflated version of Northwind, and where statistics should be accurate.
    SELECT TOP 10 * FROM Orders WHERE EmployeeID = 8
    results in a CI scan, and so does also EmployeeID = 7, and even 5. There are only 2292 rows out of a total of 344305 rows. If I try EmployeeID 808 for which there are 1797, the optimizer goes for the index seek.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • CBO generating different plans for the same data in similar Environments

    Hi All
    I have been trying to compare an SQL from 2 different but similar environments build of the same hardware specs .The issue I am facing is environment A, the query executes in less than 2 minutes with plan mostly showing full table scans and hash join whereas in environment B(problematic), it times out after 2 hours with an error of unable to extend table space . The statistics are up to date in both environments for both tables and indexes . System parameters are exactly similar(default oracle for except for multiblock_read_count ).
    Both Environment have same db parameter for db_file_multiblock_read_count(16), optimizer(refer below),hash_area_size (131072),pga_aggregate_target(1G),db_block_size(8192) etc . SREADTIM, MREADTIM, CPUSPEED, MBRC are all null in aux_stats in both environment because workload was never collected i believe.
    Attached is details about the SQL with table stats, SQL and index stats my main concern is CBO generating different plans for the similar data and statistics and same hardware and software specs. Is there any thing else I should consider .I generally see environment B being very slow and always plans tend to nested loops and index scan whereas what we really need is a sensible FTS in many cases. One of the very surprising thing is METER_CONFIG_HEADER below which has just 80 blocks of data is being asked for index scan.
    show parameter optimizer
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 100
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    **Environment**
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE     10.2.0.4.0     Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Note: : There are slight difference in the no of records in the attached sheet.However, I wanted to tell that i have tested with exact same data and was getting similar results but I couldn't retain the data untill collecting the details in the attachment
    TEST1     COMPARE TABLE LEVE STATS  used by CBO          
    ENVIRONMENT A
    TABLE_NAME     NUM_ROWS     BLOCKS     LAST_ANALYZED
    ASSET     3607425     167760     5/02/2013 22:11
    METER_CONFIG_HEADER     3658     80     5/01/2013 0:07
    METER_CONFIG_ITEM     32310     496     5/01/2013 0:07
    NMI     1899024     33557     18/02/2013 10:55
    REGISTER     4830153     101504     18/02/2013 9:57
    SDP_LOGICAL_ASSET     1607456     19137     18/02/2013 15:48
    SDP_LOGICAL_REGISTER     5110781     78691     18/02/2013 9:56
    SERVICE_DELIVERY_POINT     1425890     42468     18/02/2013 13:54
    ENVIRONMENT B
    TABLE_NAME     NUM_ROWS     BLOCKS     LAST_ANALYZED
    ASSET     4133939     198570     16/02/2013 10:02
    METER_CONFIG_HEADER     3779     80     16/02/2013 10:55
    METER_CONFIG_ITEM     33720     510     16/02/2013 10:55
    NMI     1969000     33113     16/02/2013 10:58
    REGISTER     5837874     120104     16/02/2013 11:05
    SDP_LOGICAL_ASSET     1788152     22325     16/02/2013 11:06
    SDP_LOGICAL_REGISTER     6101934     91088     16/02/2013 11:07
    SERVICE_DELIVERY_POINT     1447589     43804     16/02/2013 11:11
    TEST ITEM 2     COMPARE INDEX STATS  used by CBO          
    ENVIRONMENT A
    TABLE_NAME     INDEX_NAME     UNIQUENESS     BLEVEL     LEAF_BLOCKS     DISTINCT_KEYS     AVG_LEAF_BLOCKS_PER_KEY     AVG_DATA_BLOCKS_PER_KEY     CLUSTERING_FACTOR     NUM_ROWS
    ASSET     IDX_AST_DEVICE_CATEGORY_SK     NONUNIQUE     2     9878     67     147     12982     869801     3553095
    ASSET     IDX_A_SAPINTLOGDEV_SK     NONUNIQUE     2     7291     2747     2     639     1755977     3597916
    ASSET     SYS_C00102592     UNIQUE     2     12488     3733831     1     1     3726639     3733831
    METER_CONFIG_HEADER     SYS_C0092052     UNIQUE     1     12     3670     1     1     3590     3670
    METER_CONFIG_ITEM     SYS_C0092074     UNIQUE     1     104     32310     1     1     32132     32310
    NMI     IDX_NMI_ID     NONUNIQUE     2     6298     844853     1     2     1964769     1965029
    NMI     IDX_NMI_ID_NK     NONUNIQUE     2     6701     1923072     1     1     1922831     1923084
    NMI     IDX_NMI_STATS     NONUNIQUE     1     106     4     26     52     211     211
    REGISTER     REG_EFFECTIVE_DTM     NONUNIQUE     2     12498     795     15     2899     2304831     4711808
    REGISTER     SYS_C00102653     UNIQUE     2     16942     5065660     1     1     5056855     5065660
    SDP_LOGICAL_ASSET     IDX_SLA_SAPINTLOGDEV_SK     NONUNIQUE     2     3667     1607968     1     1     1607689     1607982
    SDP_LOGICAL_ASSET     IDX_SLA_SDP_SK     NONUNIQUE     2     3811     668727     1     2     1606204     1607982
    SDP_LOGICAL_ASSET     SYS_C00102665     UNIQUE     2     5116     1529606     1     1     1528136     1529606
    SDP_LOGICAL_REGISTER     SYS_C00102677     UNIQUE     2     17370     5193638     1     1     5193623     5193638
    SERVICE_DELIVERY_POINT     IDX_SDP_NMI_SK     NONUNIQUE     2     4406     676523     1     2     1423247     1425890
    SERVICE_DELIVERY_POINT     IDX_SDP_SAP_INT_NMI_SK     NONUNIQUE     2     7374     676523     1     2     1458238     1461108
    SERVICE_DELIVERY_POINT     SYS_C00102687     UNIQUE     2     4737     1416207     1     1     1415022     1416207
    ENVIRONMENT B
    TABLE_NAME     INDEX_NAME     UNIQUENESS     BLEVEL     LEAF_BLOCKS     DISTINCT_KEYS     AVG_LEAF_BLOCKS_PER_KEY     AVG_DATA_BLOCKS_PER_KEY     CLUSTERING_FACTOR     NUM_ROWS
    ASSET     IDX_AST_DEVICE_CATEGORY_SK     NONUNIQUE     2     8606     121     71     16428     1987833     4162257
    ASSET     IDX_A_SAPINTLOGDEV_SK     NONUNIQUE     2     8432     1780146     1     1     2048170     4162257
    ASSET     SYS_C00116157     UNIQUE     2     13597     4162263     1     1     4158759     4162263
    METER_CONFIG_HEADER     SYS_C00116570     UNIQUE     1     12     3779     1     1     3734     3779
    METER_CONFIG_ITEM     SYS_C00116592     UNIQUE     1     107     33720     1     1     33459     33720
    NMI     IDX_NMI_ID     NONUNIQUE     2     6319     683370     1     2     1970460     1971313
    NMI     IDX_NMI_ID_NK     NONUNIQUE     2     6597     1971293     1     1     1970771     1971313
    NMI     IDX_NMI_STATS     NONUNIQUE     1     98     48     2     4     196     196
    REGISTER     REG_EFFECTIVE_DTM     NONUNIQUE     2     15615     1273     12     2109     2685924     5886582
    REGISTER     SYS_C00116748     UNIQUE     2     19533     5886582     1     1     5845565     5886582
    SDP_LOGICAL_ASSET     IDX_SLA_SAPINTLOGDEV_SK     NONUNIQUE     2     4111     1795084     1     1     1758441     1795130
    SDP_LOGICAL_ASSET     IDX_SLA_SDP_SK     NONUNIQUE     2     4003     674249     1     2     1787987     1795130
    SDP_LOGICAL_ASSET     SYS_C004520     UNIQUE     2     5864     1795130     1     1     1782147     1795130
    SDP_LOGICAL_REGISTER     SYS_C004539     UNIQUE     2     20413     6152850     1     1     6073059     6152850
    SERVICE_DELIVERY_POINT     IDX_SDP_NMI_SK     NONUNIQUE     2     3227     660649     1     2     1422572     1447803
    SERVICE_DELIVERY_POINT     IDX_SDP_SAP_INT_NMI_SK     NONUNIQUE     2     6399     646257     1     2     1346948     1349993
    SERVICE_DELIVERY_POINT     SYS_C00128706     UNIQUE     2     4643     1447946     1     1     1442796     1447946
    TEST ITEM 3     COMPARE PLANS     
    ENVIRONMENT A
    Plan hash value: 4109575732                                             
    | Id  | Operation                       | Name                   | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                             
    |   0 | SELECT STATEMENT                |                        |    13 |  2067 |       |   135K  (2)| 00:27:05 |                                             
    |   1 |  HASH UNIQUE                    |                        |    13 |  2067 |       |   135K  (2)| 00:27:05 |                                             
    |*  2 |   HASH JOIN                     |                        |    13 |  2067 |       |   135K  (2)| 00:27:05 |                                             
    |*  3 |    HASH JOIN                    |                        |     6 |   900 |       |   135K  (2)| 00:27:04 |                                             
    |*  4 |     HASH JOIN ANTI              |                        |     1 |   137 |       |   135K  (2)| 00:27:03 |                                             
    |*  5 |      TABLE ACCESS BY INDEX ROWID| NMI                    |     1 |    22 |       |     5   (0)| 00:00:01 |                                             
    |   6 |       NESTED LOOPS              |                        |     1 |   131 |       | 95137   (2)| 00:19:02 |                                             
    |*  7 |        HASH JOIN                |                        |     1 |   109 |       | 95132   (2)| 00:19:02 |                                             
    |*  8 |         TABLE ACCESS FULL       | ASSET                  | 36074 |  1021K|       | 38553   (2)| 00:07:43 |                                             
    |*  9 |         HASH JOIN               |                        | 90361 |  7059K|  4040K| 56578   (2)| 00:11:19 |                                             
    |* 10 |          HASH JOIN              |                        | 52977 |  3414K|  2248K| 50654   (2)| 00:10:08 |                                             
    |* 11 |           HASH JOIN             |                        | 39674 |  1782K|       | 40101   (2)| 00:08:02 |                                             
    |* 12 |            TABLE ACCESS FULL    | REGISTER               | 39439 |  1232K|       | 22584   (2)| 00:04:32 |                                             
    |* 13 |            TABLE ACCESS FULL    | SDP_LOGICAL_REGISTER   |  4206K|    56M|       | 17490   (2)| 00:03:30 |                                             
    |* 14 |           TABLE ACCESS FULL     | SERVICE_DELIVERY_POINT |   675K|    12M|       |  9412   (2)| 00:01:53 |                                             
    |* 15 |          TABLE ACCESS FULL      | SDP_LOGICAL_ASSET      |  1178K|    15M|       |  4262   (2)| 00:00:52 |                                             
    |* 16 |        INDEX RANGE SCAN         | IDX_NMI_ID_NK          |     2 |       |       |     2   (0)| 00:00:01 |                                             
    |  17 |      VIEW                       |                        | 39674 |   232K|       | 40101   (2)| 00:08:02 |                                             
    |* 18 |       HASH JOIN                 |                        | 39674 |  1046K|       | 40101   (2)| 00:08:02 |                                             
    |* 19 |        TABLE ACCESS FULL        | REGISTER               | 39439 |   500K|       | 22584   (2)| 00:04:32 |                                             
    |* 20 |        TABLE ACCESS FULL        | SDP_LOGICAL_REGISTER   |  4206K|    56M|       | 17490   (2)| 00:03:30 |                                             
    |* 21 |     TABLE ACCESS FULL           | METER_CONFIG_HEADER    |  3658 | 47554 |       |    19   (0)| 00:00:01 |                                             
    |* 22 |    TABLE ACCESS FULL            | METER_CONFIG_ITEM      |  7590 | 68310 |       |   112   (2)| 00:00:02 |                                             
    Predicate Information (identified by operation id):                                             
       2 - access("METER_CONFIG_HEADER_SK"="METER_CONFIG_HEADER_SK")                                             
       3 - access("NETWORK_TARIFF_CD"="NETWORK_TARIFF_CD")                                             
       4 - access("SERVICE_DELIVERY_POINT_SK"="TMP"."SERVICE_DELIVERY_POINT_SK")                                             
       5 - filter("ROW_CURRENT_IND"='Y' AND ("NMI_STATUS_CD"='A' OR "NMI_STATUS_CD"='D'))                                             
       7 - access("ASSET_CD"="EQUIP_CD" AND "SAP_INT_LOG_DEVICE_SK"="SAP_INT_LOG_DEVICE_SK")                                             
       8 - filter("ROW_CURRENT_IND"='Y')                                             
       9 - access("SERVICE_DELIVERY_POINT_SK"="SERVICE_DELIVERY_POINT_SK")                                             
      10 - access("SERVICE_DELIVERY_POINT_SK"="SERVICE_DELIVERY_POINT_SK")                                             
      11 - access("SAP_INT_LOGICAL_REGISTER_SK"="SAP_INT_LOGICAL_REGISTER_SK")                                             
      12 - filter("REGISTER_TYPE_CD"='C' AND (SUBSTR("REGISTER_ID_CD",1,1)='4' OR                                              
                  SUBSTR("REGISTER_ID_CD",1,1)='5' OR SUBSTR("REGISTER_ID_CD",1,1)='6') AND "ROW_CURRENT_IND"='Y')                                             
      13 - filter("ROW_CURRENT_IND"='Y')                                             
      14 - filter("ROW_CURRENT_IND"='Y')                                             
      15 - filter("ROW_CURRENT_IND"='Y')                                             
      16 - access("NMI_SK"="NMI_SK")                                             
      18 - access("SAP_INT_LOGICAL_REGISTER_SK"="SAP_INT_LOGICAL_REGISTER_SK")                                             
      19 - filter("REGISTER_TYPE_CD"='C' AND (SUBSTR("REGISTER_ID_CD",1,1)='1' OR                                              
                  SUBSTR("REGISTER_ID_CD",1,1)='2' OR SUBSTR("REGISTER_ID_CD",1,1)='3') AND "ROW_CURRENT_IND"='Y')                                             
      20 - filter("ROW_CURRENT_IND"='Y')                                             
      21 - filter("ROW_CURRENT_IND"='Y')                                             
      22 - filter("ROW_CURRENT_IND"='Y' AND "CONROL_REGISTER"='X')                                             
    ENVIRONMENT B
    Plan hash value: 2826260434                                   
    | Id  | Operation                            | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |                                   
    |   0 | SELECT STATEMENT                     |                        |     1 |   181 |   103K  (2)| 00:20:47 |                                   
    |   1 |  HASH UNIQUE                         |                        |     1 |   181 |   103K  (2)| 00:20:47 |                                   
    |*  2 |   HASH JOIN ANTI                     |                        |     1 |   181 |   103K  (2)| 00:20:47 |                                   
    |*  3 |    HASH JOIN                         |                        |     1 |   176 | 56855   (2)| 00:11:23 |                                   
    |*  4 |     HASH JOIN                        |                        |     1 |   163 | 36577   (2)| 00:07:19 |                                   
    |*  5 |      TABLE ACCESS BY INDEX ROWID     | ASSET                  |     1 |    44 |     4   (0)| 00:00:01 |                                   
    |   6 |       NESTED LOOPS                   |                        |     1 |   131 |  9834   (2)| 00:01:59 |                                   
    |   7 |        NESTED LOOPS                  |                        |     1 |    87 |  9830   (2)| 00:01:58 |                                   
    |   8 |         NESTED LOOPS                 |                        |     1 |    74 |  9825   (2)| 00:01:58 |                                   
    |*  9 |          HASH JOIN                   |                        |     1 |    52 |  9820   (2)| 00:01:58 |                                   
    |* 10 |           TABLE ACCESS BY INDEX ROWID| METER_CONFIG_HEADER    |     1 |    14 |     1   (0)| 00:00:01 |                                   
    |  11 |            NESTED LOOPS              |                        |     1 |    33 |   116   (2)| 00:00:02 |                                   
    |* 12 |             TABLE ACCESS FULL        | METER_CONFIG_ITEM      |     1 |    19 |   115   (2)| 00:00:02 |                                   
    |* 13 |             INDEX RANGE SCAN         | SYS_C00116570          |     1 |       |     1   (0)| 00:00:01 |                                   
    |* 14 |           TABLE ACCESS FULL          | SERVICE_DELIVERY_POINT |   723K|    13M|  9699   (2)| 00:01:57 |                                   
    |* 15 |          TABLE ACCESS BY INDEX ROWID | NMI                    |     1 |    22 |     5   (0)| 00:00:01 |                                   
    |* 16 |           INDEX RANGE SCAN           | IDX_NMI_ID_NK          |     2 |       |     2   (0)| 00:00:01 |                                   
    |* 17 |         TABLE ACCESS BY INDEX ROWID  | SDP_LOGICAL_ASSET      |     1 |    13 |     5   (0)| 00:00:01 |                                   
    |* 18 |          INDEX RANGE SCAN            | IDX_SLA_SDP_SK         |     2 |       |     2   (0)| 00:00:01 |                                   
    |* 19 |        INDEX RANGE SCAN              | IDX_A_SAPINTLOGDEV_SK  |     2 |       |     2   (0)| 00:00:01 |                                   
    |* 20 |      TABLE ACCESS FULL               | REGISTER               | 76113 |  2378K| 26743   (2)| 00:05:21 |                                   
    |* 21 |     TABLE ACCESS FULL                | SDP_LOGICAL_REGISTER   |  5095K|    63M| 20245   (2)| 00:04:03 |                                   
    |  22 |    VIEW                              |                        | 90889 |   443K| 47021   (2)| 00:09:25 |                                   
    |* 23 |     HASH JOIN                        |                        | 90889 |  2307K| 47021   (2)| 00:09:25 |                                   
    |* 24 |      TABLE ACCESS FULL               | REGISTER               | 76113 |   966K| 26743   (2)| 00:05:21 |                                   
    |* 25 |      TABLE ACCESS FULL               | SDP_LOGICAL_REGISTER   |  5095K|    63M| 20245   (2)| 00:04:03 |                                   
    Predicate Information (identified by operation id):                                   
       2 - access("SERVICE_DELIVERY_POINT_SK"="TMP"."SERVICE_DELIVERY_POINT_SK")                                   
       3 - access("SERVICE_DELIVERY_POINT_SK"="SERVICE_DELIVERY_POINT_SK" AND                                    
                  "SAP_INT_LOGICAL_REGISTER_SK"="SAP_INT_LOGICAL_REGISTER_SK")                                   
       4 - access("ASSET_CD"="EQUIP_CD")                                   
       5 - filter("ROW_CURRENT_IND"='Y')                                   
       9 - access("NETWORK_TARIFF_CD"="NETWORK_TARIFF_CD")                                   
      10 - filter("ROW_CURRENT_IND"='Y')                                   
      12 - filter("ROW_CURRENT_IND"='Y' AND "CONROL_REGISTER"='X')                                   
      13 - access("METER_CONFIG_HEADER_SK"="METER_CONFIG_HEADER_SK")                                   
      14 - filter("ROW_CURRENT_IND"='Y')                                   
      15 - filter("ROW_CURRENT_IND"='Y' AND ("NMI_STATUS_CD"='A' OR "NMI_STATUS_CD"='D'))                                   
      16 - access("NMI_SK"="NMI_SK")                                   
      17 - filter("ROW_CURRENT_IND"='Y')                                   
      18 - access("SERVICE_DELIVERY_POINT_SK"="SERVICE_DELIVERY_POINT_SK")                                   
      19 - access("SAP_INT_LOG_DEVICE_SK"="SAP_INT_LOG_DEVICE_SK")                                   
      20 - filter((SUBSTR("REGISTER_ID_CD",1,1)='4' OR SUBSTR("REGISTER_ID_CD",1,1)='5' OR                                    
                  SUBSTR("REGISTER_ID_CD",1,1)='6') AND "REGISTER_TYPE_CD"='C' AND "ROW_CURRENT_IND"='Y')                                   
      21 - filter("ROW_CURRENT_IND"='Y')                                   
      23 - access("SAP_INT_LOGICAL_REGISTER_SK"="SAP_INT_LOGICAL_REGISTER_SK")                                   
      24 - filter((SUBSTR("REGISTER_ID_CD",1,1)='1' OR SUBSTR("REGISTER_ID_CD",1,1)='2' OR                                    
                  SUBSTR("REGISTER_ID_CD",1,1)='3') AND "REGISTER_TYPE_CD"='C' AND "ROW_CURRENT_IND"='Y')                                   
      25 - filter("ROW_CURRENT_IND"='Y')Edited by: abhilash173 on Feb 24, 2013 9:16 PM
    Edited by: abhilash173 on Feb 24, 2013 9:18 PM

    Hi Paul,
    I misread your question initially .The system stats are outdated in both ( same result as seen from aux_stats) .I am not a DBA and do not have access to gather system stats fresh.
    select * from sys.aux_stats$
    SNAME     PNAME     PVAL1     PVAL2
    SYSSTATS_INFO     STATUS     NULL     COMPLETED
    SYSSTATS_INFO     DSTART     NULL     02-16-2011 15:24
    SYSSTATS_INFO     DSTOP     NULL     02-16-2011 15:24
    SYSSTATS_INFO     FLAGS     1     NULL
    SYSSTATS_MAIN     CPUSPEEDNW     1321.20523     NULL
    SYSSTATS_MAIN     IOSEEKTIM     10     NULL
    SYSSTATS_MAIN     IOTFRSPEED     4096     NULL
    SYSSTATS_MAIN     SREADTIM     NULL     NULL
    SYSSTATS_MAIN     MREADTIM     NULL     NULL
    SYSSTATS_MAIN     CPUSPEED     NULL     NULL
    SYSSTATS_MAIN     MBRC     NULL     NULL
    SYSSTATS_MAIN     MAXTHR     NULL     NULL
    SYSSTATS_MAIN     SLAVETHR     NULL     NULL

  • One query - one database - different execution plan for different users.

    Hi everyone.
    I've encountered one of the strangest things I've ever seen with Oracle.  I'm hoping that someone else here has seen something like this before and solved it!  On an 11g database I have a query that runs differently depending on which user runs it.  If the owner of the tables or someone with the DBA role runs the query I get a perfect execution plan.  If someone else runs it, I get a really bad execution plan - though the query still executes.  So it almost seems like depending on who is running the query, the optimizer might not have access to the same statistics??  I'm really grasping at straws here - any help would be greatfully accepted!!!
    Here is the query and the two plans for it...
    On TASD as a General User (Bad execution plan) - CA17062 is USER
    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
    Connected as ca17062
    SQL> explain plan for
    select w.worker_id, w.worker_name
      from worker_v                   w,
           worker_cost_centre_v       c
    where w.worker_id = c.worker_id
       and c.effective_date <= trunc(sysdate)
       and c.expiration_date >= trunc(sysdate)
       and c.cost_centre = '100033'
       and pkg_taw_security.user_worker_access('CA17062',
                                               'TIMEKEEPER',
                                               w.worker_id,
                                               trunc(sysdate)) = 1
    order by w.worker_name;
    Explained
    Executed in 0.234 seconds
    PLAN_TABLE_OUTPUT
    Plan hash value: 1726112176
    | Id  | Pid | Ord | Operation                      | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 |     |   8 | SELECT STATEMENT               |                        |    18 |  1800 |   606   (1)| 00:00:01 |
    |   1 |   0 |   7 |  SORT ORDER BY                 |                        |    18 |  1800 |   606   (1)| 00:00:01 |
    |*  2 |   1 |   6 |   HASH JOIN                    |                        |    18 |  1800 |   605   (1)| 00:00:01 |
    |   3 |   2 |   3 |    VIEW                        | WORKER_COST_CENTRE_V   |    18 |   558 |    19   (0)| 00:00:01 |
    |*  4 |   3 |   2 |     TABLE ACCESS BY INDEX ROWID| WORKER_COST_CENTRE_TBL |    18 |   522 |    19   (0)| 00:00:01 |
    |*  5 |   4 |   1 |      INDEX RANGE SCAN          | WORKER_CC_CC_IDX       |    29 |       |     3   (0)| 00:00:01 |
    |*  6 |   2 |   5 |    VIEW                        | WORKER_V               |   161K|    10M|   584   (1)| 00:00:01 |
    |   7 |   6 |   4 |     TABLE ACCESS FULL          | WORKER_TBL             |   161K|  3466K|   584   (1)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("W"."WORKER_ID"="C"."WORKER_ID")
       4 - filter("X"."EXPIRATION_DATE">=TRUNC(SYSDATE@!))
    PLAN_TABLE_OUTPUT
       5 - access("X"."COST_CENTRE"='100033' AND "X"."EFFECTIVE_DATE"<=TRUNC(SYSDATE@!))
       6 - filter("PKG_TAW_SECURITY"."USER_WORKER_ACCESS"('CA17062','TIMEKEEPER',"W"."WORKER_ID",TRUN
                  C(SYSDATE@!))=1)
    About
      - XPlan v1.2 by Adrian Billington (http://www.oracle-developer.net)
    23 rows selected
    Executed in 0.577 seconds
    WORKER_ID WORKER_NAME
    123703    FADDEN, CLAYTON
    11131     HAHN, BRAD
    33811     HALL, MAUREEN
    53934     JANES, CATHERINE
    Executed in 35.241 seconds
    On TASD as the owner of the tables or as someone with the DBA role (Good Execution) - TAS is USER:
    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
    Connected as tas
    SQL> explain plan for
    select w.worker_id, w.worker_name
      from worker_v                   w,
           worker_cost_centre_v       c
    where w.worker_id = c.worker_id
       and c.effective_date <= trunc(sysdate)
       and c.expiration_date >= trunc(sysdate)
       and c.cost_centre = '100033'
       and pkg_taw_security.user_worker_access('CA17062',
                                               'TIMEKEEPER',
                                               w.worker_id,
                                               trunc(sysdate)) = 1
    order by w.worker_name;
    Explained
    Executed in 0.203 seconds
    PLAN_TABLE_OUTPUT
    Plan hash value: 3435904055
    | Id  | Pid | Ord | Operation                      | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 |     |   8 | SELECT STATEMENT               |                        |    18 |   918 |    38   (3)| 00:00:01 |
    |   1 |   0 |   7 |  SORT ORDER BY                 |                        |    18 |   918 |    38   (3)| 00:00:01 |
    |   2 |   1 |   6 |   NESTED LOOPS                 |                        |       |       |            |          |
    |   3 |   2 |   4 |    NESTED LOOPS                |                        |    18 |   918 |    37   (0)| 00:00:01 |
    |*  4 |   3 |   2 |     TABLE ACCESS BY INDEX ROWID| WORKER_COST_CENTRE_TBL |    18 |   522 |    19   (0)| 00:00:01 |
    |*  5 |   4 |   1 |      INDEX RANGE SCAN          | WORKER_CC_CC_IDX       |    29 |       |     3   (0)| 00:00:01 |
    |*  6 |   3 |   3 |     INDEX UNIQUE SCAN          | WORKER_PK              |     1 |       |     0   (0)| 00:00:01 |
    |   7 |   2 |   5 |    TABLE ACCESS BY INDEX ROWID | WORKER_TBL             |     1 |    22 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - filter("X"."EXPIRATION_DATE">=TRUNC(SYSDATE@!))
       5 - access("X"."COST_CENTRE"='100033' AND "X"."EFFECTIVE_DATE"<=TRUNC(SYSDATE@!))
    PLAN_TABLE_OUTPUT
       6 - access("X"."WORKER_ID"="X"."WORKER_ID")
           filter("PKG_TAW_SECURITY"."USER_WORKER_ACCESS"('CA17062','TIMEKEEPER',"X"."WORKER_ID",TRUN
                  C(SYSDATE@!))=1)
    About
      - XPlan v1.2 by Adrian Billington (http://www.oracle-developer.net)
    23 rows selected
    Executed in 0.624 seconds
    WORKER_ID WORKER_NAME
    123703    FADDEN, CLAYTON
    11131     HAHN, BRAD
    33811     HALL, MAUREEN
    53934     JANES, CATHERINE
    Executed in 1.307 seconds
    THANKS!!!
    Cory Aston

    I reran the whole thing - with full declared view names and display_cursor.  Here are the results...
    On TASD as CA17062  (BAD EXECUTION PLAN)
    SQL> set linesize 160
    SQL> set serveroutput off
    SQL>
    SQL> select /*+ gather_plan_statistics */
      2         w.worker_id, w.worker_name
      3    from tas.worker_v                   w,
      4         tas.worker_cost_centre_v       c
      5   where w.worker_id = c.worker_id
      6     and c.effective_date <= trunc(sysdate)
      7     and c.expiration_date >= trunc(sysdate)
      8     and c.cost_centre = '100033'
      9     and tas_user.pkg_taw_security.user_worker_access('CA17062',
    10                                             'TIMEKEEPER',
    11                                             w.worker_id,
    12                                             trunc(sysdate)) = 1
    13   order by w.worker_name;
    WORKER_ID WORKER_NAME
    123703    FADDEN, CLAYTON
    11131     HAHN, BRAD
    33811     HALL, MAUREEN
    53934     JANES, CATHERINE
    SQL>
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  gs5vtgany8vbv, child number 3
    select /*+ gather_plan_statistics */        w.worker_id, w.worker_name
    from tas.worker_v                   w,        tas.worker_cost_centre_v
          c  where w.worker_id = c.worker_id    and c.effective_date <=
    trunc(sysdate)    and c.expiration_date >= trunc(sysdate)    and
    c.cost_centre = '100033'    and tas_user.pkg_taw_security.user_worker_ac
    cess('CA17062',
    'TIMEKEEPER',                                            w.worker_id,
                                             trunc(sysdate)) = 1  order by
    w.worker_name
    Plan hash value: 1726112176
    | Id  | Operation                      | Name                   | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   0 | SELECT STATEMENT               |                        |      1 |        |      4 |00:00:18.52 |     947K|       |       |          |
    |   1 |  SORT ORDER BY                 |                        |      1 |      4 |      4 |00:00:18.52 |     947K|  2048 |  2048 | 2048  (0)|
    |*  2 |   HASH JOIN                    |                        |      1 |      4 |      4 |00:00:15.84 |     947K|  1348K|  1348K|  791K (0)|
    |   3 |    VIEW                        | WORKER_COST_CENTRE_V   |      1 |      4 |      4 |00:00:00.01 |      18 |       |       |          |
    |*  4 |     TABLE ACCESS BY INDEX ROWID| WORKER_COST_CENTRE_TBL |      1 |      4 |      4 |00:00:00.01 |      18 |       |       |          |
    |*  5 |      INDEX RANGE SCAN          | WORKER_CC_CC_IDX       |      1 |     29 |     21 |00:00:00.01 |       3 |       |       |          |
    |*  6 |    VIEW                        | WORKER_V               |      1 |    161K|      4 |00:00:15.84 |     946K|       |       |          |
    |   7 |     TABLE ACCESS FULL          | WORKER_TBL             |      1 |    161K|    160K|00:00:00.09 |    2135 |       |       |          |
    Predicate Information (identified by operation id):
       2 - access("W"."WORKER_ID"="C"."WORKER_ID")
       4 - filter("X"."EXPIRATION_DATE">=TRUNC(SYSDATE@!))
       5 - access("X"."COST_CENTRE"='100033' AND "X"."EFFECTIVE_DATE"<=TRUNC(SYSDATE@!))
       6 - filter("PKG_TAW_SECURITY"."USER_WORKER_ACCESS"('CA17062','TIMEKEEPER',"W"."WORKER_ID",TRUNC(SYSDATE@!))=1)
    Note
       - cardinality feedback used for this statement
    39 rows selected.
    SQL>
    On TASD as TAS: (GOOD EXECUTION PLAN)
    SQL> set serveroutput off
    SQL>
    SQL> select /*+ gather_plan_statistics */
      2         w.worker_id, w.worker_name
      3    from tas.worker_v                   w,
      4         tas.worker_cost_centre_v       c
      5   where w.worker_id = c.worker_id
      6     and c.effective_date <= trunc(sysdate)
      7     and c.expiration_date >= trunc(sysdate)
      8     and c.cost_centre = '100033'
      9     and tas_user.pkg_taw_security.user_worker_access('CA17062',
    10                                             'TIMEKEEPER',
    11                                             w.worker_id,
    12                                             trunc(sysdate)) = 1
    13   order by w.worker_name;
    WORKER_ID WORKER_NAME
    123703    FADDEN, CLAYTON
    11131     HAHN, BRAD
    33811     HALL, MAUREEN
    53934     JANES, CATHERINE
    SQL>
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  gs5vtgany8vbv, child number 1
    select /*+ gather_plan_statistics */        w.worker_id, w.worker_name
    from tas.worker_v                   w,        tas.worker_cost_centre_v
          c  where w.worker_id = c.worker_id    and c.effective_date <=
    trunc(sysdate)    and c.expiration_date >= trunc(sysdate)    and
    c.cost_centre = '100033'    and tas_user.pkg_taw_security.user_worker_ac
    cess('CA17062',
    'TIMEKEEPER',                                            w.worker_id,
                                             trunc(sysdate)) = 1  order by
    w.worker_name
    Plan hash value: 3435904055
    | Id  | Operation                      | Name                   | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   0 | SELECT STATEMENT               |                        |      1 |        |      4 |00:00:00.01 |     185 |       |       |          |
    |   1 |  SORT ORDER BY                 |                        |      1 |      4 |      4 |00:00:00.01 |     185 |  2048 |  2048 | 2048  (0)|
    |   2 |   NESTED LOOPS                 |                        |      1 |        |      4 |00:00:00.01 |     185 |       |       |          |
    |   3 |    NESTED LOOPS                |                        |      1 |      4 |      4 |00:00:00.01 |     181 |       |       |          |
    |*  4 |     TABLE ACCESS BY INDEX ROWID| WORKER_COST_CENTRE_TBL |      1 |      4 |      4 |00:00:00.01 |      18 |       |       |          |
    |*  5 |      INDEX RANGE SCAN          | WORKER_CC_CC_IDX       |      1 |     29 |     21 |00:00:00.01 |       3 |       |       |          |
    |*  6 |     INDEX UNIQUE SCAN          | WORKER_PK              |      4 |      1 |      4 |00:00:00.01 |     163 |       |       |          |
    |   7 |    TABLE ACCESS BY INDEX ROWID | WORKER_TBL             |      4 |      1 |      4 |00:00:00.01 |       4 |       |       |          |
    Predicate Information (identified by operation id):
       4 - filter("X"."EXPIRATION_DATE">=TRUNC(SYSDATE@!))
       5 - access("X"."COST_CENTRE"='100033' AND "X"."EFFECTIVE_DATE"<=TRUNC(SYSDATE@!))
       6 - access("X"."WORKER_ID"="X"."WORKER_ID")
           filter("PKG_TAW_SECURITY"."USER_WORKER_ACCESS"('CA17062','TIMEKEEPER',"X"."WORKER_ID",TRUNC(SYSDATE@!))=1)
    Note
       - cardinality feedback used for this statement
    39 rows selected.
    SQL>

  • Different Info Packages for the same data source.

    Hi Team,
    I have a question, which i asked before that but i ended up with different solution.
    I want to load 02.2002 to till date into ODS. Data source is 0FI_AR_10.
    My boss wants in this way .
    1) one infopackage for 02.2002 to 02.2005 with init.
    2) one infopack for 03.2005 to 07.2008 with init for the same datasource.
    3) one info pack with no selection criteira.
    What will be the result ?
    My guess is, Once we do init for the time period 02.2002 to 02.2005 ,
    the system with note the timepreiod for the Datasource.
    When i try to do Init for the second, the system will say init already exits for the data source. And it will not allow me to do init for the second selection.
    Correct me if  i am wrong.
    Regards,
    -Sonti-

    Your planned InfoPackages:
    - 1) one infopackage for 02.2002 to 02.2005 with init.
    - 2) one infopack for 03.2005 to 07.2008 with init for the same datasource.
    - 3) one info pack with no selection criteira.
    As the selection criteria of package 1) & 2) do not overlap, is it possible.
    For package 3), you need to do it as delta update instead of initialisation.  Package 3) with no selection criteria overlaps with package 1) & 2).
    Refer to the Help Documentation, which explains this quite clearly.
    Link: [Maintaining InfoPackage - Tab Page: Updating|http://help.sap.com/saphelp_nw70/helpdata/en/e3/e60138fede083de10000009b38f8cf/frameset.htm]
    >For selection criteria that do not overlap, several initialization criteria are possible for initializing the delta process when scheduling InfoPackages for data from an SAP system. This gives you the option of loading the relevant data for the delta process, step by step into the Business Information Warehouse. For example, you can load the data into BI for cost center 1000 in the first step, and the data for cost center 2000 in the second step.
    >A delta requested after several initializations, contains the super set of all the successful initial selections as a selection condition. This selection condition can then no longer be changed for the delta.
    Hope this help.

  • Sales Deal with two different validation dates for the same material

    Hi SAPers,
    I am trying to create a u201CSales Dealu201D VB31, for the same material/condition, but with two different validation dates. After the creation of the first record, I select u201CNew conditionu201D button, but the system give me the message VK104, u201Cthe condition is being processed in the current session.u201D.
    How can I solve this issue?
    Thanks in advance.
    Pedro

    We can't have multiple records for the same condition and key values valid on the same date. The condition end date is part of the primary key in the database table. The date ranges between the records cannot overlap. When you create a new record, usually the end date is set to 12/31/9999 by default. If you need to have this deal to end on a different date and a new deal to start afterwards, then first you need to change 12/31/9999 to a different date.
    Also usually I try to exit the screen between the transactions.

  • Different 'execution plans' for same sql in 10R2

    DB=10.2.0.5
    OS=RHEL 3
    Im not sure of this, but seeing different plans for same SQL.
    select sql_text from v$sqlarea where sql_id='92mb4z83fg4st'; <---TOP SQL from AWR
    SELECT /*+ OPAQUE_TRANSFORM */ "ENDUSERID","LASTLOGINATTEMPTTIMESTAMP","LOGINSOURCECD","LOGINSUCCESSFLG",
    "ENDUSERLOGINATTEMPTHISTORYID","VERSION_NUM","CREATEDATE"
    FROM "BOMB"."ENDUSERLOGINATTEMPTHISTORY" "ENDUSERLOGINATTEMPTHISTORY";
    SQL> set autotrace traceonly
    SQL> SELECT /*+ OPAQUE_TRANSFORM */ "ENDUSERID","LASTLOGINATTEMPTTIMESTAMP","LOGINSOURCECD","LOGINSUCCESSFLG",
    "ENDUSERLOGINATTEMPTHISTORYID","VERSION_NUM","CREATEDATE"
    FROM "BOMB"."ENDUSERLOGINATTEMPTHISTORY" "ENDUSERLOGINATTEMPTHISTORY"; 2 3
    1822203 rows selected.
    Execution Plan
    Plan hash value: 568996432
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1803K| 75M| 2919 (2)| 00:00:36 |
    | 1 | TABLE ACCESS FULL| ENDUSERLOGINATTEMPTHISTORY | 1803K| 75M| 2919 (2)| 00:00:36 |
    Statistics
    0 recursive calls
    0 db block gets
    133793 consistent gets
    0 physical reads
    0 redo size
    76637183 bytes sent via SQL*Net to client
    1336772 bytes received via SQL*Net from client
    121482 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1822203 rows processed
    ===================================== another plan ===============
    SQL> select * from TABLE(dbms_xplan.display_awr('92mb4z83fg4st'));
    15 rows selected.
    Execution Plan
    Plan hash value: 3015018810
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | COLLECTION ITERATOR PICKLER FETCH| DISPLAY_AWR |
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    24 recursive calls
    24 db block gets
    49 consistent gets
    0 physical reads
    0 redo size
    1529 bytes sent via SQL*Net to client
    492 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    15 rows processed
    =========second one shows only 15 rows...
    Which one is correct ?

    Understood, second plan is for self 'dbms_xplan'.
    Anyhow I opened a new session where I did NOT on 'auto-trace'. but plan is somewhat than the original.
    SQL> /
    PLAN_TABLE_OUTPUT
    SQL_ID 92mb4z83fg4st
    SELECT /*+ OPAQUE_TRANSFORM */ "ENDUSERID","LASTLOGINATTEMPTTIMESTAMP","LOGINSOURCECD","
    LOGINSUCCESSFLG","ENDUSERLOGINATTEMPTHISTORYID","VERSION_NUM","CREATEDATE" FROM
    "BOMB"."ENDUSERLOGINATTEMPTHISTORY" "ENDUSERLOGINATTEMPTHISTORY"
    Plan hash value: 568996432
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | | | 2919 (100)| |
    | 1 | TABLE ACCESS FULL| ENDUSERLOGINATTEMPTHISTORY | 1803K| 75M| 2919 (2)| 00:00:36 |
    15 rows selected.
    I am just wondering, which plan is the accurate and which I need to believe ?

  • Different execution plan in ApEx and SQL/PLUS

    Hi
    I have weird problem with sql query exectuion plans.
    DB version: 10.2.0.1
    ApEx version: 3.1.2
    I have workspace parsed as SCHEMA1.
    I have a view under different schema - SCHEMA2.view1 and a function SCHEMA2.func1.
    I have a query like SELECT * from SCHEMA2.view1 WHERE col1 = SCHEMA2.func1(:bind1)
    "col1" is a indexed column.
    When I execute this query in SQL/PLUS under user SCHEMA1 with the same bind value, then index is used perfectly.
    When I execute this query in ApEx report then index is not used, full scan is performed and hash join is done between the tables used in the view and explain plan shows that a view is formed during execution.
    What can be the reason for such a different behaviour.
    Statistics are freshly calculated, FIRST_ROWS hint doesn't help, using the INDEX hint results only index full scan.
    This happens only if I use a view and pl/sql function together in the query. If I use view with Oracle built in function like NVL instead then it works perfectly. Also when I access directly the same tabels with the same PL/SQL function then the execution plan is perfect. Only if the view and pl/sql function is used together in the query then execution plan is bad.
    It is not a problem of this specific query but, many different other queries with same pattern also. I have tried ApEx versions 3.0, 3.1.1 and 3.1.2.
    At the same time the exectuion plan is good in SQL/PLUS and TOAD.
    Any ideas?
    Best regards,
    jan

    I didn't help. But I rewrote the queries so that there is no database view and PL/SQL function used in the same query. I still don't know the reason for such different behavior, but I just try to accept it and keep in mind for future :)
    Thanks anyway!
    jan

  • Can two Instances of Planning share the same SQl Server Instance?

    Hi
    Can anyone clarify me on the below
    Is it possible to have our DEV and TEST instances of planning (on different host servers) point to different tables in the same instance of SQL Server 2005. I know that the apllication databases can be directed to different table names but what about the core tables:
    FSDHAADMS
    FSDHBIP
    FSDHSS
    FSDHPLANAPP
    FSDHPLANSYS
    Thanks in advance.

    I think it will work. As long as you create separate SQL databases for the planning system files for dev and prod on the sql server. If your planning web for dev is deployed on server x, and planning web for prod is on server y, when you run config utility on server x you would point to the SQL database u created for dev. Repeat on prod when u run the config utility just point to the planning system database you created for prod.
    haven't done this myself but sounds possible.

Maybe you are looking for

  • Performing math on Decode function tags and moving averages

    I have a query shown below to create columns for my report. Can I use the field names as shown in bold to perform math functions? Is there an easy way to do this? select Data_date, SUM(DECODE(tag_id,'SEF_F0348I',avg_value,NULL))"TE_Flow_mgd", SUM(DEC

  • DNxHD renders either too dark or effect isnt present. How is this the case?

    I was able to resolve the dark issue by referencing another discussion where it mentions that if you render to dnxhd that you should choose RGB and not 709 when exporting. That did work, and the footage was lighter, but almost TOO light. It resembled

  • Creating a DVD from flash movies (flv)

    Does iDVD 6 support flash movies (flv) importing? -pom-

  • Change scale legend programatically?

    Is there any way to change the scale legend programattically? I have a graph with two plots and two y-scales. I won't know if the second plot refers to the first or second scale until run-time. I'd like to adjust the scale legend appropriately. I can

  • Wget an Oracle Note ID?

    Hi, Can wget be used to download note IDs from my oracle support/metalink? I am aware of the wget script that downloads patches. Modifying that script doesn't seem to work even if the correct login details are used. Here's an example Note ID: Note ID