Bug #72476 Modifying in Workbench causes update trigger to modify all records instead of 1
Submitted: 28 Apr 2014 23:42 Modified: 15 Sep 2014 17:28
Reporter: Gordon Ramshackle Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Workbench Severity:S1 (Critical)
Version:6.1 OS:Windows (8.1 64-bit)
Assigned to: CPU Architecture:Any

[28 Apr 2014 23:42] Gordon Ramshackle
Description:
I query a table. Results display in the grid.

I have a update trigger with an update command that puts a value in a field of the modified record when the update trigger is invoked. It can be any field. I'll call it "test".

I modify 1 record in the result grid. The update trigger's update command should update the "test" field of that modified record. Instead, the update command is applied to every record in the grid.

The SPECIFIC scenario where this occurs is when the results satisfy a certain criteria. When the modified record  no longer satisfies that criteria, the result grid is refreshed and the modified record is removed. It seems that when the grid is refreshed, the update command in the update triggers gets applied to all records in the result grid.

For example, I have a field called "color" and I query for records with "color=red". If I change the color in the result grid from "red" to "green", that record no longer satisfies the query so it disappears and the bug kicks in.

My update trigger also had an INSERT command, but only the UPDATE command is errant.

How to repeat:
Create a table and add a trigger that updates a field in the updated record. It should update that record only.

Query a table with a criteria (select * from cars where colorid=1) and display in Workbench result grid.

Change one record so that it no longer satisfies the criteria. (Change "colorid" of a single record to "2".) The update trigger should apply only to that one record.

However, when the record no longer satisfies the criteria, it is removed from the result grid and after the refresh, the update trigger applies the update to all records that appear in the result grid.

Suggested fix:
Don't perform the excessive updates. It corrupts the data.
[7 May 2014 14:31] Chuck Bell
Filed under wrong category. Reset to WB proper.
[24 May 2014 16:41] Gordon Ramshackle
Vehicle	Color	SeatColor

Car1		Red		White
Car2		Red		White
Car3		Red		White
Car4		Red		White
Car5		Red		White

Vehicle	        Color	        SeatColor

Car1		Red		White
Car2		Red		White
Car3		Blue		Blue
Car4		Red		White
Car5		Red		White

Vehicle	Color	SeatColor

Car1		Red		Blue
Car2		Red		Blue
Car3		Blue		Blue
Car4		Red		Blue
Car5		Red		Blue
[24 May 2014 16:41] Gordon Ramshackle
Vehicle	Color	SeatColor

Car1		Red		White
Car2		Red		White
Car3		Red		White
Car4		Red		White
Car5		Red		White

Vehicle	        Color	        SeatColor

Car1		Red		White
Car2		Red		White
Car3		Blue		Blue
Car4		Red		White
Car5		Red		White

Vehicle	Color	SeatColor

Car1		Red		Blue
Car2		Red		Blue
Car3		Blue		Blue
Car4		Red		Blue
Car5		Red		Blue
[24 May 2014 16:41] Gordon Ramshackle
Vehicle	 Color	SeatColor

Car1		Red		White
Car2		Red		White
Car3		Red		White
Car4		Red		White
Car5		Red		White

Vehicle	        Color	        SeatColor

Car1		Red		White
Car2		Red		White
Car3		Blue		Blue
Car4		Red		White
Car5		Red		White

Vehicle	Color	SeatColor

Car1		Red		Blue
Car2		Red		Blue
Car3		Blue		Blue
Car4		Red		Blue
Car5		Red		Blue
[24 May 2014 17:01] Gordon Ramshackle
Here's a clearer, visual explanation of the bug:

We start with the following sample data. There is update trigger that checks if the color was changed. If it was, "SeatColor" is updated to the same color.

Vehicle  	 Color	       SeatColor

Car1		Red		White
Car2		Red		White
Car3		Red		White
Car4		Red		White
Car5		Red		White

If I change the color of "Car3" to "Blue", the "SeatColor" field will change to blue. This is the desired result.

Vehicle	        Color	        SeatColor

Car1		Red		White
Car2		Red		White
Car3		Blue		Blue
Car4		Red		White
Car5		Red		White

This is what happens if the color field is changed in the Workbench result grid, if the results were displayed using 

"select vehicle, color, seatcolor from Cars where color='Red'". 

The "SeatColor" for all records in the result grid are updated with the action intended for "Car3"

Vehicle  	Color    	SeatColor

Car1		Red		Blue
Car2		Red		Blue
Car3		Blue		Blue
Car4		Red		Blue
Car5		Red		Blue

This is clearly a "Workbench" bug because it does not occur through other means, such as running an UPDATE command such as:

"UPDATE Cars SET Color='Blue' WHERE Vehicle='Car3'"  // This updates data properly.

The bug does not occur if all cars are listed rather just "Red" cars. In that case, "Car3" remains in the result grid, thus, no bug.

The bug occurs when the results are filtered, for this example, show only "Red" cars. When the color of "Car3" is changed to "Blue", it is removed from the result grid because the grid is currently displaying only "Red" cars. When the "update trigger" changes the "SeatColor" of "Car3" to "Blue", rather just "Car3" being affected, all cars in the result grid are affected and all their "SeatColor" fields are changed to "Blue".
[24 May 2014 17:12] Gordon Ramshackle
To clear up the above example, the last set of data is a tabular representation of the results, not the actual results in the Workbench grid. In workbench, the record for "Car3" is removed because Workbench is only displaying "Red" cars.

Vehicle  	Color    	SeatColor

Car1		Red		Blue
Car2		Red		Blue
Car3		Blue		Blue  // This row is removed from the result grid because
                                      // Workbench is only showing "Red" cars.
Car4		Red		Blue
Car5		Red		Blue
[15 Aug 2014 14:14] MySQL Verification Team
Please provide a dump file with create statement and data inserts. Thanks.
[15 Aug 2014 17:22] Gordon Ramshackle
The bug appears to have been fixed.

My real-life case was a 2-table scenario. The sample I provided was a 1-table scenario, which was simpler to recreate and simple to verify and which I did verify.

I currently use Workbench 6.1.6.11834 build 1642 Community. I don't have a record of the 6.1 build with the bug.

The 1-table scenario now does not complete the sequence of events the resulted in data corruption. The sequence halts with an error saying the table is in use by a trigger and cannot be updated.

The 2-table scenario now only updates the proper rows rather than all the rows that was displayed in the Workbench output grid.

I would have like to see an indication that someone had worked on my bug submission., an indication that the bug existed and was fixed due to my bug submission. At least make me feel that the time I put in to help was worthwhile. I would hate to see my submission put under “Can't repeat”, “Not a bug”, “Won't fix” etc.

Anyone can use an older version of 6.1 to recreate the bug but the world will never know how and why the “obscure” bug was fixed.

Also, the 1-table fix looks more like a quick-fix than a proper solution but it at least halts the possible corruption of data.
[15 Aug 2014 17:28] MySQL Verification Team
Thank you for the feedback. If the issue isn't more repeatable on 6.1.7 then this bug report will be closed. Thanks.
[16 Sep 2014 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".