Trying to tune a statement without success.

Dear all,
I got this statement in production:
SELECT a.ID, a.order_date, b.NAME, a.customer_total_price, a.department_name,
a.gilboa_no, a.currency_id
FROM orders a, order_statuses b
WHERE a.is_local = 0
AND a.order_date > TRUNC (SYSDATE, 'YEAR')
AND a.status_id = b.ID
-- AND a.status_id IN (7, 43, 62)
it runs very fast, see execution plan:
SELECT STATEMENT, GOAL = CHOOSE                         
NESTED LOOPS                         
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDERS               
INDEX RANGE SCAN     Object owner=D90STORYSERVER     Object name=IDX_DEPT_ID_ORDER_DATE               
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDER_STATUSES               
INDEX UNIQUE SCAN     Object owner=D90STORYSERVER     Object name=STATUS_PK               
When I unremark the last AND condition, it became extremly slow:
SELECT a.ID, a.order_date, b.NAME, a.customer_total_price, a.department_name,
a.gilboa_no, a.currency_id
FROM orders a, order_statuses b
WHERE a.is_local = 0
AND a.order_date > TRUNC (SYSDATE, 'YEAR')
AND a.status_id = b.ID
AND a.status_id IN (7, 43, 62)
execution plan:
SELECT STATEMENT, GOAL = CHOOSE                         
CONCATENATION                         
NESTED LOOPS                         
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDERS               
INDEX RANGE SCAN     Object owner=D90STORYSERVER     Object name=ORDER_1_STATUS_FK_I_1               
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDER_STATUSES               
INDEX UNIQUE SCAN     Object owner=D90STORYSERVER     Object name=STATUS_PK               
NESTED LOOPS                         
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDERS               
INDEX RANGE SCAN     Object owner=D90STORYSERVER     Object name=ORDER_1_STATUS_FK_I_1               
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDER_STATUSES               
INDEX UNIQUE SCAN     Object owner=D90STORYSERVER     Object name=STATUS_PK               
NESTED LOOPS                         
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDERS               
INDEX RANGE SCAN     Object owner=D90STORYSERVER     Object name=ORDER_1_STATUS_FK_I_1               
TABLE ACCESS BY INDEX ROWID     Object owner=D90STORYSERVER     Object name=ORDER_STATUSES               
INDEX UNIQUE SCAN     Object owner=D90STORYSERVER     Object name=STATUS_PK     
THE field a.status_id is an INDEX.
Appriciate a lot yuor help!!!!!

Here is how I see your 2 queries:
Query 1:
SELECT a.ID, a.order_date, b.NAME,
FROM orders a, order_statuses b
WHERE a.is_local = 0
AND a.order_date > TRUNC (SYSDATE, 'YEAR')
AND a.status_id = b.ID
SELECT STATEMENT, GOAL = CHOOSE                         
NESTED LOOPS                         
TABLE ACCESS BY INDEX ROWID     Object Object name=ORDERS
INDEX RANGE SCAN     Object name=IDX_DEPT_ID_ORDER_DATE
TABLE ACCESS BY INDEX ROWID     Object Object name=ORDER_STATUSES
INDEX UNIQUE SCAN     Object Object name=STATUS_PKPresuming that the first index access listed is done first, then it is using an index on the order date on ORDERS, and then joining out to ORDER_STATUSES using its primary key index for each matching row.
Query 2:
>
SELECT a.ID, a.order_date, b.NAME,
FROM orders a, order_statuses b
WHERE a.is_local = 0
AND a.order_date > TRUNC (SYSDATE, 'YEAR')
AND a.status_id = b.ID
AND a.status_id IN (7, 43, 62)
SELECT STATEMENT, GOAL = CHOOSE
CONCATENATION
NESTED LOOPS
TABLE ACCESS BY INDEX ROWID Object name=ORDERS
INDEX RANGE SCAN Object name=ORDER_1_STATUS_FK_I_1
TABLE ACCESS BY INDEX ROWID Object name=ORDER_STATUSES
INDEX UNIQUE SCAN Object name=STATUS_PK
[Above NESTED LOOP repeated another 2 times]Again, presuming the first index access is done first, then it is applying the Status ID constraint using the ORDER_1_STATUS_FK_I_1 index, and then joining out to ORDER_STATUSES using its primary key index.
My guess is that there are many rows matching these 3 status id values i.e. not just 3 rows, but many hundreds or thousands of rows. And I am also guessing that fewer rows match the date constraint than match the status id values - probably tens of rows with the right dates versus thousands of rows with the right status ids. You can verify this by counting how many rows match each condition:
SELECT count (*) FROM orders a WHERE a.order_date > TRUNC (SYSDATE, 'YEAR')
SELECT count (*) FROM orders a WHERE a.status_id IN (7, 43, 62)
I am guessing that the second SELECT will retrieve many more rows than the first.
In the first query the date constraint was applied using an index BEFORE the data row in the table was accessed. In the second query the date constraint is applied AFTER the data row in the table has been accessed i.e. Oracle has to read the data row in the table to get the date value to check if it matches the constraint in the WHERE clause.
So the first query uses an index on date, which is quite compact, quickly identifies any matching rows, and then ONLY retrieves the matching rows from the table.
The second query uses an index on status id, has to go to the table to retrieve many hundreds or thousands of matching rows, to then reject them because their date value does not match the constraint. This second query is doing a lot more disk I/O than the first one, if my guess about the data distributions and matching rows is correct.
Why is Oracle doing this? Probably because it considers an '=' constraint to be more restrictive (will match fewer rows) than a '>' constraint (an open ended number of rows may match). Without full statistics or a histogram of data distribution, Oracle believes that using the index on status_id is BETTER than using the index on order_date. It may be wrong, but Oracle doesn't know this before it runs the query. It can only use the information available to it at the time of parsing the query. And this makes it think that the status_id index should be better than the order_date index.
You don't mention which version of Oracle you are using. This will affect how many statistics it can collect, and how well the optimiser uses them when parsing SQL. 10g collects more statistics and tries to use them better.
The solution? Create a composite index on (status_id, order_date, is_local). Query 1 will still execute using the original order_date index. Query 2 should now prefer this new index as it has BOTH status_id and order_date in it. Oracle can now test the rows using the data in the index WITHOUT retrieving the data rows from the table. This will drastically reduce the amount of disk I/O being done and improve performance. Only the matching data rows will be retrieved from the table, having already matched all 3 major constraints. Furthermore, because the index is ordered, all the relevant matching rows will be in the same index blocks when retrieved - which is one of the main benefits of an index: row density within the index and packing.
John

