Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: don't propagateColumnEQ joinCondition when nullSensitive #23989

Merged
merged 7 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions expression/constant_propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ func (s *propOuterJoinConstSolver) deriveConds(outerCol, innerCol *Column, schem
// 'expression(..., outerCol, ...)' does not reference columns outside children schemas of join node.
// Derived new expressions must be appended into join condition, not filter condition.
func (s *propOuterJoinConstSolver) propagateColumnEQ() {
if s.nullSensitive {
return
}
visited := make([]bool, 2*len(s.joinConds)+len(s.filterConds))
s.unionSet = disjointset.NewIntSet(len(s.columns))
var outerCol, innerCol *Column
Expand All @@ -553,9 +556,6 @@ func (s *propOuterJoinConstSolver) propagateColumnEQ() {
// `select *, t1.a in (select t2.b from t t2) from t t1`
// rows with t2.b is null would impact whether LeftOuterSemiJoin should output 0 or null if there
// is no row satisfying t2.b = t1.a
if s.nullSensitive {
continue
}
childCol := s.innerSchema.RetrieveColumn(innerCol)
if !mysql.HasNotNullFlag(childCol.RetType.Flag) {
notNullExpr := BuildNotNullExpr(s.ctx, childCol)
Expand Down
14 changes: 14 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9122,3 +9122,17 @@ func (s *testIntegrationSuite) TestIssue23925(c *C) {
tk.MustExec("insert into t value(1,'Bob');")
tk.MustQuery("select max(b) + 0 from t group by a;").Check(testkit.Rows("2"))
}

func (s *testIntegrationSuite) TestIssue23889(c *C) {
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists test_decimal,test_t;")
tk.MustExec("create table test_decimal(col_decimal decimal(10,0));")
tk.MustExec("insert into test_decimal values(null),(8);")
tk.MustExec("create table test_t(a int(11), b decimal(32,0));")
tk.MustExec("insert into test_t values(1,4),(2,4),(5,4),(7,4),(9,4);")

tk.MustQuery("SELECT ( test_decimal . `col_decimal` , test_decimal . `col_decimal` ) IN ( select * from test_t ) as field1 FROM test_decimal;").Check(
testkit.Rows("<nil>", "0"))
}