Optimizer choosing different plans when ROWNUM filter. [UPDATED: 11.2.0.1]

I'm having a couple of issues with a query, and I can't figure out the best way to reach a solution.
Platform Information
Windows Server 2003 R2
Oracle 10.2.0.4
Optimizer Settings
SQL > show parameter optimizer
NAME                                 TYPE        VALUE
optimizer_dynamic_sampling           integer     2
optimizer_features_enable            string      10.2.0.4
optimizer_index_caching              integer     90
optimizer_index_cost_adj             integer     30
optimizer_mode                       string      ALL_ROWS
optimizer_secure_view_merging        boolean     TRUEThe query below, is a simple "Top N" query, where the top result is returned. Here it is, with bind variables in the same location as the application code:
SELECT     PRODUCT_DESC
FROM
     SELECT     PRODUCT_DESC
     ,     COUNT(*)     AS CNT
     FROM     USER_VISITS     
     JOIN     PRODUCT     ON PRODUCT.PRODUCT_OID = USER_VISITS.PRODUCT_OID
     WHERE     PRODUCT.PRODUCT_DESC != 'Home'     
     AND     VISIT_DATE
          BETWEEN
               ADD_MONTHS                    
                    TRUNC                    
                         TO_DATE               
                              :vCurrentYear
                         ,     'YYYY'
                    ,     'YEAR'
               ,     3*(:vCurrentQuarter-1)
          AND
               ADD_MONTHS                    
                    TRUNC                    
                         TO_DATE               
                              :vCurrentYear
                         ,     'YYYY'
                    ,     'YEAR'
               ,     3*:vCurrentQuarter
               ) - INTERVAL '1' DAY               
     GROUP BY PRODUCT_DESC
     ORDER BY CNT DESC
WHERE     ROWNUM <= 1;
Explain Plan
The explain plan I receive when running the query above.
| Id  | Operation                         | Name                          | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
|*  1 |  COUNT STOPKEY                    |                               |      1 |        |      1 |00:00:34.92 |   66343 |       |       |          |
|   2 |   VIEW                            |                               |      1 |      1 |      1 |00:00:34.92 |   66343 |       |       |          |
|*  3 |    FILTER                         |                               |      1 |        |      1 |00:00:34.92 |   66343 |       |       |          |
|   4 |     SORT ORDER BY                 |                               |      1 |      1 |      1 |00:00:34.92 |   66343 |  2048 |  2048 | 2048  (0)|
|   5 |      SORT GROUP BY NOSORT         |                               |      1 |      1 |     27 |00:00:34.92 |   66343 |       |       |          |
|   6 |       NESTED LOOPS                |                               |      1 |      2 |  12711 |00:00:34.90 |   66343 |       |       |          |
|   7 |        TABLE ACCESS BY INDEX ROWID| PRODUCT                       |      1 |     74 |     77 |00:00:00.01 |      44 |       |       |          |
|*  8 |         INDEX FULL SCAN           | PRODUCT_PRODDESCHAND_UNQ      |      1 |      1 |     77 |00:00:00.01 |       1 |       |       |          |
|*  9 |        INDEX FULL SCAN            | USER_VISITS#PK                |     77 |      2 |  12711 |00:00:34.88 |   66299 |       |       |          |
Predicate Information (identified by operation id):
   1 - filter(ROWNUM<=1)
   3 - filter(ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(:VCURRENTYEAR),'YYYY'),'fmyear'),3*(:VCURRENTQUARTER-1))<=ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(:VCURR
              ENTYEAR),'YYYY'),'fmyear'),3*:VCURRENTQUARTER)-INTERVAL'+01 00:00:00' DAY(2) TO SECOND(0))
   8 - filter("PRODUCT"."PRODUCT_DESC"<>'Home')
   9 - access("USER_VISITS"."VISIT_DATE">=ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(:VCURRENTYEAR),'YYYY'),'fmyear'),3*(:VCURRENTQUARTER-1)) AND
              "USER_VISITS"."PRODUCT_OID"="PRODUCT"."PRODUCT_OID" AND "USER_VISITS"."VISIT_DATE"<=ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(:VCURRENTYEAR),'YYYY')
              ,'fmyear'),3*:VCURRENTQUARTER)-INTERVAL'+01 00:00:00' DAY(2) TO SECOND(0))
       filter(("USER_VISITS"."VISIT_DATE">=ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(:VCURRENTYEAR),'YYYY'),'fmyear'),3*(:VCURRENTQUARTER-1)) AND
              "USER_VISITS"."VISIT_DATE"<=ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(:VCURRENTYEAR),'YYYY'),'fmyear'),3*:VCURRENTQUARTER)-INTERVAL'+01 00:00:00' DAY(2)
              TO SECOND(0) AND "USER_VISITS"."PRODUCT_OID"="PRODUCT"."PRODUCT_OID"))
