diff --git a/enginetest/queries/update_queries.go b/enginetest/queries/update_queries.go index 34dae84137..6bb5093ab7 100644 --- a/enginetest/queries/update_queries.go +++ b/enginetest/queries/update_queries.go @@ -692,6 +692,24 @@ t1.oid = t2.pid;`, }, }, }, + { + // https://github.com/dolthub/dolt/issues/10385 + Name: "UPDATE JOIN - tables with capitalized names", + Dialect: "mysql", + SetUpScript: []string{ + "create table Items(ItemID char(38) NOT NULL primary key, Version int)", + "insert into Items values ('1234', 1)", + "create table Items2(ItemID char(38) NOT NULL primary key, Version int)", + "insert into Items2 values ('1234', 2)", + "UPDATE Items INNER JOIN Items2 ON (Items.ItemID = Items2.ItemID) SET Items.Version = Items2.Version WHERE Items.Version != Items2.Version", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select * from Items", + Expected: []sql.Row{{"1234", 2}}, + }, + }, + }, } var SpatialUpdateTests = []WriteQueryTest{ diff --git a/sql/plan/update_join.go b/sql/plan/update_join.go index da2ec1ca03..d7b6073140 100644 --- a/sql/plan/update_join.go +++ b/sql/plan/update_join.go @@ -235,23 +235,22 @@ func SplitRowIntoTableRowMap(row sql.Row, joinSchema sql.Schema) map[string]sql. return ret } - currentTable := joinSchema[0].Source + currentTable := strings.ToLower(joinSchema[0].Source) currentRow := sql.Row{row[0]} for i := 1; i < len(joinSchema); i++ { c := joinSchema[i] - if c.Source != currentTable { + newTable := strings.ToLower(c.Source) + if newTable != currentTable { ret[currentTable] = currentRow - currentTable = c.Source + currentTable = newTable currentRow = sql.Row{row[i]} } else { - currentTable = c.Source currentRow = append(currentRow, row[i]) } } - currentTable = strings.ToLower(currentTable) ret[currentTable] = currentRow return ret diff --git a/sql/rowexec/update.go b/sql/rowexec/update.go index 0a48582453..1d037e3a17 100644 --- a/sql/rowexec/update.go +++ b/sql/rowexec/update.go @@ -232,7 +232,8 @@ func (u *updateJoinIter) Next(ctx *sql.Context) (sql.Row, error) { tableToNewRowMap := plan.SplitRowIntoTableRowMap(newJoinRow, u.joinSchema) for tableName, _ := range u.updaters { - oldTableRow := tableToOldRowMap[strings.ToLower(tableName)] + tableName = strings.ToLower(tableName) + oldTableRow := tableToOldRowMap[tableName] // Handle the case of row being ignored due to it not being valid in the join row. if isRightOrLeftJoin(u.joinNode) {