Skip to content

Commit

Permalink
[release-19.0] Fix Join Predicate Cleanup Bug in Route Merging (#16386)…
Browse files Browse the repository at this point in the history
… (#16389)

Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Co-authored-by: Andres Taylor <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent bf16935 commit 25601df
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
15 changes: 15 additions & 0 deletions go/test/endtoend/vtgate/queries/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ func TestInvalidDateTimeTimestampVals(t *testing.T) {
require.Error(t, err)
}

func TestJoinWithThreeTables(t *testing.T) {
version, err := cluster.GetMajorVersion("vtgate")
require.NoError(t, err)
if version != 19 {
t.Skip("cannot run upgrade/downgrade test")
}

mcmp, closer := start(t)
defer closer()

mcmp.Exec("insert into t1(id1, id2) values (0,0), (1,1), (2,2)")
mcmp.Exec("insert into tbl(id, unq_col, nonunq_col) values (0,0,0), (1,1,1), (2,2,1)")
mcmp.Exec("select 42 from t1 u1, t1 u2, tbl u3 where u1.id1 = u2.id1 and u1.id1 = u3.id and (u1.id2 or u2.id2 or u3.unq_col)")
}

// TestIntervalWithMathFunctions tests that the Interval keyword can be used with math functions.
func TestIntervalWithMathFunctions(t *testing.T) {
mcmp, closer := start(t)
Expand Down
8 changes: 8 additions & 0 deletions go/test/endtoend/vtgate/queries/misc/vschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
"name": "hash"
}
]
},
"tbl": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
}
}
}
4 changes: 3 additions & 1 deletion go/vt/vtgate/planbuilder/operators/SQL_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ func (qb *queryBuilder) joinInnerWith(other *queryBuilder, onCondition sqlparser
sel.Where = &sqlparser.Where{Type: sqlparser.WhereClause, Expr: predicate}
}

qb.addPredicate(onCondition)
for _, pred := range sqlparser.SplitAndExpression(nil, onCondition) {
qb.addPredicate(pred)
}
}

func (qb *queryBuilder) joinOuterWith(other *queryBuilder, onCondition sqlparser.Expr) {
Expand Down
24 changes: 24 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/from_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,30 @@
]
}
},
{
"comment": "three table join with join predicate touching all tables",
"query": "select 42 from user u join user_extra ue on u.id = ue.user_id join music m on m.user_id = u.id where u.foo or m.foo or ue.foo",
"plan": {
"QueryType": "SELECT",
"Original": "select 42 from user u join user_extra ue on u.id = ue.user_id join music m on m.user_id = u.id where u.foo or m.foo or ue.foo",
"Instructions": {
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select 42 from `user` as u, user_extra as ue, music as m where 1 != 1",
"Query": "select 42 from `user` as u, user_extra as ue, music as m where u.id = ue.user_id and m.user_id = u.id and (u.foo or m.foo or ue.foo)",
"Table": "`user`, music, user_extra"
},
"TablesUsed": [
"user.music",
"user.user",
"user.user_extra"
]
}
},
{
"comment": "Left join, multi-chunk",
"query": "select u.col from user u left join unsharded m on u.a = m.b",
Expand Down

0 comments on commit 25601df

Please sign in to comment.