Two tables: With table B having thousands of records, which of the following statements would be the least expensive? Option 1: Option 2: My gut tells me they're exactly the same. But I need more than my gut to go on. asked 13 Aug '14, 05:12 Liam |
Having said that, my guess is they will have the same plans and the same performance. I am VERY PROUD of my guesswork... answered 19 Aug '14, 06:22 Breck Carter |
No, I don't claim to know the answer. But I wanted to add, if you're on SQLA 11 or higher, there's a 3rd method (example not verified):
IMHO all tree statements should be broken down by the query engine to similar sequences of execution, so there should be no real difference in performance.
But that's speculative, so to get more detailed information you might want to execute both statements in identical environments, capture the graphical plans and analyze them for deviations.
OK just a guess but I would think Option 1 is more efficient when dealing with a small number of rows and option 2 when dealing with large inserts. I believe some DBMS's just ignore the error with option 1.
Jim
I'm with Jim on this one. Thanks guys
FWIW, I believe "INSERT ... ON EXISTING ..." is primarily a SQL Anywhere vendor extension so I don't really understand the "some DBMS's" statement... - of course, other DBMS like MySQL have somwhat similar extensions like "INSERT ... ON DUPLICATE KEY UPDATE..."