If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Identical UPDATE?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-31-11, 06:59
Ikviens Ikviens is offline
Registered User
 
Join Date: Mar 2006
Posts: 55
Identical UPDATE?

Hello forum,

I am just wondering what a DB reacts (or should react) to an UPDATE statement that includes an identical update. By this I mean updating a column with exactly the same value as what is currently found.

Code:
UPDATE SomeTable
   SET col_1 = col_1
Does the database actually update the column with the self-same new value or is it clever enough to skip execution, "Oh, the new value is the same as the old one. No need to start an update for this row. Next!"?
Reply With Quote
  #2 (permalink)  
Old 10-31-11, 07:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
mysql is smart enough, not sure about other database systems

not sure about ANSI SQL either (the forum you posted in)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-31-11, 08:18
Ikviens Ikviens is offline
Registered User
 
Join Date: Mar 2006
Posts: 55
Thanks rudy. I was actually thinking of branching update values using CASE:
Code:
UPDATE SomeTable
   SET col_1 = CASE WHEN <cond 1>
                    THEN  col_1 * 10 
                    WHEN <cond 2>
                    THEN  col_1 * 5 
               ELSE col_1 END
I wondered if writing "ELSE col_1" makes the execution considerably slow compared to a statement that has "<cond 1> OR <cond 2>" in a WHERE clause. Glad to know that I don't have to worry about it for MySQL. Still, I will wait for info about "da standard" and other DB products.

By the way, what if the ELSE condition were "col_1 * 1"? Maybe SQL is not very good at processing equations?
Reply With Quote
  #4 (permalink)  
Old 10-31-11, 09:15
JarlH JarlH is offline
Registered User
 
Join Date: Dec 2008
Location: At work...
Posts: 68
What about transaction isolation levels and write-sets?

Example:
You have a table with one million rows, where 10 rows fulfill <cond 1>
and 10 other rows fulfill <cond 2>.

If the UPDATE statement has no where clause the transaction involves all 1 000 000 rows. What do you want to happen if somebody else at the same time updates one of the 999 980 "else" rows?
Reply With Quote
  #5 (permalink)  
Old 10-31-11, 09:51
Ikviens Ikviens is offline
Registered User
 
Join Date: Mar 2006
Posts: 55
I have a more rudimentary case where the data size is under 100 and the change is more or less permanent, but I see your point. THanks.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On