Subject | RE: [Bulk] [firebird-support] Is Update or Insert more slower than an single Update (or insert) |
---|---|
Author | Leyne, Sean |
Post date | 2012-01-14T18:51:38Z |
Stephane,
It is incorrect to assume that all SQL operators/ statements will perform the same. Further, I am not sure why you would think that way.
It seems obvious to me that "INSERT" and "UPDATE ***OR*** INSERT" would have different performance -- they are not equivalent!
The correct test would have been to create 2 SPs, one which used UPDATE OR INSERT and one which followed the legacy method:
IF (EXISTS(SELECT 1 FROM Table WHERE Fieldx = X)) THEN
UPDATE Table SET... WHERE Fieldx = X;
ELSE
INSERT INTO Table (...) VALUES (...);
And then compare the performance of the SPs.
I am 100% that you would be very happy with the performance of UPDATE OR INSERT.
Sean
> Thanks to my paranoia, i was thinking like everyone thatI don't know that "everyone" had the same expectation.
>
> Update or insert
> OR
> Insert
>
> will be close to the same speed (or very similare)
It is incorrect to assume that all SQL operators/ statements will perform the same. Further, I am not sure why you would think that way.
It seems obvious to me that "INSERT" and "UPDATE ***OR*** INSERT" would have different performance -- they are not equivalent!
> Update or insert is 2x more slower than insert alone :( :( :(This was an invalid test.
>
> 100000 Update or insert => 0.501 ms average insert time
> 100000 insert => 0.300 ms average insert time
>
> sad but interesting to know !
The correct test would have been to create 2 SPs, one which used UPDATE OR INSERT and one which followed the legacy method:
IF (EXISTS(SELECT 1 FROM Table WHERE Fieldx = X)) THEN
UPDATE Table SET... WHERE Fieldx = X;
ELSE
INSERT INTO Table (...) VALUES (...);
And then compare the performance of the SPs.
I am 100% that you would be very happy with the performance of UPDATE OR INSERT.
Sean