Optimisation, using of one subquery several times,

Hi,
is it possible to optimise such query?
select * from
(select count(*) as count1 from table where a=1) e1,
(select count(*) as count2 from table where a=1 and b=1) e2,
(select count(*) as count3 from table where a=1 and b=1 and c=1) e3,
(select count(*) as count4 from table where a=1 and b=1 and c=1 and d=1) e4
The subquery (select count(*) as count1 from table where a=1) is used and executed 4 times?
Thanks in advance!!!!!!

I think you are both speaking "generally". And generally speaking you might be right sometimes.
But in this case, the case of the question of the original poster, there should be no doubt which is faster by looking at the execution plan. The plan as shown in the explain plan is the plan that gets executed here. There is no bind variable peeking taking place, there are no rows being added or deleted between the times of analyze and execution. So what you see is what you get here.
To help cdkumar convince:
SQL> select count(case when a=1 then a end) e1
  2       , count(case when a=1 and b=1 then a end) e2
  3       , count(case when a=1 and b=1 and c=1 then a end) e3
  4       , count(case when a=1 and b=1 and c=1 and d=1 then a end) e4
  5    from mytable
  6  /
        E1         E2         E3         E4
    500005     400004     300003     200002
1 rij is geselecteerd.
Verstreken: 00:00:01.06
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   SORT (AGGREGATE)
   2    1     TABLE ACCESS (FULL) OF 'MYTABLE'
SQL> with samp_a as
  2  (select * from mytable where a = 1),
  3  samp_b as
  4  (select * from samp_a where b = 1),
  5  samp_c as
  6  (select * from samp_b where c = 1),
  7  samp_d as
  8  (select * from samp_c where d = 1)
  9  select
10  (select count(1) from samp_a) a_cnt,
11  (select count(1) from samp_b) b_cnt,
12  (select count(1) from samp_c) c_cnt,
13  (select count(1) from samp_d) d_cnt
14  from dual
15  /
     A_CNT      B_CNT      C_CNT      D_CNT
    500005     400004     300003     200002
1 rij is geselecteerd.
Verstreken: 00:00:09.02
Uitvoeringspan
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   SORT (AGGREGATE)
   2    1     VIEW
   3    2       TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D69EB_694E3998'
   4    0   SORT (AGGREGATE)
   5    4     VIEW
   6    5       TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D69EC_694E3998'
   7    0   SORT (AGGREGATE)
   8    7     VIEW
   9    8       TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D69ED_694E3998'
  10    0   SORT (AGGREGATE)
  11   10     VIEW
  12   11       TABLE ACCESS (FULL) OF 'SYS_TEMP_0FD9D69ED_694E3998'
  13   16     RECURSIVE EXECUTION OF 'SYS_LE_16_0'
  14   16     RECURSIVE EXECUTION OF 'SYS_LE_16_1'
  15   16     RECURSIVE EXECUTION OF 'SYS_LE_16_2'
  16    0   TEMP TABLE TRANSFORMATION
  17   16     TABLE ACCESS (FULL) OF 'DUAL'Regards,
Rob.

