diff --git a/enginetest/join_op_tests.go b/enginetest/join_op_tests.go index b47dbfb343..c9fab377fd 100644 --- a/enginetest/join_op_tests.go +++ b/enginetest/join_op_tests.go @@ -2363,6 +2363,30 @@ WHERE }, }, }, + { + // https://github.com/dolthub/dolt/issues/10527 + name: "join on table with dots in name", + setup: [][]string{ + { + "create table t1(id int, name varchar(100), location varchar(100));", + "create index id_name_location on t1 (id, name, location);", + "create index name_id_location on t1(name, id, location);", + "create index location_id_name on t1 (location, id, name);", + "insert into t1 values (1, 'name1', 'loc1');", + "create table `t2.with.dot`(id int, name varchar(100), country varchar(100));", + "create index id_name_country on `t2.with.dot`(id, name, country);", + "create index name_id_country on `t2.with.dot`(name, id, country);", + "create index country_id_name on `t2.with.dot`(country, id, name);", + "insert into `t2.with.dot` values (1, 'name1', 'CA');", + }, + }, + tests: []JoinOpTests{ + { + Query: "SELECT t1.id, t1.name, t1.location, `t2.with.dot`.country FROM t1 JOIN `t2.with.dot` ON t1.id = `t2.with.dot`.id WHERE t1.id = 1;", + Expected: []sql.Row{{1, "name1", "loc1", "CA"}}, + }, + }, + }, } var rangeJoinOpTests = []JoinOpTests{ diff --git a/sql/memo/rel_props.go b/sql/memo/rel_props.go index c6c18fe1e5..90933f94f9 100644 --- a/sql/memo/rel_props.go +++ b/sql/memo/rel_props.go @@ -133,8 +133,10 @@ func newRelProps(rel RelExpr) *relProps { func idxExprsColumns(idx sql.Index) []string { exprs := idx.Expressions() columns := make([]string, len(exprs)) + // prefix includes table name and '.' character + prefixLen := len(idx.Table()) + 1 for i, e := range exprs { - colName := e[strings.IndexRune(e, '.')+1:] + colName := e[prefixLen:] columns[i] = strings.ToLower(colName) } return columns @@ -229,6 +231,7 @@ func (p *relProps) populateFds() { normIdx.order = oidx.Order() } for i, c := range columns { + // TODO: This doesn't account for when the column is not found and ord is -1 ord := sch.IndexOfColName(strings.ToLower(c)) idOffset := firstCol + sql.ColumnId(ord) colId, _ := all.Next(idOffset)