You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It uses a DELETE FROM LEFT JOIN but uses an AND instead of a WHERE clause and is likely caused by the nature of a left join which will delete the rows from the left table even if not present in the right table. This is reproducible with a trivial example in mysql.
root@mysql> CREATE TABLE vdiff (
-> id INTEGERPRIMARY KEY AUTO_INCREMENT,
-> vdiff_uuid INTEGER-> );
Query OK, 0 rows affected (0.01 sec)
root@mysql> CREATE TABLE vdiff_table (
-> id INTEGERPRIMARY KEY AUTO_INCREMENT,
-> vdiff_id INTEGER-> );
Query OK, 0 rows affected (0.01 sec)
root@mysql>INSERT INTO vdiff(vdiff_uuid) VALUES (1);
Query OK, 1 row affected (0.00 sec)
root@mysql>INSERT INTO vdiff(vdiff_uuid) VALUES (2);
Query OK, 1 row affected (0.01 sec)
root@mysql>INSERT INTO vdiff(vdiff_uuid) VALUES (3);
Query OK, 1 row affected (0.00 sec)
root@mysql>INSERT INTO vdiff_table(vdiff_id) VALUES (1);
Query OK, 1 row affected (0.00 sec)
root@mysql>INSERT INTO vdiff_table(vdiff_id) VALUES (1);
Query OK, 1 row affected (0.00 sec)
root@mysql>INSERT INTO vdiff_table(vdiff_id) VALUES (2);
Query OK, 1 row affected (0.01 sec)
root@mysql>INSERT INTO vdiff_table(vdiff_id) VALUES (2);
Query OK, 1 row affected (0.00 sec)
root@mysql># BEFORE DELETE WITH 'LEFT JOIN AND'
root@mysql>select vd.*from vdiff as vd
->left join vdiff_table on (vd.id=vdiff_table.vdiff_id);
+----+------------+
| id | vdiff_uuid |
+----+------------+
| 1 | 1 |
| 1 | 1 |
| 2 | 2 |
| 2 | 2 |
| 3 | 3 |
+----+------------+5 rows inset (0.00 sec)
root@mysql>deletefrom vd, vdt using vdiff as vd left join vdiff_table as vdt on (vd.id=vdt.vdiff_id)
->andvd.vdiff_uuid=2;
Query OK, 5 rows affected (0.01 sec)
root@mysql># AFTER DELETE WITH 'LEFT JOIN AND'
root@mysql>select vd.*from vdiff as vd
->left join vdiff_table on (vd.id=vdiff_table.vdiff_id);
Empty set (0.00 sec)
However, if I switch to use a where clause in WHERE vd.vdiff_uuid = 2 we see it deletes the rows correctly.
root@mysql>deletefrom vd, vdt using vdiff as vd left join vdiff_table as vdt on (vd.id=vdt.vdiff_id)
->wherevd.vdiff_uuid=2;
Query OK, 3 rows affected (0.00 sec)
root@mysql>select*from vdiff;
+----+------------+
| id | vdiff_uuid |
+----+------------+
| 1 | 1 |
| 3 | 3 |
+----+------------+2 rows inset (0.00 sec)
root@mysql>select*from vdiff_table;
+----+----------+
| id | vdiff_id |
+----+----------+
| 1 | 1 |
| 2 | 1 |
+----+----------+2 rows inset (0.00 sec)
Binary Version
Version: 15.0.3 (Git revision f3899036152acc676612494938a6c1f48e3e5068 branch 'HEAD') built on Tue Apr 18 20:21:51 UTC 2023 by vitess@buildkitsandbox using go1.18.9 linux/amd64
Thanks, @austenLacy ! You're right, that should be using WHERE there instead of AND. I think this was the result of ending up with a mix of the original query and the final one -- where I realized that a LEFT JOIN was needed as you might not have have any vdiff_table records. But when switching from a WHERE with implicit INNER JOIN to the LEFT JOIN I left the final AND clause untouched.
Overview of the Issue
We noticed that when we had multiple vdiffs with different UUIDs if we deleted a vdiff by UUID using the command
it would delete all of the vdiffs instead of just the vdiff specified by the UUID.
Reproduction Steps
The show command returns zero results even though we only deleted the vdiff for a single UUID.
We believe this could be caused by the
DELETE
query run on the_vt.vdiff
and_vt.vdiff_table
tables.It uses a
DELETE FROM LEFT JOIN
but uses anAND
instead of aWHERE
clause and is likely caused by the nature of a left join which will delete the rows from the left table even if not present in the right table. This is reproducible with a trivial example in mysql.However, if I switch to use a where clause in
WHERE vd.vdiff_uuid = 2
we see it deletes the rows correctly.Binary Version
Version: 15.0.3 (Git revision f3899036152acc676612494938a6c1f48e3e5068 branch 'HEAD') built on Tue Apr 18 20:21:51 UTC 2023 by vitess@buildkitsandbox using go1.18.9 linux/amd64
Operating System and Environment details
Log Fragments
No response
The text was updated successfully, but these errors were encountered: