Skip to content

Commit

Permalink
planner: keep the original join schema in predicate pushdown
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka committed May 25, 2021
1 parent ad72d38 commit 831ad63
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/explaintest/r/subquery.result
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ HashJoin 7992.00 root inner join, equal:[eq(test.t.b, test.t.b) eq(test.t.c, te
└─TableReader(Probe) 9970.03 root data:Selection
└─Selection 9970.03 cop[tikv] not(isnull(test.t.a)), not(isnull(test.t.b)), not(isnull(test.t.c))
└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
drop table if exists t1, t2;
create table t1(a int(11));
create table t2(a decimal(40,20) unsigned, b decimal(40,20));
select count(*) as x from t1 group by a having x not in (select a from t2 where x = t2.b);
x
5 changes: 5 additions & 0 deletions cmd/explaintest/t/subquery.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ explain format = 'brief' select t.c in (select count(*) from t s use index(idx),
drop table if exists t;
create table t(a int, b int, c int);
explain format = 'brief' select a from t t1 where t1.a = (select max(t2.a) from t t2 where t1.b=t2.b and t1.c=t2.b);

drop table if exists t1, t2;
create table t1(a int(11));
create table t2(a decimal(40,20) unsigned, b decimal(40,20));
select count(*) as x from t1 group by a having x not in (select a from t2 where x = t2.b);
9 changes: 9 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3429,6 +3429,15 @@ func (s *testIntegrationSuite) TestIssue22850(c *C) {
tk.MustQuery("SELECT @v:=(SELECT 1 FROM t1 t2 LEFT JOIN t1 ON t1.a GROUP BY t1.a) FROM t1").Check(testkit.Rows()) // work fine
}

func (s *testIntegrationSuite) TestJoinSchemaChange(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1(a int(11))")
tk.MustExec("create table t2(a decimal(40,20) unsigned, b decimal(40,20))")
tk.MustQuery("select count(*) as x from t1 group by a having x not in (select a from t2 where x = t2.b)").Check(testkit.Rows())
}

// #22949: test HexLiteral Used in GetVar expr
func (s *testIntegrationSuite) TestGetVarExprWithHexLiteral(c *C) {
tk := testkit.NewTestKit(c, s.store)
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ func (s *testPlanSuite) TestUpdateEQCond(c *C) {
}{
{
sql: "select t1.a from t t1, t t2 where t1.a = t2.a+1",
best: "Join{DataScan(t1)->DataScan(t2)->Projection}(test.t.a,Column#25)->Projection",
best: "Join{DataScan(t1)->DataScan(t2)->Projection}(test.t.a,Column#25)->Projection->Projection",
},
}
ctx := context.TODO()
Expand Down
1 change: 0 additions & 1 deletion planner/core/rule_predicate_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ func (p *LogicalJoin) PredicatePushDown(predicates []expression.Expression) (ret
addSelection(p, lCh, leftRet, 0)
addSelection(p, rCh, rightRet, 1)
p.updateEQCond()
p.mergeSchema()
buildKeyInfo(p)
return ret, p.self
}
Expand Down

0 comments on commit 831ad63

Please sign in to comment.