-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Right/left/Cross/Indexed Joins and Implement Table Edit Accumulator #596
Changes from all commits
11840a3
71e2916
7d5a573
798d71f
9c86eb8
322bd67
810003a
86cb384
822267e
b722d9e
f0f9648
bf3d11c
f92cbce
b8b1337
00c0ecd
08a2262
ba837b8
0c2e19b
db56f4e
15d8a24
6bbf376
0600ab2
d4e7fea
5358690
55baecc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,6 +261,140 @@ var UpdateTests = []WriteQueryTest{ | |
sql.NewRow(1, 1, 32, 31, 32, 33, 34), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable CROSS JOIN tabletest set othertable.i2 = othertable.i2 * 10`, // cross join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, | ||
SelectQuery: "SELECT * FROM othertable order by i2", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow("third", 10), | ||
sql.NewRow("second", 20), | ||
sql.NewRow("first", 30), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE tabletest cross join tabletest as t2 set tabletest.i = tabletest.i * 10`, // cross join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, | ||
SelectQuery: "SELECT * FROM tabletest order by i", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(10, "first row"), | ||
sql.NewRow(20, "second row"), | ||
sql.NewRow(30, "third row"), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable, tabletest set tabletest.i = tabletest.i * 10`, // cross join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, | ||
SelectQuery: "SELECT * FROM tabletest order by i", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(10, "first row"), | ||
sql.NewRow(20, "second row"), | ||
sql.NewRow(30, "third row"), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 INNER JOIN two_pk a1 on one_pk.pk = two_pk.pk2 SET two_pk.c1 = two_pk.c1 + 1`, // cross join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, | ||
SelectQuery: "SELECT * FROM two_pk order by pk1 ASC, pk2 ASC;", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(0, 0, 1, 1, 2, 3, 4), | ||
sql.NewRow(0, 1, 10, 11, 12, 13, 14), | ||
sql.NewRow(1, 0, 20, 21, 22, 23, 24), | ||
sql.NewRow(1, 1, 31, 31, 32, 33, 34), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable INNER JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, // cross join | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a cross join but not phrased as on A cross join has no join condition This just reduces to a cross join because the analyzer realizes that none of the join predicates are actually join predicates to moves them to the filter. You should keep this test and add another one that is an explicit cross join There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should make sure you have tests for the implicit cross join, e.g.
|
||
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, | ||
SelectQuery: "SELECT * FROM othertable order by i2", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow("third", 1), | ||
sql.NewRow("second", 2), | ||
sql.NewRow("fourth", 3), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, // left join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, | ||
SelectQuery: "SELECT * FROM othertable order by i2", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow("fourth", 1), | ||
sql.NewRow("fourth", 2), | ||
sql.NewRow("fourth", 3), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET tabletest.s = 'fourth row', tabletest.i = tabletest.i + 1`, // left join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, | ||
SelectQuery: "SELECT * FROM tabletest order by i", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(1, "first row"), | ||
sql.NewRow(2, "second row"), | ||
sql.NewRow(4, "fourth row"), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 LEFT JOIN one_pk on othertable.i2 = one_pk.pk SET one_pk.c1 = one_pk.c1 + 1`, // left join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(3, 3)}}, | ||
SelectQuery: "SELECT * FROM one_pk order by pk", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(0, 0, 1, 2, 3, 4), | ||
sql.NewRow(1, 11, 11, 12, 13, 14), | ||
sql.NewRow(2, 21, 21, 22, 23, 24), | ||
sql.NewRow(3, 31, 31, 32, 33, 34), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 LEFT JOIN one_pk on othertable.i2 = one_pk.pk SET one_pk.c1 = one_pk.c1 + 1 where one_pk.pk > 4`, // left join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(0, 0)}}, | ||
SelectQuery: "SELECT * FROM one_pk order by pk", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(0, 0, 1, 2, 3, 4), | ||
sql.NewRow(1, 10, 11, 12, 13, 14), | ||
sql.NewRow(2, 20, 21, 22, 23, 24), | ||
sql.NewRow(3, 30, 31, 32, 33, 34), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=3 and tabletest.i=3 LEFT JOIN one_pk on othertable.i2 = 1 and one_pk.pk = 1 SET one_pk.c1 = one_pk.c1 + 1`, // left join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, | ||
SelectQuery: "SELECT * FROM one_pk order by pk", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(0, 0, 1, 2, 3, 4), | ||
sql.NewRow(1, 11, 11, 12, 13, 14), | ||
sql.NewRow(2, 20, 21, 22, 23, 24), | ||
sql.NewRow(3, 30, 31, 32, 33, 34), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable RIGHT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, // right join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, | ||
SelectQuery: "SELECT * FROM othertable order by i2", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow("third", 1), | ||
sql.NewRow("second", 2), | ||
sql.NewRow("fourth", 3), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable RIGHT JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.i2 = othertable.i2 + 1`, // right join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, | ||
SelectQuery: "SELECT * FROM othertable order by i2", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow("third", 1), | ||
sql.NewRow("second", 2), | ||
sql.NewRow("first", 4), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable LEFT JOIN tabletest on othertable.i2=tabletest.i RIGHT JOIN one_pk on othertable.i2 = 1 and one_pk.pk = 1 SET tabletest.s = 'updated';`, // right join | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, | ||
SelectQuery: "SELECT * FROM tabletest order by i", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(1, "updated"), | ||
sql.NewRow(2, "second row"), | ||
sql.NewRow(3, "third row"), | ||
}, | ||
}, | ||
} | ||
|
||
// These tests return the correct select query answer but the wrong write result. | ||
|
@@ -276,17 +410,6 @@ var SkippedUpdateTests = []WriteQueryTest{ | |
sql.NewRow(1, 1, 32, 31, 32, 33, 34), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 INNER JOIN two_pk a1 on one_pk.pk = two_pk.pk2 SET two_pk.c1 = two_pk.c1 + 1`, | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(2, 2)}}, | ||
SelectQuery: "SELECT * FROM two_pk;", | ||
ExpectedSelect: []sql.Row{ | ||
sql.NewRow(0, 0, 1, 1, 2, 3, 4), | ||
sql.NewRow(0, 1, 10, 11, 12, 13, 14), | ||
sql.NewRow(1, 0, 20, 21, 22, 23, 24), | ||
sql.NewRow(1, 1, 31, 31, 32, 33, 34), | ||
}, | ||
}, | ||
{ | ||
WriteQuery: `UPDATE othertable INNER JOIN tabletest on othertable.i2=3 and tabletest.i=3 SET othertable.s2 = 'fourth'`, | ||
ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}}, | ||
|
@@ -371,11 +494,7 @@ var GenericUpdateErrorTests = []GenericErrorQueryTest{ | |
|
||
var UpdateErrorTests = []QueryErrorTest{ | ||
{ | ||
Query: `UPDATE one_pk INNER JOIN two_pk on one_pk.pk = two_pk.pk1 INNER JOIN two_pk a1 on one_pk.pk = two_pk.pk2 SET two_pk.c1 = two_pk.c1 + 1`, | ||
ExpectedErr: sql.ErrUnsupportedFeature, | ||
}, | ||
{ | ||
Query: `UPDATE othertable INNER JOIN tabletest on othertable.i2=3 and tabletest.s=3 SET othertable.s2 = 'fourth'`, | ||
Query: `UPDATE keyless INNER JOIN one_pk on keyless.c0 = one_pk.pk SET keyless.c0 = keyless.c0 + 1`, | ||
ExpectedErr: sql.ErrUnsupportedFeature, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not verifying these query results by hand, make sure you have (or tested them on mysql)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a cross join (a cross join has no join condition)(