Which is faster: 2 selects or 1 union

Hello,
I have 2 tables... each with 500,000 records each. Each table
has about 15 columns. Each has a non unique index, because
there can be multiple records with the same index.
I AM USING PL/SQL.
The union goes something like this:
SELECT tblA.*, tblB.*
FROM tblA, tblB,
WHERE A.ID (+)= B.ID
UNION
SELECT tblA.*, tblB.*
FROM tblA, tblB,
WHERE B.ID (+)= A.ID
I want all records and fields from table A that are not in table
B and vice versa.
NOW THE QUESTION...
Is it faster to do this union or just perform 2 select
statements and use logic to get the results I am looking for.
thanks for your help or other ideas!
larry
null

Hi Larry
<<I want all records and fields from table A that are not
in table B and vice versa.>>
Try this,
Select *
from tbl a
where not exists (select 'x'
from tbl b
where b.id = a.id)
union
select *
from tbl b
where not exists (select 'x'
from tbl a
where a.id = b.id)
This would be faster.
-Raj
larry (guest) wrote:
: Hello,
: I have 2 tables... each with 500,000 records each. Each table
: has about 15 columns. Each has a non unique index, because
: there can be multiple records with the same index.
: I AM USING PL/SQL.
: The union goes something like this:
: SELECT tblA.*, tblB.*
: FROM tblA, tblB,
: WHERE A.ID (+)= B.ID
: UNION
: SELECT tblA.*, tblB.*
: FROM tblA, tblB,
: WHERE B.ID (+)= A.ID
: I want all records and fields from table A that are not in
table
: B and vice versa.
: NOW THE QUESTION...
: Is it faster to do this union or just perform 2 select
: statements and use logic to get the results I am looking for.
: thanks for your help or other ideas!
: larry
null

