planner: correctly handle expression.ScalarFunction in the buildSemiJoinForSetOperator (#40390)
close pingcap/tidb#40279
This commit is contained in:
@ -1521,6 +1521,21 @@ func TestSetOperation(t *testing.T) {
|
||||
tk.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...))
|
||||
tk.MustQuery(tt).Sort().Check(testkit.Rows(output[i].Res...))
|
||||
}
|
||||
|
||||
// from https://github.com/pingcap/tidb/issues/40279
|
||||
tk.MustExec("CREATE TABLE `issue40279` (`a` char(155) NOT NULL DEFAULT 'on1unvbxp5sko6mbetn3ku26tuiyju7w3wc0olzto9ew7gsrx',`b` mediumint(9) NOT NULL DEFAULT '2525518',PRIMARY KEY (`b`,`a`) /*T![clustered_index] CLUSTERED */);")
|
||||
tk.MustExec("insert into `issue40279` values ();")
|
||||
tk.MustQuery("( select `issue40279`.`b` as r0 , from_base64( `issue40279`.`a` ) as r1 from `issue40279` ) " +
|
||||
"except ( " +
|
||||
"select `issue40279`.`a` as r0 , elt(2, `issue40279`.`a` , `issue40279`.`a` ) as r1 from `issue40279`);").
|
||||
Check(testkit.Rows("2525518 <nil>"))
|
||||
tk.MustExec("drop table if exists t2")
|
||||
|
||||
tk.MustExec("CREATE TABLE `t2` ( `a` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")
|
||||
tk.MustExec("insert into t2 values(0xCED2)")
|
||||
result := tk.MustQuery("(select elt(2,t2.a,t2.a) from t2) except (select 0xCED2 from t2)")
|
||||
rows := result.Rows()
|
||||
require.Len(t, rows, 0)
|
||||
}
|
||||
|
||||
func TestSetOperationOnDiffColType(t *testing.T) {
|
||||
|
||||
@ -1747,7 +1747,9 @@ func (b *PlanBuilder) buildSemiJoinForSetOperator(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if leftCol.RetType.GetType() != rightCol.RetType.GetType() {
|
||||
_, leftArgIsColumn := eqCond.(*expression.ScalarFunction).GetArgs()[0].(*expression.Column)
|
||||
_, rightArgIsColumn := eqCond.(*expression.ScalarFunction).GetArgs()[1].(*expression.Column)
|
||||
if leftCol.RetType.GetType() != rightCol.RetType.GetType() || !leftArgIsColumn || !rightArgIsColumn {
|
||||
joinPlan.OtherConditions = append(joinPlan.OtherConditions, eqCond)
|
||||
} else {
|
||||
joinPlan.EqualConditions = append(joinPlan.EqualConditions, eqCond.(*expression.ScalarFunction))
|
||||
|
||||
Reference in New Issue
Block a user