How to make the sql with unions to run faster

I have the following sql which takes long time to run in sqlplus. This is in oracle 10, can I use hints to speed up the process. Union all brings all rows, but I want to eliminate the duplicates.
select A.EMPLID,S.OPRID,A.LASTUPDDTTM,A.EMPL_RCD_NBR,A.LAST_NAME,A.FIRST_NAME,A.DEPTID,B.COMPANY,B.PAYGROUP,B.PAY_END_DT,B.OFF_CYCLE,
B.ERNCD_REG_HRS,B.REG_HRS,0,B.REG_HRLY_EARNS
from PS_EMPLOYEES A,PS_PAY_EARNINGS B,PS_SCRTY_TBL_DEPT S,PSTREENODE T
where S.ACCESS_CD = 'Y' and T.SETID = ' ' and T.TREE_NAME = 'DEPT_SECURITY'
and T.EFFDT = S.TREE_EFFDT and T.TREE_NODE = A.DEPTID and T.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END
and not exists (select 'X' from PS_SCRTY_TBL_DEPT S1
where S.OPRID = S1.OPRID
and S.TREE_NODE_NUM <> S1.TREE_NODE_NUM
and T.TREE_NODE_NUM between S1.TREE_NODE_NUM
and S1.TREE_NODE_NUM_END
and S1.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END)
and B.EMPLID = A.EMPLID and B.EMPL_RCD_NBR = A.EMPL_RCD_NBR
and B.SINGLE_CHECK_USE IN ('C', 'N') and (B.REG_HRS<>0 or B.REG_HRLY_EARNS<>0)
and B.PAY_LINE_STATUS in ('C','F')
union
select A.EMPLID,S.OPRID,A.LASTUPDDTTM,A.EMPL_RCD_NBR,A.LAST_NAME,A.FIRST_NAME,A.DEPTID,B.COMPANY,B.PAYGROUP,B.PAY_END_DT,B.OFF_CYCLE,
B.ERNCD_REG_HRS,B.REG_HRS,0,B.REG_EARNS
from PS_EMPLOYEES A,PS_PAY_EARNINGS B,PS_SCRTY_TBL_DEPT S,PSTREENODE T
where S.ACCESS_CD = 'Y' and T.SETID = ' ' and T.TREE_NAME = 'DEPT_SECURITY'
and T.EFFDT = S.TREE_EFFDT and T.TREE_NODE = A.DEPTID and T.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END
and not exists (select 'X' from PS_SCRTY_TBL_DEPT S1
where S.OPRID = S1.OPRID
and S.TREE_NODE_NUM <> S1.TREE_NODE_NUM
and T.TREE_NODE_NUM between S1.TREE_NODE_NUM
and S1.TREE_NODE_NUM_END
and S1.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END)
and B.EMPLID = A.EMPLID and B.EMPL_RCD_NBR = A.EMPL_RCD_NBR
and B.SINGLE_CHECK_USE IN ('C', 'N') and (B.REG_HRS<>0 or B.REG_HRLY_EARNS<>0)
and B.PAY_LINE_STATUS in ('C','F')
union
select A.EMPLID,S.OPRID,A.LASTUPDDTTM,A.EMPL_RCD_NBR,A.LAST_NAME,A.FIRST_NAME,A.DEPTID,B.COMPANY,B.PAYGROUP,B.PAY_END_DT,B.OFF_CYCLE,
B.ERNCD_OT_HRS,B.OT_HRS,0,B.OT_HRLY_EARNS
from PS_EMPLOYEES A,PS_PAY_EARNINGS B,PS_SCRTY_TBL_DEPT S,PSTREENODE T
where S.ACCESS_CD = 'Y' and T.SETID = ' ' and T.TREE_NAME = 'DEPT_SECURITY'
and T.EFFDT = S.TREE_EFFDT and T.TREE_NODE = A.DEPTID and T.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END
and not exists (select 'X' from PS_SCRTY_TBL_DEPT S1
where S.OPRID = S1.OPRID
and S.TREE_NODE_NUM <> S1.TREE_NODE_NUM
and T.TREE_NODE_NUM between S1.TREE_NODE_NUM
and S1.TREE_NODE_NUM_END
and S1.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END)
and B.EMPLID = A.EMPLID and B.EMPL_RCD_NBR = A.EMPL_RCD_NBR
and B.SINGLE_CHECK_USE IN ('C', 'N')
and (B.OT_HRS<>0 or B.OT_HRLY_EARNS<>0)
union
select
A.EMPLID,S.OPRID,A.LASTUPDDTTM,A.EMPL_RCD_NBR,A.LAST_NAME,A.FIRST_NAME,A.DEPTID,B.COMPANY,B.PAYGROUP,B.PAY_END_DT,B.OFF_CYCLE,
C.ERNCD,C.OTH_HRS,C.OTH_PAY,C.OTH_EARNS
from PS_EMPLOYEES A,PS_PAY_EARNINGS B,PS_PAY_OTH_EARNS C,PS_SCRTY_TBL_DEPT S,PSTREENODE T
where S.ACCESS_CD = 'Y' and T.SETID = ' ' and T.TREE_NAME = 'DEPT_SECURITY'
and T.EFFDT = S.TREE_EFFDT and T.TREE_NODE = A.DEPTID and T.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END
and not exists (select 'X' from PS_SCRTY_TBL_DEPT S1
where S.OPRID = S1.OPRID
and S.TREE_NODE_NUM <> S1.TREE_NODE_NUM
and T.TREE_NODE_NUM between S1.TREE_NODE_NUM
and S1.TREE_NODE_NUM_END
and S1.TREE_NODE_NUM between S.TREE_NODE_NUM
and S.TREE_NODE_NUM_END)
and B.EMPLID = A.EMPLID and B.EMPL_RCD_NBR = A.EMPL_RCD_NBR
and C.COMPANY = B.COMPANY and C.PAYGROUP = B.PAYGROUP
and C.PAY_END_DT = B.PAY_END_DT and C.OFF_CYCLE = B.OFF_CYCLE
and C.PAGE_NBR = B.PAGE_NBR and C.LINE_NBR = B.LINE_NBR
and C.ADDL_NBR = B.ADDL_NBR and B.SINGLE_CHECK_USE IN ('C', 'N')
and (C.OTH_HRS<>0 or C.OTH_PAY<>0 or C.OTH_EARNS<>0)
and B.PAY_LINE_STATUS in ('C','F')

