Is there any way to tune this query? EXPLAIN PLAN included

DB version:10gR2
The below query was taking more than 3 seconds. The statistics are up to date for these tables. Is there any other way i could tune this query?
SELECT COUNT(1)
FROM
INVN_SCOPE_DTL, ship_dtl WHERE ship_dtl.WHSE = INVN_SCOPE_DTL.WHSE (+)
AND 'QC' = INVN_SCOPE_DTL.FROM_WORK_GRP (+)
AND  'MQN' = INVN_SCOPE_DTL.FROM_WORK_AREA (+)
AND  ship_dtl.START_CURR_WORK_GRP = INVN_SCOPE_DTL.TO_WORK_GRP (+)
AND  ship_dtl.START_CURR_WORK_AREA = INVN_SCOPE_DTL.TO_WORK_AREA (+)
AND  ship_dtl.WHSE = '930' AND  ship_dtl.OWNER_USER_ID = 'CTZDM'
OR ship_dtl.OWNER_USER_ID = '*'
AND ship_dtl.STAT_CODE >= '10'
AND ship_dtl.STAT_CODE <= '20'
ORDER BY ship_dtl.OWNER_USER_ID DESC,
ship_dtl.CURR_TASK_PRTY ASC, INVN_SCOPE_DTL.DISTANCE ASC, ship_dtl.RLS_DATE_TIME ASC, ship_dtl.TASK_ID ASC;
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id  | Operation                      |  Name               | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT               |                     |     1 |    86 |    86   (2)|
|   1 |  SORT AGGREGATE                |                     |     1 |    86 |            |
|   2 |   NESTED LOOPS OUTER           |                     |   898 | 77228 |    86   (2)|
|   3 |    INLIST ITERATOR             |                     |       |       |            |
|*  4 |     TABLE ACCESS BY INDEX ROWID| ship_dtl            |   898 | 31430 |    85   (2)|
|*  5 |      INDEX RANGE SCAN          | ship_dtl_IND_4      |  2876 |       |     1   (0)|
|   6 |    TABLE ACCESS BY INDEX ROWID | INVN_SCOPE_DTL     |     1 |    51 |     2  (50)|
PLAN_TABLE_OUTPUT
|*  7 |     INDEX UNIQUE SCAN          | PK_INVN_SCOPE_DTL  |     1 |       |            |
Predicate Information (identified by operation id):
   4 - filter("ship_dtl"."WHSE"='930' AND "ship_dtl"."STAT_CODE">=10 AND
              "ship_dtl"."STAT_CODE"<=20)
   5 - access("ship_dtl"."OWNER_USER_ID"='*' OR "ship_dtl"."OWNER_USER_ID"='CTZDM')
   7 - access("INVN_SCOPE_DTL"."WHSE"(+)='930' AND
              "INVN_SCOPE_DTL"."FROM_WORK_GRP"(+)='QC' AND "INVN_SCOPE_DTL"."FROM_WORK_AREA"(+)='MQN'
PLAN_TABLE_OUTPUT
              AND "ship_dtl"."START_CURR_WORK_GRP"="INVN_SCOPE_DTL"."TO_WORK_GRP"(+) AND
              "ship_dtl"."START_CURR_WORK_AREA"="INVN_SCOPE_DTL"."TO_WORK_AREA"(+))
       filter("ship_dtl"."WHSE"="INVN_SCOPE_DTL"."WHSE"(+))
25 rows selected.