Similar Messages

  • Which is fast ? Select * from tableName or Select Column1,Column2 .... From tableName ? and Why ?

    Which is fast ? Select * from tableName or Select Column1,Column2 .... From tableName ? and Why ?
    select * from Sales.[SalesOrderHeader]
    select SalesOrderNumber,RevisionNumber,rowguid from Sales.[SalesOrderHeader]
    As you can see both the query execution plan and subtree cost is same. So how selecting the particular columns optimize the query ?

    Which is fast ? Select * from tableName or Select Column1,Column2 .... From tableName ? and Why ?
    select * from Sales.[SalesOrderHeader]
    select SalesOrderNumber,RevisionNumber,rowguid from Sales.[SalesOrderHeader]
    As you can see both the query execution plan and subtree cost is same. So how selecting the particular columns optimize the query ?
    Yes, selecting specific columns is always better than select *.
    If you always need few columns in result, then just use SELECT col1, col2 FROM YourTable. If you SELECT * FROM YourTable; that is extra useless overhead.
    If in future if someone adds Image/BLOB/Text type columns in your table, using SELECT * will worsen the performace for sure.
    Let's say if you have SP and you use INSERT INTO DestTable SELECT * FROM TABLE which runs fine BUT again if someone adds few more columns then your SP will fail saying provided columns don't match.
    -Vaibhav Chaudhari

  • Which is fast / Smooth performing?

    I have 10 circles on the stage, animated on the time line, simple animation like scale, rotation and size changes.
    Which will give me best performance in terms of browser load and smoothness of animation?
    Ellipse or Svg file
    What if it is 100 objects, or even 1000 objects?

    Which is fast ? Select * from tableName or Select Column1,Column2 .... From tableName ? and Why ?
    select * from Sales.[SalesOrderHeader]
    select SalesOrderNumber,RevisionNumber,rowguid from Sales.[SalesOrderHeader]
    As you can see both the query execution plan and subtree cost is same. So how selecting the particular columns optimize the query ?
    Yes, selecting specific columns is always better than select *.
    If you always need few columns in result, then just use SELECT col1, col2 FROM YourTable. If you SELECT * FROM YourTable; that is extra useless overhead.
    If in future if someone adds Image/BLOB/Text type columns in your table, using SELECT * will worsen the performace for sure.
    Let's say if you have SP and you use INSERT INTO DestTable SELECT * FROM TABLE which runs fine BUT again if someone adds few more columns then your SP will fail saying provided columns don't match.
    -Vaibhav Chaudhari

  • Which is fast: between or ( =  =)

    Hi,
    can anyone explain me which is fast?
    between
    or
    <= >= operator.
    Thanks in advance.

    Hi, you can easy test that and find out that they're in fact the same:
    MHO%xe> create table t as select level col from dual connect by level <= 1000000;
    Tabel is aangemaakt.
    MHO%xe> create index t_i on t(col);
    Index is aangemaakt.
    MHO%xe> set autotrace traceonly explain
    MHO%xe> select * from t where col between 100000 and 300000;
    Verstreken: 00:00:01.78
    Uitvoeringspan
    Plan hash value: 1601196873
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |   211K|  2679K|   460   (9)| 00:00:06 |
    |*  1 |  TABLE ACCESS FULL| T    |   211K|  2679K|   460   (9)| 00:00:06 |
    Predicate Information (identified by operation id):
       1 - filter("COL">=100000 AND "COL"<=300000)  -- See that BETWEEN gets rewritten to >= and <=
    Note
       - dynamic sampling used for this statement
    MHO%xe> select * from t where col >= 200000 and col <= 400000;
    Verstreken: 00:00:00.14
    Uitvoeringspan
    Plan hash value: 1601196873
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |   227K|  2885K|   460   (9)| 00:00:06 |
    |*  1 |  TABLE ACCESS FULL| T    |   227K|  2885K|   460   (9)| 00:00:06 |
    Predicate Information (identified by operation id):
       1 - filter("COL">=200000 AND "COL"<=400000)
    Note
       - dynamic sampling used for this statement
    MHO%xe> select * from t where col >= 500000 and col <= 600000;
    Verstreken: 00:00:00.34
    Uitvoeringspan
    Plan hash value: 4021086813
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      | 48712 |   618K|   109   (2)| 00:00:02 |
    |*  1 |  INDEX RANGE SCAN| T_I  | 48712 |   618K|   109   (2)| 00:00:02 |
    Predicate Information (identified by operation id):
       1 - access("COL">=500000 AND "COL"<=600000)
    Note
       - dynamic sampling used for this statement
    MHO%xe> select * from t where col between 500000 and 600000;
    Verstreken: 00:00:00.11
    Uitvoeringspan
    Plan hash value: 4021086813
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      | 48712 |   618K|   109   (2)| 00:00:02 |
    |*  1 |  INDEX RANGE SCAN| T_I  | 48712 |   618K|   109   (2)| 00:00:02 |
    Predicate Information (identified by operation id):
       1 - access("COL">=500000 AND "COL"<=600000)
    Note
       - dynamic sampling used for this statement

  • Which is faster -  Member formula or Calculation script?

    Hi,
    I have a very basic question, though I am not sure if there is a definite right or wrong answer.
    To keep the calculation scripts to a minimum, I have put all the calculations in member formula.
    Which is faster - Member formula or calculation scripts? Because, if i am not mistaken, FIX cannot be used in member formulas, so I need to resort to the use of IF, which is not index driven!
    Though in the calculation script,while aggregating members which have member formula, I have tried to FIX as many members as I can.
    What is the best way to optimize member formulas?
    I am using Hyperion Planning and Essbase 11.1.2.1.
    Thanks.

    Re the mostly "free" comment -- if the block is in memory (qualification #1), and the formula is within the block (qualification #2), the the expensive bit was reading the block off of the disk and expanding it into memory. Once that is done, I typically think of the dynamic calcs as free as the amount of data being moved about is very, very, very small. That goes out the window if the formula pulls lots of blocks to value and they get cycled in and out of the cache. Then they are not free and are potentially slower. And yes, I have personally shot myself in the foot with this -- I wrote a calc that did @PRIORS against a bunch of years. It was a dream when I pulled 10 cells. And then I found out that the client had reports that pulled 5,000. Performance when right down the drain at that point. That one was 100% my fault for not forcing the client to show me what they were reporting.
    I think your reference to stored formulas being 10-15% faster than calc script formulas deals with if the Formulas are executed from within the default calc. When the default Calc is used, it precompiles the formulas and handles many two pass calculations in a single pass. Perhaps that is what you are thinking of.^^^I guess that must be it. I think I remember you talking about this technique at one of your Kscope sessions and realizing that I had never tried that approach. Isn't there something funky about not being able to turn off the default calc if a user has calc access? I sort of thing so. I typically assing a ; to the default calc so it can't do anything.
    Regards,
    Cameron Lackpour

  • Which is faster - Member formula or Calculation scripts?

    Hi,
    I have a very basic question, though I am not sure if there is a definite right or wrong answer.
    To keep the calculation scripts to a minimum, I have put all the calculations in member formula.
    Which is faster - Member formula or calculation scripts? Because, if i am not mistaken, FIX cannot be used in member formulas, so I need to resort to the use of IF, which is not index driven!
    Though in the calculation script,while aggregating members which have member formula, I have tried to FIX as many members as I can.
    What is the best way to optimize member formulas?
    I am using Hyperion Planning and Essbase 11.1.2.1.
    Thanks.

    The idea that you can't reference a member formula in a FIX is false. Here's an example:
    - Assume you have an account that has a data storage of Stored or Never Share.
    - This account is called Account_A and it has a member formula of Account_B * Account_C;.
    - You would calculate this account within a FIX (inside of a business rule) something like this:
    FIX(whatever . . . )
    "Account_A";
    ENDFIX
    If you simply place the member named followed by a semi-colon within a business rule, the business rule will execute the code in the in that member's member formula.
    Why would you want to do this instead of just putting ALL of the logic inside the business rule? Perhaps that logic gets referenced in a LOT of different business rules, and you want to centralize the code in the outline? This way, if the logic changes, you only need to update it in one location. The downside to this is that it can make debugging a bit harder. When something doesn't work, you can find yourself searching for the code a bit.
    Most of my applications end up with a mix of member formulas and business rules. I find that performance isn't the main driving force behind where I put my code. (The performance difference is usually not that significant when you're talking about stored members.) What typically drives my decision is the organization of code and future maintenance. It's more art than science.
    Hope this helps,
    - Jake

  • How to get the specific name of the workset which is currently selected by the user in sap portal 7.0

    Dear Expert,
    I have one requirement like to read the selected workset name in portal by the current user.I have read two documents regarding how to retrieve the PCD contents (iViews, Pages, Worksets and Roles) and its properties like Created by, Changed by, Last changed by and others using PCD API.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/6112ecb7-0a01-0010-ef90-941c70c9e401?overridelayout=true
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/508baf88-9335-2d10-efa6-c6ad61e5fc4b?quicklink=index&overridelayout=true
    But I am not able to understand how to get the specific name of the workset which is currently selected by the user.Can you please help me.
    I am using portal 7.0.
    Thanks & Regards,
    Patralekha

    Hi Expert,
    I found that we can use Interface INavigationHelperService to read Portal Role selected by user at runtime from http://scn.sap.com/thread/52194
    But this class is available in SAP NetWeaver 7.30 Enterprise Portal .
    But in SAP NetWeaver 7.0 Enterprise Portal that interface is not available.
    INavigationService is available there.
    But didn't get any proper discussion on this interface for the same requirement.
    Can you please help me.
    Thanks & Regards,
    Patralekha

  • Payment run error "No check exists which meets the selection criteria"

    I have done a payment run successfully, maintained a variant for the check print program but when I want to display the cheques i get this error: " No check exists which meets the selection criteria"  
    I have mantained the check lot for the house bank and the ID as well.
    What could be the problem? Please help.
    Regards
    Debra

    Hi
    I have checked FBZP t. code and the check lots , all seem to be in order. I still have not found out where the problem is.
    Thanks Shammi
    Regards
    Debra

  • SO Pricing User Exit - How to know which item is selected for re-pricing.

    Hello Experts,
    I have to modify material data when user does a update pricing in VA02, the problem is...How do I know which item is selected for re-pricing (in MV45AFZZ)? I am using user exit USEREXIT_PRICING_PREPARE_TKOMP.
    For Ex: If my order has 3 items and 2nd one is selected and then 'Update' is done on 'conditions' tab. Above pricing user exit is triggered 3 times for all items, so I cant check XVBAP.
    Your help will be appreciated.
    Thanks,
    Sagar

    Hi J@Y,
    Thanks for reply. But USEREXIT_PRICING_PREPARE_TKOMP is triggered for all items, so how do I know which is current item?
    If you see in debug mode, xvbap-posnr and tkomp-kposn will have 10,20,30 everytime (for 3 times). How do I know if user has selected 20?
    Thanks,
    Sagar

  • Identifying which line was selected from a WebDynpro table

    Hi,
    can any one give me some advice, I've created a view which displays a table of filenames, which in fact are "LinkToAction" columns. The idea was that when a filename(LinkToAction) was selected, I could retrieve the appropriate file from the Applicatio server and Open the file in Excel or Save as Excel. My problem is, when I select a filename I don't know how to identify what line was selected in the table. Any advice would be great.
    Thanks,
    C

    Hi , Just identify its element which is lead selected and read attribut of that element .
    Have the code for the same
    DATA:
        node_nd_worlflow                    TYPE REF TO if_wd_context_node,
        elem_nd_worlflow                    TYPE REF TO if_wd_context_element,
        stru_nd_worlflow                    TYPE wd_this->element_nd_worlflow ,
        lead_selection_index                TYPE i,
        relation_no                         TYPE guid_32.
    navigate from <CONTEXT> to <ND_WORLFLOW> via lead selection
      node_nd_worlflow = wd_context->get_child_node( name = wd_this->wdctx_nd_worlflow ).
    @TODO handle not set lead selection
      IF ( node_nd_worlflow IS INITIAL ).
      ENDIF.
    get element via lead selection
      lead_selection_index = node_nd_worlflow->get_lead_selection_index( ).
      elem_nd_worlflow = node_nd_worlflow->get_element( index = lead_selection_index ).
    elem_nd_worlflow->get_static_attributes( IMPORTING static_attributes = stru_nd_worlflow ).
    Cheers
    Parry

  • Java io and Java nio, which is faster to binary io?

    Anybody can advise me about java io and java nio ?
    I want to write the faster code to read and write binary files.
    I'm going to read/write
    - individual elements (int, double, etc)
    - arraylists
    - objects
    Also I'm going (or I'd want) to use seek functions.
    Thanks

    Anybody can advise me about java io and java nio ?
    I want to write the faster code to read and write binary files.Which is "faster" depends on exactly how you're using them. For example, a MappedByteBuffer is usually faster for random access than a RandomAccessFile, unless your files are so large (and your accesses so random) than you're constantly loading from disk. And it's not at all faster for linear uni-directional access than a simple FileInputStream.
    So, rather than expecting some random stranger telling you that one is faster than the other without knowing your project, perhaps you should tell us exactly how you plan to use IO, and why you think that one approach may be faster than the other.

  • Which is faster while executing statment having Case or Decode.

    Pls tell me which execute faster a case or decode.

    ajallen wrote:
    If you are really concerned about this, then you are being taken over by the tuning virus. You are out of control. You are tuning beyond reason. DECODE() is deprecated - not being enhanced. CASE is the new preferred approach. CASE is simpler and easier to code/follow.I can't find a link saying that DECODE() function is already deprecated. Can you give us a valid link?
    Regards.

  • WHICH IS FASTER AND WHY

    Hi Guys,
    Just want to knw which is faster
    java.lang.String.toLowerCase()
    or
    java.lang.String.toUpperCase()
    Thanks,
    Tuniki

    A look into the source code tells me that
    toUpperCasemay be slightly slower in rare cases when a single lower-case
    letter needs to be converted to an array of upper-case double-bytes.
    However, this depends somewhat on the frequency of conversions.
    If you have frequently strings that are all-upper-case, use
    toUpperCase()and -- vice versa -- if the strings are frequently all lower-case, then prefer
    toLowerCaseboth methods first test whether a conversion has to be made at all.

  • Which is fast

    Which is fast either stored procedure or stored function in oracle 10g.
    Thanks in advance

    i would say it depends on what you are trying to do in the body of the procedure or function.   i don't think it's a matter of which is faster. it would be more of a question of did you want to return something (in which case use a function) or nothing (in which case you can use a procedure).

  • Which item is selected?

    Hello,
    In Dreamweaver CS3 we have a drop-down list in a form. When
    the user selects an element in the list, we need to determine which
    element was selected; specifically we need the text string of the
    selected element. How do you do this? The raw code that we have so
    far is attached.
    If there is an online tutorial or sample code for this, that
    would be great.

    The element or item that was selected is automatically placed
    in a form variable for you by CS3. You can access it by binding it
    to the screen you are calling.

