Skip to content

Commit

Permalink
Cherry-pick 3cb61cd with conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vitess-bot[bot] committed Jul 15, 2024
1 parent bf16935 commit 60394bd
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
49 changes: 49 additions & 0 deletions go/test/endtoend/vtgate/vitess_tester/join/join.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
CREATE TABLE `t1`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE InnoDB,
CHARSET utf8mb4,
COLLATE utf8mb4_unicode_ci;

CREATE TABLE `t2`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`t1_id` int unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE InnoDB,
CHARSET utf8mb4,
COLLATE utf8mb4_unicode_ci;

CREATE TABLE `t3`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE InnoDB,
CHARSET utf8mb4,
COLLATE utf8mb4_unicode_ci;

insert into t1 (id, name)
values (1, 'A'),
(2, 'B'),
(3, 'C'),
(4, 'D');

insert into t2 (id, t1_id)
values (1, 1),
(2, 2),
(3, 3);

insert into t3 (id, name)
values (1, 'A'),
(2, 'B'),
(3, 'B'),
(4, 'B'),
(5, 'B');

-- wait_authoritative t1
-- wait_authoritative t2
-- wait_authoritative t3
select 42 from t1 join t2 on t1.id = t2.t1_id join t3 on t1.id = t3.id where t1.name or t2.id or t3.name;
38 changes: 38 additions & 0 deletions go/test/endtoend/vtgate/vitess_tester/join/vschema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"keyspaces": {
"joinks": {
"sharded": true,
"vindexes": {
"hash": {
"type": "hash"
}
},
"tables": {
"t1": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
},
"t2": {
"column_vindexes": [
{
"column": "t1_id",
"name": "hash"
}
]
},
"t3": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
}
}
}
}
}
23 changes: 23 additions & 0 deletions go/vt/vtgate/planbuilder/operators/SQL_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,30 @@ func (qb *queryBuilder) joinInnerWith(other *queryBuilder, onCondition sqlparser
if sel.Where != nil {
predicate = sel.Where.Expr
}
<<<<<<< HEAD

Check failure on line 214 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected <<, expected }

Check failure on line 214 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected <<, expected }
if otherSel.Where != nil {
=======

qb.mergeWhereClauses(stmt, otherStmt)

var newFromClause []sqlparser.TableExpr
switch joinType {

Check failure on line 221 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: non-declaration statement outside function body

Check failure on line 221 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: non-declaration statement outside function body
case sqlparser.NormalJoinType:
newFromClause = append(stmt.GetFrom(), otherStmt.GetFrom()...)
for _, pred := range sqlparser.SplitAndExpression(nil, onCondition) {
qb.addPredicate(pred)
}
default:
newFromClause = []sqlparser.TableExpr{buildJoin(stmt, otherStmt, onCondition, joinType)}
}

stmt.SetFrom(newFromClause)
}

func (qb *queryBuilder) mergeWhereClauses(stmt, otherStmt FromStatement) {
predicate := stmt.GetWherePredicate()
if otherPredicate := otherStmt.GetWherePredicate(); otherPredicate != nil {
>>>>>>> 3cb61cd613 (Fix Join Predicate Cleanup Bug in Route Merging (#16386))

Check failure on line 237 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected >>, expected }

Check failure on line 237 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

invalid character U+0023 '#'

Check failure on line 237 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected >>, expected }

Check failure on line 237 in go/vt/vtgate/planbuilder/operators/SQL_builder.go

View workflow job for this annotation

GitHub Actions / Code Coverage

invalid character U+0023 '#'
predExprs := sqlparser.SplitAndExpression(nil, predicate)
otherExprs := sqlparser.SplitAndExpression(nil, otherSel.Where.Expr)
predicate = qb.ctx.SemTable.AndExpressions(append(predExprs, otherExprs...)...)
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 @@ -1783,6 +1783,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": "join of normal table with information_schema",
"query": "select unsharded.foo from unsharded join information_schema.CHARACTER_SETS",
Expand Down

0 comments on commit 60394bd

Please sign in to comment.