Row Source Generation
TKPROF Row Source Generation
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.01          0          0          0           0
Fetch        2     35.10      35.13          0      66343          0           1
total        4     35.10      35.14          0      66343          0           1
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 62 
Rows     Row Source Operation
      1  COUNT STOPKEY (cr=66343 pr=0 pw=0 time=35132008 us)
      1   VIEW  (cr=66343 pr=0 pw=0 time=35131996 us)
      1    FILTER  (cr=66343 pr=0 pw=0 time=35131991 us)
      1     SORT ORDER BY (cr=66343 pr=0 pw=0 time=35131936 us)
     27      SORT GROUP BY NOSORT (cr=66343 pr=0 pw=0 time=14476309 us)
  12711       NESTED LOOPS  (cr=66343 pr=0 pw=0 time=22921810 us)
     77        TABLE ACCESS BY INDEX ROWID PRODUCT (cr=44 pr=0 pw=0 time=3674 us)
     77         INDEX FULL SCAN PRODUCT_PRODDESCHAND_UNQ (cr=1 pr=0 pw=0 time=827 us)(object id 52355)
  12711        INDEX FULL SCAN USER_VISITS#PK (cr=66299 pr=0 pw=0 time=44083746 us)(object id 52949)However when I run the query with an ALL_ROWS hint I receive this explain plan (reasoning for this can be found here Jonathan's Lewis' response: http://www.freelists.org/post/oracle-l/ORDER-BY-and-first-rows-10-madness,4):