Maybe you are looking for

  • Podcasts broken in 9.2 with error "A duplicate file name was specified"

    Ever since the 9.2 upgrade my podcasts have not been able to update. The following error message is displayed when I click the icon next to the podcast: +There was a problem downloading "... podcast name ...". A duplicate file name was specified.+ Di

  • PROBLEM to give condition in ADF table column and on pressing enter

    Hi, 1st problem: ======== I have 1 ADF input text , <af:inputText id="testinp" contentStyle="width:200px" value="#{adfobj.input1}" /> say user is trying to enter any value , immediately if user presses "ENTER KEY" inside input text only i should invo

  • Security - Hackers Getting Usernames from Open Directory

    Hello, My logs indicate that someone from an outside IP has been trying to log-in to our MacOS X Server using AFP and SMB protocols. It appears they already know what usernames to try but they do not know the passwords. They even know about "test" ac

  • Reg : Error While uploading Datas from EXCEL in to SAP

    Hi Experts,                       Please help me with code inorder to upload EXCEL File DATA in to SAP.... I tried with FM : ALSM_EXCEL_TO_INTERNAL_TABLE   &   TEXT_CONVERT_XLS_TO_SAP but exception raised like  UPLOAD_OLE for me.. Wat to do...? Pleas

  • How can I get App Store to ignore updates?

    I'm sick and tired of being prompted to update to pages 5 which I utterly loathe. I keep trying to control-click the update which used to give the option to skip that update, but now I can't seem to get that menu item. Is there a way to do that now?