Skip to content

Commit

Permalink
cherry pick pingcap#19567 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
wshwsh12 authored and ti-srebot committed Aug 31, 2020
1 parent 3b13965 commit a56b6cd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
50 changes: 50 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6763,3 +6763,53 @@ func (s *testIntegrationSerialSuite) TestIssue19045(c *C) {
tk.MustExec(`insert into t(a) values('101'),('101');`)
tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011"))
}
<<<<<<< HEAD
=======

func (s *testIntegrationSerialSuite) TestIssue19116(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;")
tk.MustQuery("select collation(concat(1 collate `binary`));").Check(testkit.Rows("binary"))
tk.MustQuery("select coercibility(concat(1 collate `binary`));").Check(testkit.Rows("0"))
tk.MustQuery("select collation(concat(NULL,NULL));").Check(testkit.Rows("binary"))
tk.MustQuery("select coercibility(concat(NULL,NULL));").Check(testkit.Rows("6"))
tk.MustQuery("select collation(concat(1,1));").Check(testkit.Rows("utf8mb4_general_ci"))
tk.MustQuery("select coercibility(concat(1,1));").Check(testkit.Rows("4"))
tk.MustQuery("select collation(1);").Check(testkit.Rows("binary"))
tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5"))
tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5"))
}

func (s *testIntegrationSerialSuite) TestIssue17063(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)

tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test;`)
tk.MustExec(`drop table if exists t;`)
tk.MustExec("create table t(a char, b char) collate utf8mb4_general_ci;")
tk.MustExec(`insert into t values('a', 'b');`)
tk.MustExec(`insert into t values('a', 'B');`)
tk.MustQuery(`select * from t where if(a='x', a, b) = 'b';`).Check(testkit.Rows("a b", "a B"))
tk.MustQuery(`select collation(if(a='x', a, b)) from t;`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci"))
tk.MustQuery(`select coercibility(if(a='x', a, b)) from t;`).Check(testkit.Rows("2", "2"))
tk.MustQuery(`select collation(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci"))
tk.MustQuery(`select coercibility(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("2", "2"))
}

func (s *testIntegrationSuite) TestIssue19504(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1 (c_int int, primary key (c_int));")
tk.MustExec("insert into t1 values (1), (2), (3);")
tk.MustExec("drop table if exists t2;")
tk.MustExec("create table t2 (c_int int, primary key (c_int));")
tk.MustExec("insert into t2 values (1);")
tk.MustQuery("select (select count(c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;").
Check(testkit.Rows("1 1", "0 0", "0 0"))
}
>>>>>>> 27ea908... planner: reset not null flag when Apply convert to Join (#19567)
14 changes: 12 additions & 2 deletions planner/core/rule_decorrelate.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,19 @@ func (s *decorrelateSolver) optimize(ctx context.Context, p LogicalPlan) (Logica
outerCol.RetType = first.RetTp
outerColsInSchema = append(outerColsInSchema, outerCol)
}
newAggFuncs = append(newAggFuncs, agg.AggFuncs...)
agg.AggFuncs = newAggFuncs
apply.SetSchema(expression.MergeSchema(expression.NewSchema(outerColsInSchema...), innerPlan.Schema()))
resetNotNullFlag(apply.schema, outerPlan.Schema().Len(), apply.schema.Len())

for i, aggFunc := range agg.AggFuncs {
if idx := apply.schema.ColumnIndex(aggFunc.Args[0].(*expression.Column)); idx != -1 {
desc, err := aggregation.NewAggFuncDesc(agg.ctx, agg.AggFuncs[i].Name, []expression.Expression{apply.schema.Columns[idx]}, false)
if err != nil {
return nil, err
}
newAggFuncs = append(newAggFuncs, desc)
}
}
agg.AggFuncs = newAggFuncs
np, err := s.optimize(ctx, p)
if err != nil {
return nil, err
Expand Down

0 comments on commit a56b6cd

Please sign in to comment.