Give destructive warning on multi-table UPDATEs#1519
Conversation
scottnemes
left a comment
There was a problem hiding this comment.
This works in the case of always warning if you run a multi table update, regardless of where clause.
However it diverges from the behavior of a single table update, where if you do have a where clause on a single table update, it will not warn. However with this change, every multi table update will warn, even if you have a full where clause. This goes back to the comment I posted in the issue originally, where it is more difficult to make sure a multi table where clause covers all tables due to the possible variations on specifying columns in the where clause (with or without a table prefix, and aliases). I.e. if you are updating t1 and t2, you need a where clause with columns from both t1 and t2.
So long and short, this will start forcing a warn on all multi table updates, even if they have a full where clause. Users can disable warns on update at that point, but then they end up worse than before.
Before:
update t1, t2 set t1.id = 3, t2.id = 3; # warning, no where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1; # no warning, partial where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1 and t2.id = 1; # no warning, full where clause
After
update t1, t2 set t1.id = 3, t2.id = 3; # warning, no where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1; # warning, partial where clause
update t1, t2 set t1.id = 3, t2.id = 3 where t1.id = 1 and t2.id = 1; # warning, full where clause
So in the case where someone runs a multi table update without a full where clause, this change is better as that is dangerous. However if someone runs a multi table update with a full where clause, it still warns, which might not be ideal.
That was the intention of the PR! We'd have to go deep into the SQL to do otherwise. Open to that, too! |
Only suppress the destructive-command warning for the simple case of a single-table UPDATE with a WHERE clause.
1e97caf to
fd9ca86
Compare
Yeah I'm pointing out this makes divergent behavior, which in the past you've always been against. But if it's working as you want, then that's okay; it works as described. |
|
Agreed, @scottnemes, this is a super tricky feature. Even with the prior and current implementations, nothing helps you if you type |
Description
Only suppress the destructive-command warning for the simple case of a single-table
UPDATEwith aWHEREclause.Fixes #791.
Checklist
changelog.mdfile.AUTHORSfile (or it's already there).