Why is the 'UNION' statement faster than 'OR' sometimes?

Many articles say that the 'UNION' statement can make the SQL statement run faster than "GOLD" awhile. However, why is the 'UNION' statement faster than 'OR' some time? Why does CBO sometimes choose 'UNION', not 'GOLD'.

Hello

If you have a select statement like this

Select * from my_table where col1 like "something %' or col2 like '% else';"

and there is an index on col1 and an index on col2. It may be a good idea to chosse a union. This is just an example.

Best regards

Thomas

Tags: Database

Similar Questions

  • What can I do if the script runs faster than the network?

    I wrote a script between applications moving to InDesign, where he begins to AppleScript, to Photoshop, which AppleScript runs a JavaScript script to perform various tasks.

    It works beautifully on my laptop at home where I do my development. Yesterday, using me as a Guinea pig, I tried it in the office.

    On the third round, I was horrified to see the ExtendScript Toolkit pop up with an error message (about as welcome to see an AppleScript script, asking the user to open the Script Editor and fix a script).

    The error message was that app.bringToFront (); was not a valid function.

    This was the case in InDesign, which has a different activation function, and I realized that, even if my AppleScript called Photoshop activate, I was still in InDesign.

    The app.bringToFront JavaScript was so called because I had joined my code in the model of Tranberry.

    So I pressed the button stop on ExtendScript, returned to InDesign and represented the script. This time he worked as usual.

    Occasionally on our network we spend some time beachball - watch as a communication happens in the background. So I guess the time wherever the error was thrown was on one of these downturns in the network.

    The passage of InDesign, Photoshop is not happening pretty fast, but the script has run and has issued an order Photoshop JavaScript while I was still in InDesign.

    In AppleScript this unhappy communication with users can be avoided using blocks '... try error'.

    Is there an equivalent of the error handling in JavaScript that would allow me to avoid being tossed in the ExtendScript Toolkit and give them a friendly message to apologize, explaining what had happened and inviting them to try again?

    JavaScript has try/catch blocks

    try {}

    app.bringToFront ();

    } catch (e) {}

    error handling code

    }

    Or you might be able to use an if statement

    If (app == 'photoshop') {}

    app.bringToFront ();

    } else {}

    app handle not photoshop

    }

  • scroll - why only the up and down arrows works sometimes, and then you must use the arrow on the right side, very annoying, thank you very much

    will have hard to scroll upwards and the arrows of downusing, to scroll, I use aeeow to scroll on the side, first release it on bar, using internet brands this task

    a real pain.  also how to use all the symbols on the keyboard, keyword, can'tget four symbols to display

    Thank you very much

    Hello

    1. What is the brand and model of the computer?
    2. In the face of this issue only when you are on the Internet?
    3. Have you made changes on the computer before this problem?

    I suggest you to check the status of the issue to keep the computer in a clean boot state.

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7.

    http://support.Microsoft.com/kb/929135

    Note: Please, go to step 7 of the Kb to maintain the computer to a normal startup after you fix the problem.

    You can also refer to:

    Troubleshoot wired keyboards that do not or only the erroneous characters category.

    http://support.Microsoft.com/kb/258826

     

    Optimize Windows 7 for better performance.

    http://Windows.Microsoft.com/en-us/Windows7/optimize-Windows-7-for-better-performance

     

     

  • need help with the Merge statement

    I'm on: Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    I'm currently an UPDATE statement and then it works and is accurate, it takes 30 minutes. I heard that MERGE
    can do the same thing and is just as accurate and much faster!

    Here's the query I want to convert into a MERGE INTO statement. I tried to do it myself, but I get errors and don't know simply, since it's new for me.

    Basically I want to update table your on a corresponding condition in the table tt for 2 columns (GTP and UPDATE_DT), for UPDATE_DT I want to insert the Date current system.
    UPDATE /*+ PARALLEL (16) */  OLDER_Table ta
    
    SET (ta.GTP, ta.UPDATE_DT) = 
    
                    (SELECT /*+ PARALLEL (16) */ tt.GTP, SYSDATE
                     FROM NEWER_Table tt
                     WHERE ta.cust_id = tt.cust_id
                     AND ta.STAMP_DATE = tt.STAMP_DATE
                     AND ROWNUM = 1)
    
                     WHERE EXISTS (SELECT 1
                                   FROM NEWER_Table tt
                                   WHERE ta.cust_id = tt.cust_id
                                   AND ta.STAMP_DATE = tt.STAMP_DATE
                                   AND (NVL(ta.GTP, 'X') != NVL(tt.GTP, 'X'))); 
    Thank you!

    Hello

    Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all of the tables involved.
    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
    If you ask on a DML statement, such as UPDATE, CREATE TABLE and INSERT statements need to re - create the tables as they are before the DML, and results will be the content of the or the tables changed when it's all over.
    See the FAQ forum {message identifier: = 9360002}

    MERGE peut be much faster than update; Sometimes, there is no significant difference in speed.
    Tables in multiple situations like this, I've never seen a case where the MERGER has been slower than the UPDATE, even if the UPDATE is sometimes easier to code and just as fast.

    Maybe that's what you want:

    MERGE INTO  older_table            dst
    USING  (
               SELECT  n.cust_id
            ,        n.stamp_date
            ,        n.gtp
            ,        ROW_NUMBER () OVER ( PARTITION BY  n.cust_id
                                               ,           n.stamp_date
                             ORDER BY      n.gtp
                              )                    AS r_num
            FROM        newer_table  n
            JOIN        older_table     o  ON   n.cust_id     = o.cust_id
                                 AND     n.stamp_date     = o.stamp_date
                           AND     NVL ( n.gtp
                                    , 'X'
                                 )          != NVL ( o.gtp
                                                  , 'X'
                                              )
    
           )                 src
    ON     (    src.cust_id            = dst.cust_id
           AND  src.stamp_date     = dst.stamp_date
           AND  src.r_num            = 1
           )
    WHEN MATCHED THEN UPDATE
    SET    dst.gtp          = src.gtp
    ,      dst.update_date     = SYSDATE
    ;
    

    As I can't test it, I can't be sure.

  • Problem with analysis - union statement

    Hi all

    I have an analysis where I use the union statement. I have 4 columns in the result and 4 columns in select statements.
    Each select statement is a single equipped with filters.
    The results are presented in two rows. In my understanding it #of of columns and type paired in the union statement, I should get 1 row of results (summary of the two).

    How can I check in BI which is the cause two appear in two lines instead of 1?

    Thank you.

    Published by: user8461308 on April 13, 2012 03:13

    Set property of a measure to pivot as SUM aggregation. If all the attributes displayed in 'Row' are exactly the same, OBIEE apply group by making the data.

    See you soon...

    Patrick
    [http://obieetipsandconcepts.blogspot.com/]

  • Reset the accordion State when the Page refreshes

    I read a few posts online of people who have encountered the same problem, however I have not yet met any soloution to it.

    If you have an accordion menu and the page is refreshed that the accordion retains its last State rather than reloading to its first State. Is there anyway to stop it from doing this?

    Thank you
    Katy

    "katychapman85" wrote in message
    News:g77ca5$9C$1@forums. Macromedia.com...
    > I read a few posts online of people who met the same
    > problem.
    > However, I have not met any soloution to it.
    >
    > If you have an accordion menu and the page is refreshed on the accordion
    > canned
    > It is the last State rather than reloading to its first State. Is there anyway
    > to
    > don't let him do that?

    Disable history management.

  • query: without the help of the union

    Hai, everyone,

    IHAVE àtable like this:

    Table1:

    ID emp1 emp2 emp3
    1 100 200 300
    2 90 295 977
    3 150 299 500




    and I need the result like this:

    100
    90
    150
    200
    295
    299
    300
    977
    500



    the result is just union emp1, emp2 and emp3

    That is to say, this type of result, we can produce with this:

    Select emp1 in table1 union select emp2 emp3 union table1 select from table1

    but I need a query with the same result as above without using the union statement

    Thanks in advance...

    Published by: jp_valapad on Sep 12, 2008 02:38

    Published by: jp_valapad on Sep 12, 2008 02:39

    But the order guaranteed?

    N ° as it is never without an order by ;)
    But op didn't say anything about a particular order (again)...

  • Why disable SuperFetch on ssd, if the RAM is much faster than the ssd?

    Directed by Microsoft that SuperFetch and PreFetch must be disabled, if the OS is installed on an ssd, in accordance with article http://support.microsoft.com/kb/2727880. But SuperFetch is used for loading the data components of applications, which were very often used for RAM. Although the ssd is faster that a hard drive is not faster than the RAM. So, I do not understand why Microsoft suggest disabling this feature. The only reason why I want to understand, it's because of a limited RAM. If the RAM is sufficient beyond 6 GB, if we disable SuperFetch, then the boot time and increase the loading time of most used applications. I miss something here?

    The other question is about PreFetch. I feel, maybe wrong, it does the same thing with SuperFetch, with one major difference. It loads all the information data on the ssd or hard drive, instead of the RAM, in order to accelerate the launch of applications and time when the OS is installed on a hard drive to boot. If I'm right, let's disable the PreFetch it stores information for one ssd or hdd, while SuperFetch stores data of RAM information, which is much faster and so it must be enabled if there is a sufficient RAM.

    I look forward to reading the notice of a Microsoft software engineer.

    Hi Leventis,

    Prefetch copies frequently accessed files together into a contiguous on the disk area so that they can be located and loaded more quickly. That it takes a lot of old drives to recover data faster.

    SuperFetch predict what applications you run next and preload all the necessary data in the memory. She has also done that with startup files. And for all the three days he sends a defragmentation command to the OS drive that will cause problems in the SSD drives.

    In traditional hard drives (HDD) data are scattered throughout the disk, so that the operating system for access, it will take more time. It is suggested to perform a disk defragmentation. But storage technology is different in SSD, where, it records the data dynamically and it recovers more quickly. Who will be low down the burden on the RAM and the RAM can be used for uses such as for the opening of the games graphics high-end, etc..

    Hope this information is useful.

  • something faster than the UNION ALL?

    Hello

    I have two tables, with 20% and 80% of a total Group of data.
    The next time you press data, I need to have one top index so that the total dataset can be scanned.

    The result of this update is an update of the two tables.

    Here's my question (pls ignore syntax errors):

    I could do something like:

    create new_table
    As select * from t1
    UNION ALL
    Select * from t2

    change new_table add a primary key (acc_no)

    and then
    drop table t1
    drop table t2

    then the next cycle of treatment happens that, using new_table and a new set of entry, the t1 and t2 are filled (updates/inserts; and non-modifications/old)

    Then, new new_table is generated by t1 and t2... with a new index.

    This table is used again to read the next incoming batch of data, new filling t1 and t2...
    etc etc.

    actually, we have table t1 to send out of the database (flatfile). Then maybe we can do something faster as well. Maybe we don't need two tables at all?


    QUESTION 1:
    rather than generate a new table OF T2 T1 UNION ALL, I rather have the new table 'to be' the two tables? In this case, I just need to build the index on the table. Of course, t1 and t2 would disappear, but I have to drop them in any case for the next set of data.

    QUESTION 2:
    a little more advanced, is this table that combines all the results in the next 'as-is', must in fact be a table? I just need the appropriate fields (hm, in fact - all - fields) so I can make a new t1 and t2; There may be some smarter way to do it, without actually creating a new table t1 and t2 all the time...

    a big thank you in advance, your help is greatly appreciated

    Arne

    Rustydud wrote:
    Hi Dave Hemming.

    two thoughts on this approach,
    first of all I have not needed to keep the info on what were t1 and t2; they can be recessed. Rather the other way around, t1 + t2 will be "reborn" in the next run, based on the staging of new data and the "union all" table of the previous run (t1 + t2). then you see IS t1 + t2, after which t1/t2 would become useless.

    No, I do not say that you will not regenerate the tables t1 and t2. There is only one only true table new_table. Everything you would do the table t1 that you do view t1 and it is done as if by magic to the underlying new_table. Even with t2 - there is an opinion, not a table.

    The other approach is a view new_table which is a union of the tables t1 and t2, but then how do you index?

  • Why is the Nightly build of so much faster and has better quality than the final product of Firefox features?

    The Nightly build is so much faster than Firefox, and the download feature is much better than the download feature in Firefox.

    The arrow next to the home button will appear in the version of Firefox in Firefox 20. All the features that are in every night thereafter will appear in liberation, when they are ready.

  • Why preview is rendered faster than the actual speed of my clips?

    When I create a new project, the overview of my project "plays" faster than the speed of the video. As it is fast forward. Each of the speed of clips are 100%.

    I tried to uninstall and reinstall the first but still have the same problem.

    Any idea? Thank you

    sample rate is 48 kHz

    Some people set their entry to 'none', but I do not see as to how that is going to change anything

  • Why is developer of Firefox more stable and faster than ordinary Firefox?

    So, I have some great experiences with regular Firefox. It works great themes, beautiful, good plugins, security etc., but there is one thing that bothers me in Firefox on ALL computers on EACH operating system. Whenever I have install Firefox, it is already slow, he stutters sometimes and sometimes it freezes. And this isn't just my problem because many of my friends and classmates using Chrome right now they complain about the speed of Firefox. Now, for me it is not a problem, I'm not a patient person, but it certainly is the browser that will protect my privacy rather than Chrome.

    Recently, somewhere, I saw download link saying something like "Developer Mozilla, for people like you", or something like, I installed and the man, the browser is like 10 x faster than regular Firefox AND Chrome AND Safari, I mean, this speed is outrageous! It's great, no sarcasm!

    I don't get, why is so slow regular Firefox and Firefox Developer so frickin' fast? Why? Perhaps, you can base your next update of Firefox to the developer of Firefox?

    Sincerely in love with developer of Mozilla Firefox. * muah *.

    Firefox Developer Edition is a version of Firefox. So what you see in the developer edition is coming out to regular Firefox in about 12 weeks (we releases every 6 weeks, and Dev edition is two versions before publication)

    Dev Edition also uses a fresh profile, which may be faster than your old profile which is full of old data.

  • Why Chrome load websites faster than Firefox

    I can load a website at least two times faster than Firefox Chrome. Why?

    Hello

    The reset Firefox feature can solve a lot of problems in restaurant Firefox to its factory default condition while saving your vital information.
    Note: This will make you lose all the Extensions, open Web sites and preferences.

    To reset Firefox, perform the following steps:

    1. Go to Firefox > help > troubleshooting information.
    2. Click on the button 'Reset Firefox'.
    3. Firefox will close and reset. After Firefox is finished, it will display a window with the imported information. Click Finish.
    4. Firefox opens with all the default settings applied.

    Information can be found in the article Firefox Refresh - reset the settings and Add-ons .

    This solve your problems? Please report to us!

    Thank you.

  • Why this parallel DML statement is not run as fast as DBMS_PARALLEL_EXECUTE?

    Hello

    I'm on the database Oracle Enterprise Edition, Linux RH 11.2.0.3. I have a pl/sql function that accepts a sdo_geometry (essentially an object with a few varrays), round each number in one of the varrays and retransmits the object.  Here is a version of the function, simplified slightly for brevity:

    create or replace round_coordinates (p_geometry in sdo_geometry, p_round_factor in numbers)

    return sdo_geometry parallel_enable

    is

    sdo_geometry v_geometry: = p_geometry;

    v_ordinates sdo_ordinate_array;

    Start

    v_ordinates: = p_geometry.sdo_ordinates;

    for me in v_ordinates.first... loop of v_ordinates. Last

    v_ordinates (i): = round (v_ordinates (i), p_round_factor);

    end loop;

    Return sdo_geometry (v_geometry.sdo_gtype, v_geometry.sdo_srid, v_geometry.sdo_point, v_geometry.sdo_elem_info, v_ordinates);

    end round_coordinates;

    /

    I need to perform this function as an update DML on hundreds of millions of sdo_geometry objects and according to my estimates it will take weeks.  So, I want to run in parallel.

    The data is in a bunch of tables, some with lines of k ~ 100 more with millions of people.  My preference is to browse the tables and run an update such as:

    Update < table > set geometry = round_coordinates (geometry);

    But I would like to operate in parallel, so I thought that I would allow the DML parallel to the session with

    ALTER session enable parallel dml.

    ALTER table < table > parallel;

    , and then run the update by: Update / * + parallel * / < table > set geometry = round_coordinates (geometry);

    When I do that, I can see a v$ px_session 16 parallel slaves are bent and the plan of the explanation is the following:

    ------------------------------------------------------------------------------------------------------------------

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |    TQ | IN-OUT | PQ Distrib.

    ------------------------------------------------------------------------------------------------------------------

    |   0 | UPDATE STATEMENT.             | 10000 |   468K |    43 (0) | 00:00:01 |        |      |            |

    |   1.  UPDATE | SMALL_10000 |       |       |            |          |        |      |            |

    |   2.   COORDINATOR OF PX |             |       |       |            |          |        |      |            |

    |   3.    PX SEND QC (RANDOM). : TQ10000 | 10000 |   468K |    43 (0) | 00:00:01 |  Q1 00 | P > S | QC (RAND) |

    |   4.     ITERATOR BLOCK PX |             | 10000 |   468K |    43 (0) | 00:00:01 |  Q1 00 | ISSUE |            |

    |   5.      TABLE ACCESS FULL | SMALL_10000 | 10000 |   468K |    43 (0) | 00:00:01 |  Q1 00 | SVCP |            |

    ------------------------------------------------------------------------------------------------------------------

    But the update statement on my test data set does not any more quickly - it takes a few seconds more series that suggests General fresh extra expectations for the management of parallel slaves that's happened, but they did not have the query run faster.


    I tried to use the dbms_parallel_execute with the create_chunks_by_rowid option package and parallel_level = 16 With that I get at the end just over 1/16th of the time that it takes to run in series!

    That's fine, so I have the option dbms_parallel_execute, but I would like to understand why the query with the parallel flag does not expedite things.

    Any ideas?

    Thank you

    John

    It may be that the call to the PL/SQL function slows down things. Did you think to do in pure SQL?

    Here is an example:

    update test_sdo tsd
       set tsd.geometry.sdo_ordinates =
           (select cast(collect(round(t2.column_value)) as sdo_ordinate_array)
              from test_sdo t1
                  ,table(t1.geometry.sdo_ordinates) t2
             where t1.id = tsd.id)
    

    Post edited by: PaulHorth

    BTW: You can parallelize the query part of the SQL but not updating, it's documentation:

    "Parallel DML can be done on tables with columns object provided that the columns of the object are not accessible."

  • T500 T8700 processor work much faster than on the current of a battery!

    My colleagues and I are having a very annoying problem with our thinkpad t500 (approximately 200 laptops or more). the problem is that the CPU is intel core 2 duo T8700 2.53 ghz works only with 1.6 ghz speed on idle and load the State with alternating current and never jump higher than speed and jumps only to 2.53 ghz speed if and only if the battery is connected to the laptop, the laptop is faster using the battery that is strange indeed.

    My own opinion on this issue, it is that it is a bug in the bios that is the switching in a different way processor modes (processor with power supply ofc should be faster than with battery) I've already updated my bios of the laptop to 3.09 version, but always without success. The serial number of my laptop is "*".

    I hope that fix you this very soon.

    Moderator edit: number masked to prevent improper use.

    Hi mtaher and welcome to the Lenovo user community!

    Connected to a 65W power adapter, the T500 is relies on the battery to power during peak load. If you remove the battery, he's choking back the CPU at a level that the 65W adapter can handle alone. It probably won't happen if you use a 90W Adapter (I don't have anyone around to test - maybe someone can confirm).

    The research community and you will find this discussed many times - that's the behavior designed most of the models.

Maybe you are looking for

  • Web site says 8.0.1 available, but my paycheck update v8.0.0 says that Firefox is updated

    I see on the web site of Mozilla Firefox 8.0.1 is available on the output channel, however, when I check with v8.0.0 updates that Firefox says it is up-to-date. I tried with my user and administrator accounts. I also tried the 'solution' described in

  • Satellite L555-10N: toshiba recovery not disc creator no work Win7 x 64

    Hello creator of recovery disk Toshiba cannot be installed. need it please help. Thank you http://img517.imageshack.us/img517/5869/unbenannt1ja.jpg Does anyone has the left one to the current version? Laptop: Toshiba Satellite L555-10NWin7 x 64

  • Bluetooth network and Internet connection sharing problem

    I am putting in place a network via Bluetooth between two computers later with Toshiba Stack installed and to share the Internet connection with the second computer. On the computer of trees I put Internet connection sharing, and for this reason, it

  • Spectrum 360 core i5 HP: e ghost?

    I got my spectrum in April 2015. Generally, I love him, but have questions if anyone of you a few problems: (1) sometimes, I get an 'e' ghost appearing. Looks like the keyboard detects my fingers hovering above it and displays an 'e' on the screen. I

  • Error HP Deskjet F2280 peripheral USB not recognized.

    Original title: How can I get my printer recognized. When I turn my printer I get the error notice following (USB device not recognized). I'm working on Windows XP. It was working fine until last week when he suddenly showed the error notice. It's a