Skip to content

Commit

Permalink
planner: correctly handle expression.ScalarFunction in the buildSemiJ…
Browse files Browse the repository at this point in the history
…oinForSetOperator (#40390) (#40539)

close #40279
  • Loading branch information
ti-chi-bot authored Aug 17, 2023
1 parent 7c1e445 commit 046daf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,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) {
Expand Down
4 changes: 3 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,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))
Expand Down

0 comments on commit 046daf1

Please sign in to comment.