| Id  | Operation                  | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT           |                |     1 |    39 |   223  (25)| 00:00:03 |
|*  1 |  COUNT STOPKEY             |                |       |       |            |          |
|   2 |   VIEW                     |                |     1 |    39 |   223  (25)| 00:00:03 |
|*  3 |    FILTER                  |                |       |       |            |          |
|   4 |     SORT ORDER BY          |                |     1 |    49 |   223  (25)| 00:00:03 |
|   5 |      HASH GROUP BY         |                |     1 |    49 |   223  (25)| 00:00:03 |
|*  6 |       HASH JOIN            |                |   490 | 24010 |   222  (24)| 00:00:03 |
|*  7 |        TABLE ACCESS FULL   | PRODUCT   |    77 |  2849 |     2   (0)| 00:00:01 |
|*  8 |        INDEX FAST FULL SCAN| USER_VISITS#PK |   490 |  5880 |   219  (24)| 00:00:03 |
Predicate Information (identified by operation id):
   1 - filter(ROWNUM<=1)
   3 - filter(ADD_MONTHS(TRUNC(TO_DATE(:VCURRENTYEAR,'YYYY'),'fmyear'),3*(TO_NUMBER(:
              VCURRENTQUARTER)-1))<=ADD_MONTHS(TRUNC(TO_DATE(:VCURRENTYEAR,'YYYY'),'fmyear'),3*TO_N
              UMBER(:VCURRENTQUARTER))-INTERVAL'+01 00:00:00' DAY(2) TO SECOND(0))
   6 - access("USER_VISITS"."PRODUCT_OID"="PRODUCT"."PRODUCT_OID")
   7 - filter("PRODUCT"."PRODUCT_DESC"<>'Home')
   8 - filter("USER_VISITS"."VISIT_DATE">=ADD_MONTHS(TRUNC(TO_DATE(:VCURRENTYEAR,'YYY
              Y'),'fmyear'),3*(TO_NUMBER(:VCURRENTQUARTER)-1)) AND
              "USER_VISITS"."VISIT_DATE"<=ADD_MONTHS(TRUNC(TO_DATE(:VCURRENTYEAR,'YYYY'),'fmyear'),
              3*TO_NUMBER(:VCURRENTQUARTER))-INTERVAL'+01 00:00:00' DAY(2) TO SECOND(0))And the TKPROF Row Source Generation:
call     count       cpu    elapsed       disk      query    current        rows
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        3      0.51       0.51          0        907          0          27
total        5      0.51       0.51          0        907          0          27
Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 62 
Rows     Row Source Operation
     27  FILTER  (cr=907 pr=0 pw=0 time=513472 us)
     27   SORT ORDER BY (cr=907 pr=0 pw=0 time=513414 us)
     27    HASH GROUP BY (cr=907 pr=0 pw=0 time=512919 us)
  12711     HASH JOIN  (cr=907 pr=0 pw=0 time=641130 us)
     77      TABLE ACCESS FULL PRODUCT (cr=5 pr=0 pw=0 time=249 us)
  22844      INDEX FAST FULL SCAN USER_VISITS#PK (cr=902 pr=0 pw=0 time=300356 us)(object id 52949)The query with the ALL_ROWS hint returns data instantly, while the other one takes about 70 times as long.
Interestingly enough BOTH queries generate plans with estimates that are WAY off. The first plan is estimating 2 rows, while the second plan is estimating 490 rows. However the real number of rows is correctly reported in the Row Source Generation as 12711 (after the join operation).
TABLE_NAME                       NUM_ROWS     BLOCKS
USER_VISITS                        196044       1049
INDEX_NAME                         BLEVEL LEAF_BLOCKS DISTINCT_KEYS CLUSTERING_FACTOR LAST_ANALYZED
USER_VISITS#PK                          2         860        196002          57761 07/24/2009 13:17:59
COLUMN_NAME                    NUM_DISTINCT LOW_VALUE            HIGH_VALUE                                 DENSITY     NUM_NULLS HISTOGRAM
VISIT_DATE                           195900 786809010E0910       786D0609111328                      .0000051046452272          0 NONEI don't know how the first one is estimating 2 rows, but I can compute the second's cardinality estimates by assuming a 5% selectivity for the TO_DATE() functions:
SQL > SELECT ROUND(0.05*0.05*196044) FROM DUAL;
ROUND(0.05*0.05*196044)
                    490However, removing the bind variables (and clearing the shared pool), does not change the cardinality estimates at all.
I would like to avoid hinting this plan if possible and that is why I'm looking for advice. I also have a followup question.
Edited by: Centinul on Sep 20, 2009 4:10 PM
See my last post for 11.2.0.1 update.

Centinul wrote:
You could potentially perform testing with either a CARDINALITY or OPT_ESTIMATE hint to see if the execution plan changes dramatically to improve performance. The question then becomes > whether this be sufficient to over-rule the first rows optimizer so that it does not use an index access which will avoid a sort.I tried doing that this morning by increasing the cardinality from the USER_VISITS table to a value such that the estimate was about that of the real amount of data. However the plan did not change.
Could you use the ROW_NUMBER analytic function instead of ROWNUMInterestingly enough, when I tried this it generated the same plan as was used with the ALL_ROWS hint, so I may implement this query for now.
I do have two more followup questions:
1. Even though a better plan is picked the optimizer estimates are still off by a large margin because of bind variables and 5%* 5% * NUM_ROWS. How do I get the estimates in-line with the actual values? Should I really fudge statistics?
2. Should I raise a bug report with Oracle over the behavior of the original query?That is great that the ROW_NUMBER analyitic function worked. You may want to perform some testing with this before implementing it in production to see whether Oracle performs significantly more logical or physical I/Os with the ROW_NUMBER analytic function compared to the ROWNUM solution with the ALL_ROWS hint.
As Timur suggests, seeing a 10053 trace during a hard parse of both queries (with and without the ALL_ROWS hint) would help determine what is happening. It could be that a histogram exists which is feeding bad information to the optimizer, causing distorted cardinality in the plan. If bind peeking is used, the 5% * 5% rule might not apply, especially if a histogram is involved. Also, the WHERE clause includes "PRODUCT.PRODUCT_DESC != 'Home'" which might affect the cardinality in the plan.
Your question may have prompted the starting of a thread in the SQL forum yesterday on the topic of ROWNUM, but it appears that thread was removed from the forum within the last couple hours.
Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.

Similar Messages

  • How do I choose an image when creating or updating a Contact?

    Hey All,
    I just upgraded to Mountain Lion and I'm converting all of my contacts (from various accounts) to use the iCloud service, and all is going very well except for one small thing.  When I either update or create a new contact via the Contacts application, I cannot choose a custom image to associate with a contact.  The application only allows me to choose from a list of "Defaults", "Recently Used" or allows me to take a picture from my computer's camera.  It seems odd that I can't simply select any image from my hard drive (or from iPhoto), but maybe I haven't set something up correctly.
    The web interface for iCloud allows me to select a custom image from my hard drive so I have a work around, but its a bit clunky to do a lot of them.
    Anyone else having this problem?
    Thanks!!!

    When you're in the contact photo edit screen, in the bottom right there is another edit button, click that and drag and drop the desired image in there, scale it as desired, save.

  • Two different plans in TEST & Prod

    hi,
    we have a problem in production database where we find some sql statements running very slow.
    but if you run same SQL statement in TEST it runs < 2 secs.
    Production DB Prod.SchemaA  is exported into TEST DB as Test.SchemaA
    When study the explain plan, we find Prod explain plan is different than test. if you create sql profile, by copying TEST explain plan, it would run faster in Production.
    Now our question is why optimizer goes through two different plans when the schema structure same and data almost same in two databases?
    Note that, we have two almost identical schema's in Production. Prod.SchemaA and Prod.SchemaB has same object names but some Prod.SchemaB may have small difference in indexes/constraints.
    Users would run same SQL statement both in Prod.SchemaA & Prod.SchemaB time to time.
    thanks
    neal

    You can have a clear picture about the accuracy of your statistics by getting the execution plan from memory into the TEST and PROD environment. You can proceed as follows
    PROD> alter session set statistics_level=ALL;
    PROD> execute your query;
    PROD> select * from table (dbms_xplan.display_cursor(null,null, 'ALLSTATS LAST'));
    TEST> alter session set statistics_level=ALL;
    TEST> execute your query
    TEST> select * from table (dbms_xplan.display_cursor(null,null, 'ALLSTATS LAST'));
    This will give an execution plan showing the estimations(E-Rows) done by the CBO and the Actual (A-Rows) rows generated allowing you to judge the accuracy of your statistics.
    The predicate part of the execution plan can also show inportant information.
    Best regards
    Mohamed Houri
    www.hourim.wordpress.com

  • My AppStore id is my apple id n password which is good when purchasing. But when I am updating from update option it ask for a password. The user id I see there is not mine, it's different. How do I change that to my apple Id? Please help me resolve .....

    My AppStore id is my apple id n password which is good when purchasing. But when I am updating from update option it ask for a password. The user id I see there is not mine, it's different. How do I change that to my apple Id? Please help me resolve  this issue. I have tried resetting it but nothing... Either I'm doing something wrong or....

    I believe the issue is with the Apple ID that was used to purchase the App. If you download an App that was purchased under a different Appple ID then all updates will also be linked to the original purchaser's Apple ID. Your Apple ID is the the same ID as your iTunes, iCloud, etc. Some folks use different ID for the different Apple sites. No need for that One ID for all Apple Sites, and if someone else buys an App using their ID and they(you) download that App onto your device and that App requires an update it will ask for the purchasers Apple ID. This happens a lot when folks sell their iPad or give it to someone else and leave some purchased(free) Apps on the iOS device. You cannot change the original ID the App was purchased under. A suggestion would be if someone else has an App that you like but do not want to pay for use their ID or in the future have them gift the App to you.

  • HT4623 I have a Gen 4 Ipod Touch, it is still running with IOS 4. When i go to my settings and select General there is no Software Update button to choose from. How do i update my Ipod to the new IOS system?

    I have a Gen 4 Ipod Touch, it is still running with IOS 4. When i go to my settings and select <General> there is no <Software Update> button to choose from. How do i update my Ipod to the new IOS system?

    You have to hook it up to a computer and update it to ios 5 and then there will be a "software update" button.

  • Macbook pro - iPhoto keep prompting to update after Yosemite update. Error message when trying to update -This update is not available for this Apple ID either because it was bought by a different user or the item was cancelled

    macbook pro - iPhoto keep prompting to update after Yosemite update. Error message when trying to update -This update is not available for this Apple ID either because it was bought by a different user or the item was refunded or cancelled. 

    I only have 1 apple ID and the same was used to set up this early 2011 macbook pro and iPhoto app. I don't want to loose out on any photos. I tried logging out of app store and back in but no luck. PLEEAASEE HELPP!!!
    This problem has been reported by quite a few forum members, who skipped the update to iPhoto 9.5.1 while running Mavericks. In that case try to purchase iPhoto again instead of updating.
    After making your backup try the following:
    Uninstall iPhoto by deleting it from the applications folder, but do not empty the Trash.
    Launch the App Store, click the "Store" menu, and sign in with your AppleID.
    Open the main page of the App Store and search for iPhoto.
    If iPhoto is listed as "Free", click the "Free" button to buy it with your current AppleID.
    If it is not showing as free, there is no help but contacting the App Store Support, as Niel pointed out: http://www.apple.com/support/mac/app-store/contact/

  • Why does my iphone come up with a different email when updating apps?

    why does my iphone come up with a different email when updating apps?
    Everytime I go to update my apps some other persons email or AppleID comes up and I have to cancel.  its annoying enough to have to update all the time but now I have about100 update notifications (don't judge, you probably have a ton of apps too..haha) that are sitting idol, what's up how do I fix?
    thx
    Jackie
    p.s. not updating to iOS6 yet

    I'm sorry Allan, I should have clarified, your answer is improbable (well the first part atleast).
    The apps I have had since the first week of purchase of my iphone back in 2011,  I have not added any apps until 2 months before the last software update.  This starting happening when the new software was implemented but I have not updated to iOS6 yet.  Unless this person was able to hack into my account & transfer them to their account, I do not see how that is possible.
    Prior to seeing this other AppleID, I have a popup to prompt me for my AppleID each time I download content.  Each time I would see mine and enter my password.

  • I can't choose Canadian dollars when picking a CC plan?

    Right here https://creative.adobe.com/plans there's no option for Canadian dollars when choosing a plan.  So I'm stuck picking US?  When the dollar fluctuates, I get to pay more or less each month?  That's not fair.  I hope they're adding Canada as an option soon.

    Lunchababe, as of now we do not have the option to pay in Canadian dollars. So, you need to pay in US dollors only.
    Hopefully, in future we might add that as well but not sure when.

  • HT5232 when trying to transfer my cellular from one ipad to a new one i get through the step where it appears i log in and then get stuck on the next step to choose a plan. any ideas?

    I am trying to transfer my cellular plan from my old ipad to the new one and get stuck after the second step. I currently log in, choose the plan which is the same as the old plan and nothing happens from there. The only way to get out of the screen is to cancel.
    Any ideas?

    Hello Deannefromco,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    When you enable the "Manually manage" option, you can use Autofill to quickly sync audio content from your music library or a selected playlist.
    iTunes: Syncing media content
    http://support.apple.com/kb/ht1351
    Best of luck,
    Mario

  • I keep getting a update notification for iMovie but when i click update it prompts a different apple id

    i keep getting a update notification for iMovie but when i click update it prompts a different apple id and it dose not allow me to change the apple id so I'm left with the old iMovie and no way to update ?? need help

    Deleting and redownloading will not fix it unless it shows as part of your purchases, which it likely doesn't.
    The resolution will depend on how you got the app in the first place.  Check my response here Lost iWorks apps after Yosemite clean install  different app, but same thing.
    If your Mac came with the dvd version, you never tied them to your Apple ID (assuming eligibility to do so), sometimes signing out/in from the App Store fixes it, allowing you to accept under purchases (see my other post).  Otherwise, you'll need to contact Apple.

  • HT1414 When I click "Update" for updating my Iphone on Itunes, it opens up the "Finder" window. It is expecting me to choose some file?

    When I click "Update" for updating my Iphone on Itunes, it opens up the "Finder" window. It is expecting me to choose some file?

    I just had the same problem... any solutions yet?

  • When downloading an update from app store, password is requested from a different user.  How to change user?

    when downloading an update from app store, password is requested from a different user.  How to change user?

    Unfortunately there's no way around this.  you will need that password to update the apps. If he won't give it to you, then i'm not sure what to say.
    You should have kept the account with the Apps you bought yourself.
    Otherwise, as I said, delete the Apps, and buy them again.
    Sorry.

  • A different person id appears on my Iphone when trying to update?

    when trying to update my existing software it comes a different name on my iphone, it is not my apple id
    any help ?
    thanks

    Was that software purchased with another Apple ID other than your own? if it was you can only update that software with that ID. Apps are tied to a particula ID once purchased with that ID.

  • HT4864 When trying to update my Mail Account Mailbox Behaviours settings, when I try to close the settings pane the following messages occur: Invalid Incoming Mail Server The "Incoming Mail Server" field cannot be empty. The incoming mail server box has p

    When trying to update my Mail Account Mailbox Behaviours settings, after making the changes when I try to close the settings pane the following messages occur: Invalid Incoming Mail Server The “Incoming Mail Server” field cannot be empty. The incoming mail server box has in light grey colour: p02-imap.mail.me.com in it and I cannot edit its content. Any ideas what is going on and how to fix it?

    Hi all,
    Mattreichenbach is probably on the right track here with a reset of settings.  I think I've determined the issue has to do with cached account information and inconsistencies for the account name.  This seems to crop up when I've changed my password and it hasn't propagated fully to all the servers, devices, certificates, etc.
    Hopefully many here are on their way to restoration of service by now but it's clear that a lot of people are having the same issues.  Very frustrating and definitely something Apple needs to resolve:  incoming mail server field grayed out, incorrect autopopulation of different fields, other unanticipated behaviors.  If you're still having issues, though, here's what worked for me...
    First, head to the iCloud preferences pane in System Configuration and choose "Sign Out".  When I did this it prompted me with a number of "are you sure" type questions about retaining information on my local machine.  I chose to delete/remove the info each time simply because it should all be restored by the cloud and I didn't want to risk a massive duplication of my data... I will say, I'm back up and running with no issues so I suspect you can make the same delete/remove choices...  But use your own judgment.  I don't want you to lose any data (ie.. please use care as you do this because I cannot bear the thought of causing anyone to experience the pain of data loss).
    Once you've signed out of iCloud, restart your system.  When you get back in, head to the Mail, Contacts and Calendars section of your System Preferences and add your account back by choosing the brushed aluminum "iCloud" button.  When it asks for your account name, use your @iCloud.com email address.  I am all but certain my issue had started because one of my devices (iPhone or whatever) had been set up with an email alias specified instead of my @iCloud.com address.
    Apple, if you're reading through any of these issues (there are TONS of users having this same problem).  Take note, that your icloud service somewhat frequently is not responding and yet tells the user that the password is wrong and this prompts people to be changing their passwords unnecessarily.  This has happened to me on numerous occasions.  Also, I noticed that last week's outage corresponded to a VERY similar outage exactly one year ago to the day.  Sounds like planned maintenance to me and I think you could do a better job notifying folks so we're not wasting HUGE amounts of time troubleshooting a problem that we have no hope of fixing.
    Hope that helps some of you!
    Terry Mullane
    Washington, DC

  • SQL query with different plans

    Hi,
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    I cannot paste the query plan due to company policies. I can see issue with the query plan, where it is doing partition range scan (with hash join) on one environment due to which it has full table scan, on and nested loop on the second environment with Index range which is fast as compared to partition range scan.
    I have checked the stats,looks updated.
    Any thoughts,...

    How, exactly, did you check the statistics? Did you just check when they were generated? Or did you check whether they were actually (more or less) the same?
    Is it an issue with bind variable peeking?
    Are there optimizer-related parameters that are different either for the databases or for different systems?
    Have you looked at a 10053 trace to see how the slower system is evaluating the faster plan?
    Unfortunately, without more information, it's going to be nearly impossible for us to help you narrow down the problem. We can speculate about things that might cause one environment to generate a different plan but we're blind to the details that would help us figure out which factors are actually influencing your particular systems.
    Justin

Maybe you are looking for