Skip to content

Commit abfa243

Browse files
committed
planner: fix typed null in outer join rewrite
1 parent ce68c53 commit abfa243

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

pkg/planner/core/casetest/rule/rule_outer_to_semi_join_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,29 @@ func TestOuterToSemiJoin(tt *testing.T) {
6262
tk.MustQuery("EXPLAIN FORMAT='plan_tree' " + sql).Check(testkit.Rows(output[i].Plan...))
6363
tk.MustQuery(sql).Check(testkit.Rows(output[i].Result...))
6464
}
65+
66+
// issue:68112
67+
tk.MustExec("drop table if exists t_outer, t_inner")
68+
tk.MustExec("create table t_outer (id int not null)")
69+
tk.MustExec(`create table t_inner (
70+
id int not null,
71+
d varchar(64) not null
72+
)`)
73+
tk.MustExec("insert into t_outer values (1), (3)")
74+
tk.MustExec("insert into t_inner values (2, 'alpha')")
75+
query := `select d
76+
from (
77+
(
78+
select t_inner.d
79+
from t_outer
80+
left join t_inner on t_outer.id = t_inner.id
81+
where t_inner.id is null
82+
)
83+
union all
84+
select 'z'
85+
) y
86+
order by d`
87+
tk.MustQuery(query).Check(testkit.Rows("<nil>", "<nil>", "z"))
6588
})
6689
}
6790

pkg/planner/core/rule/rule_outer_join_to_semi_join.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ func generateProjectForConvertAntiJoin(p *logicalop.LogicalJoin, innerSchSet *in
385385
projExprs := make([]expression.Expression, 0, len(parentNodeSchema.Columns))
386386
for _, c := range parentNodeSchema.Columns {
387387
if innerSchSet.Has(int(c.UniqueID)) {
388-
projExprs = append(projExprs, expression.NewNull())
388+
retType := c.RetType.Clone()
389+
retType.DelFlag(mysql.NotNullFlag)
390+
projExprs = append(projExprs, expression.NewNullWithFieldType(retType))
389391
} else {
390392
projExprs = append(projExprs, c.Clone())
391393
}

0 commit comments

Comments
 (0)