UNION will eliminate the duplicates. If you are seeing rows that look like duplicates, there must be something different about them that you are missing.
If there is some set of rows that is common to all of the UNION queries and expensive to retrieve, you might try subquery factoring, e.g:
WITH common_set AS
    ( SELECT somecols
      FROM   sometab x, othertab y
      WHERE  y.key = x.key
      AND    etc )
SELECT a,b,c
FROM   common_set c, table1 t
WHERE  t.key = c.key
UNION
SELECT a,b,c
FROM   common_set c, table2 t
WHERE  t.key = c.key
UNION
SELECT a,b,c
FROM   common_set c, table2 t
WHERE  t.key = c.keyThe usual advice applies for tuning requests applies though:
<ul><li>{thread:id=863295}</li>
<li>{thread:id=501834}</li>
<li>Troubleshooting Bad Execution Plans</li>
<li>Writing Good SQL</li></ul>

Similar Messages

  • How to make the panel with scrollpane transparent?

    Thanks Camicker for your help, it solves the problem but i got a new problem i.e. i want to make that panel with scrollbar transparent for this i have tried setOpaqe(false) for both scrollpane and panel but it doesn't work. do u have any solution?

    I think camickr (not Camicker) already told you to set the opacity of the JScrollPane's viewport.
    Spend just a few minutes with the JScrollPane API and you'll find an exploded view showing the components that make up a scroll pane.
    db

  • How to make the start of Disco Plus / Viewer faster

    Hello,
    I open a workbook via link in Discoverer Viewer. It takes 30-60 seconds until the workbook opens.
    I have to say that the whole environment is running on a laptop with 1,5 GB Ram (for a showcase). Is there an option to make it faster? I'm a little confused because when I manually start Discoverer Plus and then open the workbook it does not take so much time.
    regards,
    Tobias

    Toki.
    One other 'trick' you can perform for making the actual query run faster once you've connected - for demo purposes only - is to not use 'real data' with many tables, views, etc. but to dump the data you want into one table. In otherwords, you create a table that has the actual data that you would get from a query, querying say 3 tables.
    Then when you're demo'ing, you get instant response as you're only using 1 table.
    This is done by a well known company when they're trying to show off their product against an Oracle database and querying with various query tools including Disco.
    Russ

  • How to make the collection with fetched rows process dependant

    Hello,
    I have the following problem.
    A page containing some select lists narrowing the tabular form selection. In this tabular form I have an edit button that goes to another "detail" page for editing the selected record. Now I want to put next and previous buttons on this detail page but the should only take the records into account select on the master by the select lists. For the moment I get all records from the table.
    How can I manage that.
    Second question. Is there a way to highlight the record you were editing when you navigate back to the "master" page?
    thanks for the help
    No one a solution ?
    Erwin
    Message was edited by:
    Erwin L

    This is your third posting on this topic.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    We don't have access to your database so the code can't be executed.

  • How to make the playlist with all purchased songs

    I accidentally deleted the puchased playlist. How do I get it back?
    Thanks,
    Austin

    Hey OscarDeLaGrouch,
    Thanks for the question. You stated that you wish to play all of your songs at random. Shuffling might be the tool you are looking for:
    iTunes 11 for Windows: Ways to play songs
    http://support.apple.com/kb/PH12331
    Shuffle or repeat songs
    Do any of the following:
    - Turn shuffle on or off: Click the Shuffle button
    Shuffle is on when the arrows are blue
    Thanks,
    Matt M.

  • How to make the new deploed appl to run?

    Hi all,
    I have developed an WD application, and deployed the appl and ran it. <b>When I make any changes to the application abd build,deployed successfully and when i run...the old one is coming ...the changes made was not coming.</b> What caonfigurations i have to make inorder to work with newer version of deployed appl.
    Thanks in advance

    Hi Ganesh,
       To Undeploy your Web Dynpro application From SDM.
    Visual Admin -> Cluster -> Server -> Services -> Deploy -> Server -> Web Dynpro -> Select your App -> Remove.
    Regards,
    Sridhar

  • How to make the list code visible?

    Dear All Experts,
         How to make the list with A1 and so on visible?
         Pls refer to below screenshot:
    Thanks!

    Dear All,
         I already find it.
    Thanks!

  • Make the installer for my executable run the DAqcarddriver and runtime engine installer automatically

    *Hi
    I would like to know how to make the installer for my executable run the DAqcarddriver and runtime engine installer automatically
    I would like to include run time engine and the drivers of  my daqcard(AI16XE50),( and maybe Ni daq or anything else needed?) in order to make my application portable for other computers on OS win98 and winXP .
    How can I do that
    thank you in advance
    Olivier

    Olivier,
    What version of LabVIEW are you using to build your application?  On a remote computer you should only need the drivers you are using and the Run-Time Engine.  You can attach installers to LabVIEW 8 installers, but for previous versions you will have to add it by opening the installer configuration page, configuring your installer and then configure the Advanced properties.  This will allow you to attach a EXE to the installer which you can run.  Also depending on the version of LabVIEW will affect the OS version that you will be able to install the RTE on.  LabVIEW 7.0 is the last version that can be installed on Windows 98. 
    Please let me know if you have any further questions and please include the version of LabVIEW you are using.  Thanks!
    Andy F.
    National Instruments

  • Has anyone figured out how to make the Yamaha 01V96i mixer work with Logic 9.1.8

    Has anyone figured out how to make the Yamaha 01V96i mixer work with Logic 9.1.8 as a control surface ?

    In YAMAHA01v96i:
    Go to DIO/SETUP select Generic DAW. Go to MIDI settings page and set the desired port (personally I use Number 1), Select the same audio frequency you use in your DAW (I use 44.1KhZ)...at this point You should save a scene in you 01V96i to avoid to repeat all the procedure again.
    Open studio manager, go to patch and set the input port from 17 to 32 respectively to USB1-USB16 (this will give you the return from you DAW to the 01v96i
    Save again the scene overwriting the old one.
    in LOGIC
    Click on preferences, select Audio then select 01v96i, then click on control surface and select Mackie design Baby HUI and in the midi session set the same port that you've been setting on the Yamaha 01V96i (Port 1 if you follow this example).
    That's more or less it.
    It worked for me...so far

  • How can I make the popup with empty fileds and create new record?

    I would like to use a popup to create new record.
    I created a af:popup by drag and drop a VO from data control to jsff. then, I created a button and place a af:showPopupBehavior. I was able to popup window by click the button.
    however, the window filled with the information from the 1st record. and when I select a record in table and click popup, the popup is filled with that record.
    How can I make the popup with empty fileds and create new record by saving the popup?
    Thanks

    You can have edit and new buttons, in the PopupFetchEvent identify button source (using popupFetchEvent.getLaunchSourceClientId()) if new button clicked clear the binding using below code.
    If you want to see empty fields, in the popup PopupFetchEvent clear the input component bindings.
    resetBindingValue("#{bindings.<componentid>.inputValue}", null);
        public static void resetBindingValue(String expression, Object newValue) {
            FacesContext ctx = FacesContext.getCurrentInstance();
            Application app = ctx.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = ctx.getELContext();
            ValueExpression valueExp = elFactory.createValueExpression(elContext,expression,Object.class);
            Class bindClass = valueExp.getType(elContext);
            valueExp.setValue(elContext,newValue);
        }

  • I am From Asia, Malaysia. I'm still was a student, I would like to purchase a Macbook at online With Student price. How I make the payment at online?? Am I able to used my dad's credit card?

    I am From Asia, Malaysia. I'm still was a student, I would like to purchase a Macbook at online with student price. How I make the payment at online?? Am I able to used my dad's credit card? or any proof?? Emergency ***

    http://store.apple.com/my/browse/home/education_routing
    If you have further questions about the policies and procedures for ordering, call the Malaysian Apple Store at 1800-80-6419. Everyone here is just a fellow user and cannot speak for Apple.
    Regards.

  • I reset my phone and it now receives calls that were meant for my husband. I know how to fix this with messaging and facetime, but can't seem to find how to make it stop with the calls. Please help.

    I reset my phone and it now receives calls that were meant for my husband. I know how to fix this with messaging and facetime, but can't seem to find how to make it stop with the calls. Please help.

    It may be due to Continuity
    The following quote is from  Connect your iPhone, iPad, and iPod touch using Continuity
    Turn off iPhone cellular calls
    To turn off iPhone Cellular Calls on a device, go to Settings > FaceTime and turn off iPhone Cellular Calls.

  • How to make the wifi connection with Ipad in china since it requires user's name and password.

    How to make the wifi connection with Ipad in china since it requires user's name and password just like the dialed-up?

    The same way you would connect to a secure wifi network in any other country. Supply the username and password when prompted.

  • How to make the mobile application work with firewall and anti-virus ON

    Hi,
    I keep on receiving internal processing error when i try to login sap mobile solution 1.3.0 on my ipad and i was provided a solution, that is to turn off my firewall and antivirus. I works by turn off both of it but i cant possible turn of the firewall and antivirus on the server.
    Can anyone guide me how to make the mobile application work with firewall and anti-virus ON
    Thank you

    Dear Rajesh,
    Create a policy in your fire wall to allow the port to send and receive data.
    I believe the port for the mobile should be port 8080 and 8443.
    And your license server port 30000 and 30001
    nd.Q

  • How to make the contact picture should appear on the upper right corner with thumb picture when some one calling instead showing the entire screen

    How to make the contact picture should appear on the upper right corner with thumb picture when some one calling instead showing the entire screen

    See deggie's response in this post... https://discussions.apple.com/message/8531821#8531821

Maybe you are looking for

  • Bootcache.playlist no such file or directory, slow booting 10.7.2

    Hi guys, I have this problem after updating to Lion 10.7.2 : There are many threads addressing a similar problem, but all the fixes mentioned there did not work (deleting bootcache and checking access rights) and also my problem is different, because

  • Error when creating transport request in 000 clinet

    Hi All, I am getting the below message when creating a transport request manually in 000 client Requests can only be created from ChaRM! Message no. 38001 How can I deactivate charm for short time and then activate it again? Please let me know your s

  • How does LabView 8 handle Ring constants?

    Hi all, This is probably more for NI guys, but I am wondering how LabView 8 handles text rings?  In the past, constants dropped into a VI that are of type "enum" will be updated when the typedef is updated, however, ring text constants will not.  Has

  • I REALLY need expert opinion with my mac/fcp shopping list!

    I work in TV and I'm buying an hdr sr12 so that i can work on my own projects, move my skills along etc... To edit the footage I'm thinking to buy a 15" 1st generation macbook pro and fcp studio 2??? is this what i need? could i get away with spendin

  • InDesign asking for location of embedded files

    I embedded two links in an InDesign document before I sent them to another designer, so I would only have to send one file and not 3. However, the designer called to say InDesign was asking him to locate the embedded files or something, and he couldn