William Robertson wrote:
I notice an OR predicate in the middle of some AND predicates without explicit bracketing. Are you sure it does what you think it does?I underline this point.
A conjuction (AND expression) has a higher priority and will be executed (logically) before the disjunction (OR expression)! So your select looks like this
SELECT COUNT(1)
FROM INVN_SCOPE_DTL, ship_dtl
WHERE
      ( ship_dtl.WHSE = INVN_SCOPE_DTL.WHSE (+)
      AND 'QC' = INVN_SCOPE_DTL.FROM_WORK_GRP (+)
      AND  'MQN' = INVN_SCOPE_DTL.FROM_WORK_AREA (+)
      AND  ship_dtl.START_CURR_WORK_GRP = INVN_SCOPE_DTL.TO_WORK_GRP (+)
      AND  ship_dtl.START_CURR_WORK_AREA = INVN_SCOPE_DTL.TO_WORK_AREA (+)
      AND  ship_dtl.WHSE = '930'
      AND  ship_dtl.OWNER_USER_ID = 'CTZDM'
OR   ( ship_dtl.OWNER_USER_ID = '*'
      AND ship_dtl.STAT_CODE >= '10'
      AND ship_dtl.STAT_CODE <= '20'
;This might be want you want, but I doubt it very much. Please add parenthesis', to get it working the way it should be.
Edited by: Sven W. on Oct 16, 2008 3:25 PM

Similar Messages

  • Is there any way to rewrite this query?

    Is there room for improvement/rewrite for this query so that it performs well?
    select distinct shp_locn
      from shp_mstr
    where zone = to_char(:b3)
       and locn_class = 'r'
       and aisle = 'GX-08'
       and dock =  'KN'
       and locn_id not in (select locn_id from tmp_shp_out_dtl)
    order by shp_locn

    user659394 wrote:
    Alex,
    Stop your st_u_pi_d f_u_c__king sarcasm. There were lots of instances like the below thread
    where you bring your boring sarcasm to meaningful technical discussions.
    If you dont want to answer, just leave it..... you C__u__n__t
    Error for a SELECT COUNT ... in stored proc
    Alex was giving you perfectly valid assistance.
    Your post has now been reported to the moderators as it is completely offensive, unprofessional and unnecessary.

  • Hi at the moment my ipod is on manual sync mode. Is there any way of changing this to auto-sync without losing the music on my ipod or library? Possibly more importantly is there a way I can transfer the ratings from my ipod onto my i-tunes?

    Hi at the moment my ipod is on manual sync mode. Is there any way of changing this to auto-sync without losing the music on my ipod or library? Possibly more importantly is there a way I can transfer the ratings from my ipod onto my i-tunes?
    This is so I can delete music from my ipod knowing its rated on my i-tunes so I can then see later if I want to re-add it based on its rating
    Thanks

    Is there any way of changing this to auto-sync without losing the music on my ipod or library?
    Unfortunately there is not.
    Possibly more importantly is there a way I can transfer the ratings from my ipod onto my i-tunes?
    Not without the help of third party software such as this one:
    http://www.copytrans.net/copytrans.php
    B-rock

  • Is there any way to get the query used in discoverer from backend??

    Hi All,
    I am new to dicoverer.
    Is there any way to get the query used in discoverer from backend??
    Thanks,
    Sachin

    Hi,
    you can view the SQL from within the discoverer menu:
    in desktop: View-> SQL Inspector
    in Plus: Tools-> Show SQL
    The SQL in the DB tables is encrypted so it's a problem getting it from there.
    You can export the workbook into SQL but it is not working for every worksheet (subquery, inline pivot tables...)
    you can create a batch file to export them all using the output of this script:
    select null,null,'echo off'
    from dual
    union all
    select distinct
    qs.qs_doc_name Workbook_name,
    qs.qs_doc_details Worksheet_Name,
    'start /wait <path>\dis51usr.exe /connect '||'&p_user_name'||'/'||'&p_password'||'@'||'&p_env'||' /apps_user /apps_responsibility "&responsibility" /opendb '||
    chr(34)||qs.qs_doc_name||chr(34)||' /sheet "'||qs.qs_doc_details||'"'||' /export SQL "C:\Export Discoverer SQL\'||qs.qs_doc_name||'-'||qs.qs_doc_details||'.sql" /batch'
    from eul_us.eul5_qpp_stats qs
    where qs.qs_doc_name is not null
    --order by 1,2
    union all
    select null,null,'echo off'
    from dual
    union all
    select null,null,'exit'
    from dual

  • When I attempt to open a PDF file I saved from a website, I get the message "There was an error opening this document. The file is damaged and could not be repaired." Is there any way to correct this problem?

    When I attempt to open a PDF file I saved from a website using Safari, I get the message "There was an error opening this document. The file is damaged and could not be repaired." When I save the same PDF file using FireFox it opens up immediately. Is there any way to correct this problem with Safari?

    Back up all data.
    Triple-click the line of text below to select it, the copy the selected text to the Clipboard (command-C):
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, remove any items that have the letters “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari, and test.
    The "Silverlight" web plugin distributed by Microsoft can also interfere with PDF display in Safari, so you may need to remove it as well, if it's present.
    If you still have the issue, repeat with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari again.

  • When I try to print a drawing imported from my ipad iphoto crops it. Is there any way to stop this?

    When I try to print a drawing imported from my ipad iphoto crops it. Is there any way to stop this?

    Usual cause: printing at the wrong aspect ratio for the image - trying to print 5 x 3 in the shape of a 6 x 4 for instance.
    Regards
    TD

  • I'm trying to add a playlist manually to my iPhone 4. It won't let me because it's trying to delete all of the music currently on my iPhone. Is there any way to prevent this from happening in order to start manually updating it?

    I'm trying to add a playlist manually to my iPhone 4. It won't let me because it's trying to delete all of the music currently on my iPhone. Is there any way to prevent this from happening in order to start manually updating it?

    Are you leaving the box unchecked to Manually manage music & videos? You don't need to to add anything to the iPhone.
    Simply drag the playlist to the iPhone to manually add it.

  • When I listen to music on my iPhone and pause it, if I come back to it later, the playlist has started over. I have a 4S running on iOS 7.0.4. Is there any way to keep this from happening so that my playlist will start off where I last was?

    When I listen to music on my iPhone and pause it, if I come back to it later, the playlist has started over. I have a 4S running on iOS 7.0.4. Is there any way to keep this from happening so that my playlist will start off where I last was?

    Dear Jody..jone5
    Good for you that can't update your iphone because I did it and my iphone dosen't work for example I can't download any app like Wecaht or Twitter..
    Goodluck
    Atousa

  • I bought my iphone 5s a week before and now its volume "up" button is not working when pressed.Does anybody know what to do to make it work?I have a one year warranty.Should i give it to apple retail shop or is there any way to solve this problem?

    I bought my iphone 5s a week before and now its volume "up" button is not working when pressed.Does anybody know what to do to make it work?I have a one year warranty.Should i give it to apple retail shop or is there any way to solve this problem?

    IF it is a manufacturing defect and you bought the device from Apple or an authorized Apple retailer, then take it into Apple.

  • HT1386 i am trying to restore a backup og my iphone 4 from itunes on my macbook, it asks me for a password which i do not recall setting up, is there any way of getting this password.

    i am trying to restore a backup og my iphone 4 from itunes on my macbook, it asks me for a password which i do not recall setting up, is there any way of getting this password.

    No there's not.  Otherwise that wouldn't be very secure, would it?

  • Don't have money for new tech or headphones. I want to watch a movie from my laptop via AirPlay (watch a movie straight from Apple TV), but hear the sound on my headphones attached to my MB Air.  Is there any way to do this??

    I don't have money for new tech or headphones. I want to watch a movie from my laptop via AirPlay (watch a movie straight from Apple TV), but hear the sound on my headphones attached to my MB Air.
    Is there any way to do this??
    http://superuser.com/questions/853821/watch-a-movie-straight-from-apple-tv-but-h ear-the-sound-on-my-headphones-on-my

    Thanks for your help.  Since I'm uninterested in loading all my photos (the only option) into photostream, I won't be able to use the settings in ATV.  I guess I'm just stuck with using iPhoto on my MB Air.  Thanks again.
    paul

  • Is there any way to create this image in photoshop?

    Is there any way to create this image in photoshop?  ,Any help would be appreciated?

    What JJMack said. An example I pulled in less than 5 minutes:
    All I did was inserted a text layer with that same inside color and a stroke layer style with that same outside color (about 3 or 4 pixels; outside position). Font used was Calibri Regular.

  • HT5129 I had photos from MobileMe organized into different events.  When iPhoto made a MobileMe event, it took all of those photos out of the other events and put them all together in the new "from MobileMe" event.  Is there any way to reverse this?

    I had photos from MobileMe organized into different events.  When iPhoto made a MobileMe event (when MobileMe ended), it took all of those photos out of the other events and put them all together in the new "from MobileMe" event.  Is there any way to reverse this?

    Only to load your backup from before downloading the MM photos
    LN

  • My pictures are not showing up on my iphone 4s and i do not have icloud set up is there any way ro fix this?

    my pictures are not showing up on my iphone 4s and i do not have icloud set up is there any way ro fix this?

    Pictures from where?

  • Say I turn off my Computer or restart it & then I load up Firefox the pages I was previously at loads up. Is there any way to turn this off ?

    == Issue
    ==
    I have another kind of problem with Firefox
    == Description
    ==
    Say I turn off my Computer or restart it & then I load up Firefox the pages I was previously at loads up. This is very very very annoying & I see no options in the settings to turn this off. Is there any way to turn this off ? Even if I just press the X button to close Firefox then later in the day I open Firefox the previous pages always open & it is annoying. I apologize for the language but that is just how ''irritated'' & annoyed I am about this
    <blockquote>language cleaned up by a moderator - eh</blockquote>
    == This happened
    ==
    Every time Firefox opened
    == It started randomly
    ==
    == Troubleshooting information
    ==
    There was nothing in the Troubleshooting about this
    == Firefox version
    ==
    3.6.3
    == Operating system
    ==
    Windows XP
    == User Agent
    ==
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
    == Plugins installed
    ==
    *-Default Plug-in
    *The QuickTime Plugin allows you to view a wide variety of multimedia content in Web pages. For more information, visit the QuickTime Web site.
    *Shockwave Flash 10.1 r53
    *Adobe Shockwave for Director Netscape plug-in, version 11.5
    *iTunes Detector Plug-in
    *3.0.50106.0
    *Next Generation Java Plug-in 1.6.0_20 for Mozilla browsers

    Hello David.
    Go into ''Tools > Options > General > Startup:When Firefox starts:'' and configure it as you want (probably to show your home page?). This is the very first option that appears in the options screen, but I understand that it may not be very easy to find. Firefox 4 will not include any redesign to the options screen (except possibly it appearing in a tab, rather than in a popup), but you may interested to know that there are plans to redesign the options screen for versions after Firefox 4, to make it easier to use. If you want to know more about the redesign, just ask.
    Anyway, if that doesn't help (it probably does, but just in case), it's possible that you are having a problem with some Firefox add-on that is hindering your Firefox's normal behavior. Have you tried disabling all add-ons (just to check), to see if Firefox goes back to normal?
    Whenever you have a problem with Firefox, whatever it is, you should make sure it's not caused by one (or more than one) of your installed add-ons, be it an extension, a theme or a plugin. To do that easily and cleanly, run Firefox in [http://support.mozilla.com/en-US/kb/Safe+Mode safe mode] (don't forget to select ''Disable all add-ons'' when you start safe mode). If the problem disappears, you know it's from an add-on. Disable them all in normal mode, and enable them one at a time until you find the source of the problem. See [http://support.mozilla.com/en-US/kb/Troubleshooting+extensions+and+themes this article] for information about troubleshooting extensions and theme and [https://support.mozilla.com/en-US/kb/Troubleshooting+plugins this one] for plugins.
    If you need support for one of your add-ons, you'll have to contact its author.

Maybe you are looking for