Similar Messages

  • How can I trash a large number of Emails quickly from my iPod touch rather than using the one-at-a-time Edit method?

    How can I trash a large number of Emails quickly from my iPod touch rather than using the one-at-a-time Edit method?

    Once you tap on edit, you can select multiple emails, the tap archive.

  • Hi. My 2013 MacBook Air has suddenly reverted to a previous Excel spreadsheet (from May). I use the same spreadsheet several times a day and hit cmd 's' every 5-10 minutes. How can I find the version I was using yesterday?? Please help. Thanks

    Hi. My 2013 MacBook Air has suddenly reverted to a previous Excel spreadsheet (from May). I use the same spreadsheet several times a day and hit cmd 's' every 5-10 minutes. How can I find the version I was using yesterday?? Please help. Thanks

    Might be something for you here > Automatically save and recover files - mac excel

  • After duplicating a page, how do I prevent changes to both pages (without having to rename EVERY box for every duplicated page). I need a simple way to edit pages independently after I have duplicated one page several times. Thanks.

    Its a form with 3 work history sections on it. I need to duplicate the page to include my entire work history, however, when I duplicate the page and then edit the new page to put my next 3 jobs in my work history, it edits the previous page as well.
    THERE HAS TO BE  A SIMPLE WAY TO DO THIS!!!!!

    The way to do that is to make a Template object from the first page, which
    allows you to spawn copies of it and to have the fields in those copies
    automatically renamed.
    On Wed, Sep 3, 2014 at 2:40 AM, adobeuser1987 <[email protected]>

  • Can time capsule be used with one computer?

    Can time capsule be used with one computer?

    Time Capsule can serve one or more Macs:
    https://www.apple.com/airport-time-capsule/
    Ciao.

  • Firefox freezes several times a day on my Imac so that I have to close it by force quit.

    I have used several versions of firefox and each one freezes several times each day on my Imac. The only add on I use is the Ebay sidebar. When Firefox freezes the only answer is to "force Quit".
    I do not have this problem with any other search engine (safari, opera,chrome).

    http://kb.mozillazine.org/Firefox_hangs

  • There is no option to reject an incoming call in locked screen, there must be an icon on the screen for one who don't want to use lock button several times, i did'nt face this problem in last ios 6.1.3.

    There is no option to reject an incoming call in locked screen, there must be an icon on the screen for one who don't want to use lock button several times, i did'nt face this problem in last ios 6.1.3.

    A good read. Have you done anything at all to resolve your problem. Reset? Restore?
    By the way - "your products"... nobody here produced the iPhone, we are all just users. Apple is not here.

  • HT201269 I recently aquired a new iphone 4s because my old one broke. I backed it up on my itunes but now it wont give me the option of using the phone, it just says connect to itunes. I have synced it several times now and dont know what to do, please he

    I recently aquired a new iphone 4s because my old one broke. I backed it up on my itunes but now it wont give me the option of using the phone, it just says connect to itunes. I have synced it several times now and dont know what to do, please help me!!

    I recently created a new apple ID
    Bad idea.
    Content bought with an Apple ID is forever associated with that Apple ID. Apple will not transfer content from one Apple ID to another and Apple will not merge Apple IDs. Unless you are prepared to forfeit all the previously purchased content and buy it all again with the new Apple ID, you will need to maintain the old ID to update and redownload your content.

  • IMovie less than an hour. share to iDVD failed. read to share to media browser. worked for one movie. tried on different one and iDVD hung up and had to use force quit to get out of it. tried several times -- same result. suggestions?

    iMovie less than an hour in length. share to iDVD failed. read in support to share to media browser. then made DVD through iDVD. worked for one movie. tried on different one and iDVD hung up and had to use force quit to get out of it. tried several times -- same result. suggestions?

    Why start a new and very similar thread to your other one which you have not responded to (have you read the replies?)
    I suggest that no response is made to this duplicate thread. 

  • HT4436 When ever I try to log into I Cloud it rejects my Apple ID I have changed it several times but all to no avail. Strangely I can use my ID to buy Itunes music. Can any one help please?

    Can anyone help? I am unable to log into ICloud. When I type in my ID and password it comes back with 'incorrect password' I have changed the password several times but it doesn't help. strangely i can use my paswod to buy buy Itunes music but not for Icloud. Any suggestions would be gratefully recieved.

    Hello CarenzaRielle,
    I know not being able to access your Apple ID can be frustrating. I have located an article that will walk you through a series of troubleshooting steps to resolve this:
    Apple ID: If you forget your password
    http://support.apple.com/kb/ht5787
    Refer to the Apple ID Support page if you are unable to reset your password using the steps in this article. If you know your Apple ID password, you can also choose to change your Apple ID or change your password.
    Thank you for contributing to Apple Support Communities.
    Cheers,
    BobbyD

  • Using several time capsules, TM should use the one available but just stops.

    I appreciate Time Machine in most aspects, but one thing is annoying: I change between two TC hard-disks, one at work and one at home. For now, TM does not make any notice about not finding the previous TC hard-disk. I think it should alert me, and ask if I want to use another one. Or even simpler, use the first in a list of target disks that I have acknowledged. This should be a simple change, I think.
    Could I get any explanation or work-around for this, this should be appreciated. Thanks.

    Sorry, there is no work around for this.
    You might want to offer feedback directly to Apple for a "new feature"
    Apple - Time Capsule - Feedback

  • TS1368 I want to delete a lot of things childrens stories, albums which are not used which that are on my ipad. However when I go through Itunes it wont show me most of the stuff in my library. it takes ages to delete one at a time.

    I want to delete a lot of things childrens stories, albums which are not used which that are on my ipad. However when I go through Itunes it wont show me most of the stuff in my library. it takes ages to delete one at a time.
    Can you help please?

    Thanks King_Penguin for taking time to read and reply. 
    I just purchased this movie on Thursday, May 15, so just a few days ago.  I have never had any trouble whatsoever since I have been in Vietnam.  I have downloaded several movies and even music and they have all synced to my respected Apple products except for this purchase. 
    Sorry, I don't quite understand what you mean by studios and different versions.  Could you please explain? 
    I checked my purchased list in my purchase history under my account and there are no hidden items. 

  • Firefox will not open intermittently - it opens once, then will not open the next several times I try to use it - no discernable pattern or event(s) triggering failure to open

    Firefox opened today at 5 pm. I closed it when finished, then tried to reopen it about 6 pm - it will not open. I have tried several times in the last hour and it will not open.
    When I attempt to open Firefox, the 'busy' circle spins for several seconds, but then it stops, but Firefox NEVER opens and I get NO ERROR MESSAGE so I have no clue as to what the problem is.
    I have a Dell PC, running Microsoft Windows Vista, 32 bit (I think). AS far as I know, there were no updates of any kind that preceded the Firefox problems, which started about one week to 10 days ago.
    I have re-downloaded the program; I have uninstalled and then redownloaded the program to no avail. I can not figure out any kind of pattern, although it does seem to be more likely to open in the a.m. hours - but not always.
    I really prefer Firefox as my default browser, but I will not continue to use it on such an intermittant basis. Please help me trouble shoot this issue. By the way, I have had no problems, when Firefox won't open, opeing IE or Chrome, so I know it is not a generalized internet access issue.
    Please help.
    29Aug2011, Kay Arnold

    Which security software (firewall, anti-virus) do you have?
    Try to boot the computer in Windows Safe mode with network support (press F8 on the boot screen) as a test to see if that helps.
    A possible cause is security software (firewall,anti-virus) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox and the plugin-container from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.org/kb/Server+not+found
    *https://support.mozilla.org/kb/Firewalls

  • Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system. I have a wndiws 7 system and use a Intel core processor. I have restarted several times and still ge this

    Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system. I have a wndows 7 system and use a Intel core processor. I have restarted several times and still ge this error. I have also tried to reinstall firefox and get the same error
    == This happened ==
    Every time Firefox opened
    == today ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDS; InfoPath.2; .NET4.0C; AskTbUT2V5/5.8.0.12304)

    <u>'''Kill Application'''</u>
    In Task Manager, does firefox.exe show in the <u>'''Processes'''</u> tab?
    See: [http://kb.mozillazine.org/Kill_application Kill Application]
    '''<u>Causes and solutions for Firefox hanging at exit:</u>'''
    [[Firefox hangs]]
    [http://kb.mozillazine.org/Firefox_hangs#Hang_at_exit Firefox hangs at exit]
    [[Firefox is already running but is not responding]]
    <u>'''Safe Mode'''</u>
    You may need to use '''[[Safe Mode]]''' (click on "Safe Mode" and read) to localize the problem. Firefox Safe Mode is a diagnostic mode that disables Extensions and some other features of Firefox. If you are using a theme, switch to the DEFAULT theme: Tools > Add-ons > Themes <u>'''before'''</u> starting Safe Mode. When entering Safe Mode, do not check any items on the entry window, just click "Continue in Safe Mode". Test to see if the problem you are experiencing is corrected.
    See:
    '''[[Troubleshooting extensions and themes]]'''
    '''[[Troubleshooting plugins]]'''
    '''[[Basic Troubleshooting]]'''
    If the problem does not occur in Safe-mode then disable all of your Extensions and Plug-ins and then try to find which is causing it by enabling <u>'''one at a time'''</u> until the problem reappears. <u>'''You MUST close and restart Firefox after EACH change'''</u> via File > Restart Firefox (on Mac: Firefox > Quit). You can use "Disable all add-ons" on the Safe mode start window.

  • I tried to upgrade the ios on the phone and I was asked for my icloud user and password. I don't remember these exactly and I tried several times with different options but unsuccessfully. I also forget my email used to configurate the phone.

    How i said on the question. I tried to upgrade the ios on the phone and I was asked for my icloud user and password. I don’t remember these exactly and I tried several times with different options but unsuccessfully. I also forget my email used to configurate the phone. I have the phone box and the bill. I sent you an email with my problem and attachments with the box informations, the bill and the reset request. What to do? You said to me:
    Your request comes from an unrecognized email domain. Apple accepts email requests only from email domains for Apple-authorized carriers.
    Please re-submit your request using your official carrier domain.
    but this email is authorized, what to do??
                                                                                                              respectfully, Beba

    If you have forgotten then these links are the only way to resolve
    http://www.apple.com/support/appleid/
    As long as you have owned the iPhone from new and your Apple id is the one used to activate when new
    OR have you recently purchased the iPhone secondhand ?

Maybe you are looking for

  • New BT website = I can no longer find my mobile ac...

    Well done BT! For the 2nd month running I get the usual e-mail telling me my mobile bill is now available, only to find they've changed mybt.com and I can no longer see my mobile phone account, only my landline/broadband. I've wasted at least 10 minu

  • Problem with user access level

    David, I have so far succesfully implementend your tutorial on users registering and having to validate their emailaddress (both part I and II). Part I: http://cookbooks.adobe.com/post_Registration_system_that_requires_the_user_to_vali-16646.h tml Pa

  • Setting currency in iphone

    When I go to itunes or apple store from my iphone, the currency is not in us dollars. I have checked the language in phone and in my account with itunes. All say english. Any suggestions?

  • Outlook event export defaults to current date/time

    iCal suddenly started imported all outlook exported events as "Private Event" at the date and time of the import rather than the date and time specified in the exported event. Any help?

  • CS5: Bug when exporting directly from PPro with hardware MPE?

    For the record, I'm using: A GTX-480 (unsupported) The hardware MPE-enabling hack (unsupported) The latest version of the nVidia drivers (257.whatever) I discovered an issue, of sorts, when exporting directly from Premiere CS5, versus using the "Queu