Similar Messages

  • Hello I'm trying to create Apple ID without success even after checking the bank information

    Hello I'm trying to create Apple ID without success even after checking the bankinformation

    If you choose US as your country while your bank details and credit card or PayPal account are from another country, then you will get an error not related to your details, such as 'the CVV number is incorrect', although it is correct.

  • Hello I'm trying to create Apple ID without success for a long time. And after checking with the bank details are correct with no success

    Hello I'm trying to create Apple ID without success for a long time.
    And after checking with the bank details are correct with no success

    If you choose US as your country while your bank details and credit card or PayPal account are from another country, then you will get an error not related to your details, such as 'the CVV number is incorrect', although it is correct.

  • How do I set up hotmail account on MacBook Air - tried for 2 days now without success?

    I have been trying to add a hotmail account on my new MacBook Air without success - searched on the net for 2 evenings now and still no success!  Can anyone suggest what I might be doing wrong although I think it could be that I am not sure that the Exchange Server address I have used is correct.  If anyone can help how to check I have the correct exchange server address, that would also be appreciated
    Thanks!

    Hello Mariei,
    Thanks for using Apple Support Communities.
    To look up your mail server settings for configuring Mail on your Mac please enter your email in the article linked to below.
    Mail Settings Lookup
    https://ssl.apple.com/support/mail-settings-lookup/
    Take care,
    Alex H.

  • Trying to stop MYSQL service without success in snow leopard server

    Hello
    I trying to enabled MySQL service on snow leopard server.
    My hard drive name is "Macintosh HD2".
    I receive this message :
    Can't change dir to '/Volumes/Macintosh HD2/ServiceData/MySQL/' (Errcode: 2)
    I try to stop without success MySQL service for rename my HD without blank
    How do that please ?

    That's set up via the [MySQL command line|http://labs.hoffmanlabs.com/node/376]. Or you can install the (free) Sequel Pro GUI package, given you're probably more comfortable in the GUI. The steps required for Mac OS X Server are the same as most any other platform, so [launch the MySQL client per the Wordpress Codex|http://codex.wordpress.org/Installing_WordPress], and follow the instructions.

  • I tried to install 10.5 without success

    I tried to install itunes 10.5 on windows 7, 64 bit without success, after reinstalling 10.4.1 itunes ignores my iphone. What can I do?

    What kind of 10.5 disk did you use? If it was a grey system disk from a newer Intel-based Mac, that disk has no 10.5 code that a G4 processor can read and could leave you with what you describe.
    I tried booting ........... from the usb 2.0 disk that's attached via a PCI card.
    In spite of what Apple says (here), it's hard to find a G-series Mac that likes to boot from a USB device. Do you have one with FireWire connectivity? And some system software may have to load before the USB bus wakes up. You can try it on oneof the logic board 1.1 ports--has a better chance of getting a boot from there than a PCI card. But don't be surprised if it still doesn't boot.
    The 10.5 installer requires a minimum 867 mHz processor and may look at something stored in ROM on the computer rather than actually polling the new processor before deciding if it can install. Although you have an upgraded processor, the installer may be reading the original specs off the Machine type code or other parameter that was not affected by the upgrade.

  • IPod Nano 4G frozen at language screen. Tried holding down menu-click without success. Have gone through restore process, but it continues to stick at the language screen. Intel iMac 3ghz, OS X 10.6.7, iTunes 10.3.1 (55).

    I have a frozen iPod Nano 4G. After syncing it gets stuck at the language screen and cannot proceed any further.
    I have tried holding down the Menu and click buttons for >6 seconds, without luck. Have reset to factory settings and re-syncd, but it keeps getting stuck at the language screen.
    I suspect it is the latest version of iTunes causing the problem, as I just installed it a couple of days ago and this is the first sync since the update.
    24" Intel iMac 3ghz C2D, OS X 10.6.7, iTunes 10.3.1 (55).

    +Do you have access to, another Firewire enabled Mac, that you could use, to attempt a retrieval of data, using Firewire Target Disk Mode?+
    A question on this Firewire Target Disk Mode - If I could get access to another Firewire enabled Mac and connected the two together, host #2 to Target #1, with a Firewire cable (6-pin to 6-pin), and power the two up, even though #1 would not be booted up to the desktop but just have the hard drive powered up, would the hard drive of #1 be accessible to #2? If so, would I be able to perform any repairs or do anything to the drive to enable it to bootup the #1 computer? This would be similar to when I remove and hook up a 2.5" IDE-ATA PC laptop hard drive to another PC computer, usually a desktop, via a drive adapter and USB 2.0 cable, as an external drive. When I do this in a PC, it's usually one that is unable to boot up to Windows due to malware or other problems. I am able to see the files and folders on the #1 computer's hdd and then clean out any malware (virus/spyware), or add/replace any corrupt/damaged Windows files that might be keeping the #1 computer from booting up. After that, I can usually return the hdd to the #1 computer and boot up normally to finish any clean up or change any settings.
    I had considered taking the hdd out of this damaged iMac computer and attempting to hook it up with a PC, but after seeing how difficult it is to get to this hdd and not sure of what I'd do when and if I did get the two connected together, I put the idea way back as a last resort. I wasn't sure I'd even be able to see any folders or files on the Mac hdd due to the differences between OS X and WinXP. And, after reading that Macs aren't susceptible to malware, I didn't know what I would be accomplishing.

  • I upgraded to Mac OS X 10.6.8 and Epson Printer Software update 2.7 on the 29th of June and now I cannot print anything.  I have contacted Epson and Apple and both have tried to fix the problem without success. I am using a MacBook

    Does anybody else have this problem?  Epson and Apple don't have any solution.  The message I get from the printer is as follows:
    Error/library/printers/EPSON/Inkjet Printer2/Filter/rasteroescpII.app/Conents/MacOS/rasteroescpIIfailed

    Thanks for the replies guys.  Epson put me through a complex set of instructions to install an earlier driver.  The problem was not solved.  Apple also tried to solve the provlem by getting rid of the printer, unplugging it etc and then re starting and checking computer/printer communication by printing a test page from the system preferences/Pring & Fax options.  This worked proving the the computer and printer are talking to each other. 
    The printer works properly as a stand alone unit.  That is, I can copy and print and scan and print with no problems.
    The Apple support guy didn't suggest any Apple alternative drivers so I assume there aren't any.
    Neither the Epson nor Apple assistants seemed interested in the printer generated error message.  I would have thought it would at least provide a clue to the problem to someone with technical expertise.
    It seems that there are a lot of problems with the 10.6.8 update so maybe Apple will get to work and bring it up to scratch.  I hope it gets things right soon.

  • Trying to edit PDF file without success

    I am trying to edit the wording of a a few lines in a long pdf. I have seen the tutorials but cant find anywhere it shows how I can delete and correct typos. How is this done in preview if it can be done at all?

    William is correct regarding PDFPen.  Here's where to find it:
    http://www.smilesoftware.com/PDFpen/index.html
    They do indeed offer a free trial.  It's fully functional.  The only thing it does that might inconvenience you is put their logo on any pages you might print.
    I've used their product for several years and am a satisfied customer.  I do not have any financial or other interest in the company or product.

  • I can't get ahome page that has 6 or 8 tablets of most common used websites. Tried Option "use current pages" without success. Can you help?s

    Since having Firefox I have used as a Home page a page with "tablets" showing the most recent pae of my most popular websites. By clicking on this I returned immediately to that site. Suddenly it's disappeared and I can't get it back. I tried "Options Use current pages" but that doesn't work. Help!

    You can set the home page to about:newtab to have the page with the 5x3 tiles showing.
    You can check the home page setting:
    *Tools > Options > General > Startup: Home page
    Firefox supports multiple home pages separated by '|' (pipe) symbols.
    *https://support.mozilla.org/kb/How+to+set+the+home+page
    You can check the value of the <b>browser.newtab.url</b> pref that sets the new tab page page and make sure it is set to about:newtab.
    See this article about the New Tab page (about:newtab):
    *https://support.mozilla.org/kb/new-tab-page-show-hide-and-customize-top-sites

  • Despite having iMatch, my iPhone has lost all of my music. Tried synching 3 times, but without success.

    For some reason, iTunes Match is not working for my iPhone. It was OK and then suddenly everything disappeared.  I've checked my phone settings, and iTunes Match is switched on.  I've tried synching the phone with my computer 3 times (most recently today), but it still shows that I have no content. How can I fix this?

    Re: Downloaded Songs On IPhone 5 Go Poof After installation of Match
    FYI, with iTunes Match enabled on an iOS device traditional syncing of music via USB/Thunderbolt is disabled. All music management takes place directly on the device.

  • I' m trying to add a webcam without success .

    It says its UVC compatible , and my software version is  10.5.8 . What am I doing wrong ?
    I want to add this to monitor for animals in the atic  but can't get anything to happen .
    Thanks for any advice

    The details are as below
    its a MacBook using Mac OS X version 10.5 8 .
    Iwant to use an additionall web cam , in this case a PlusCom usb that supports mac with UVC .
    As far as I can tell, this version of osx should have UVC .
    When connected , nothng happens although the lights on the camera come on .
    The image Image capture software suplied withthe macbook says that there is no device  attached .
    What have i missed ?

  • I am trying to install update 11.0.06 for my Adobe Acrobat XI Pro, but without success multiple times.Get error 1603 each time,

    I am trying to install update 11.0.06 for my Adobe Acrobat XI Pro, but without success multiple times.Get error 1603 each time. I have tried disabling my antivirus software without success. I have looked for solutions to error 1603, and have tried what it suggests (empty temp files in Windows, etc.), also without success.There is nothing that mentions Window 8 or 8.1 operating system, though. Is this the issue? Please help.

    Hi Dawn,
    We might want to have a look at the install logs to determine the cause.
    Please try the following basic steps :
    > Enable the hidden Admin Account on Windows 7 ( Ref :  http://www.howtogeek.com/howto/windows-vista/enable-the-hidden-administrator-account-on-wi ndows-vista/ )
    > Disable all Non-Microsoft Startup Services. (Ref : http://helpx.adobe.com/x-productkb/global/disable-startup-items-services-windows.html )
    > Disable all the Antivirus softwares like CA, Norton,Mc Afee etc. temporarily from the computer.
    Reboot and try installing in the new enabled Admin user account and check.
    Regards,
    Rave

  • TS3899 Email locked. Tried disconnecting and reconnecting without success

    Email is locked.  Tried disconnecting and reconnecting but without success.  Safari is working ok and no problems with provider.  Any solutions please

    Hello Sher.
    If you're talking about the menu bar, press ALT or F10 in your keyboard to make the Menu Bar temporarily visible. If you want it to be permanently visible, go into ''View > Toolbars > Menu Bar'', or right-click the Navigation Toolbar (the Reload button, for example) and select ''Menu Bar''.
    If this doesn't help, right-click the navigation toolbar, select ''Customize...'' and click ''Restore Default Set''. If it doesn't appear right away, try pressing ALT or F10. You can go into ''View > Toolbars > Menu Bar'' to make it permanently visible, or right-click the Navigation Toolbar and select ''Menu Bar''.
    If none of this helps, you may be having a problem with some Firefox add-on that is hindering your Firefox's normal behavior. Try disabling all add-ons (just to check), to see if Firefox goes back to normal.

  • On my macbook pro when opening a page i can not save it as a pdf only give me the option of saving it as a web page can any body help me on this I have tryed so many times without success

    on my macbook pro when opening a page on safaryi can not save it as a pdf only give me the option of saving it as a web page can any body help me on this I have tryed so many times without success?

    Just select Print in Safari and then, in the bottom left-hand corner, select PDF and you can save it to whichever flavor pdf file you like.
    Clinton

Maybe you are looking for