Repository: pingcap/tidb (Go)

Issue:
If fucntion can't process enum type.
## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)


drop table t;
create table t(a int,b enum("b"),c enum("c"));
insert into t values(1,1,1),(2,1,1),(1,1,1),(2,1,1);
select if(A, null,b)=1 from t;


<!-- a step by step guide for reproducing the bug. -->

### 2. What did you expect to see? (Required)
Get some result.
### 3. What did you see instead (Required)
ERROR 1105 (HY000): baseBuiltinFunc.vecEvalInt() should never be called, please contact the TiDB team for help

### 4. What is your TiDB version? (Required)
master, release-4.0, release-5.0
<!-- Paste the output of SELECT tidb_version() -->




Discussion:
## Please edit this comment or add a new comment to complete the following information

### Not a bug

1. Remove the 'type/bug' label
2. Add notes to indicate why it is not a bug

### Duplicate bug

1. Add the 'type/duplicate' label
2. Add the link to the original bug

### Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: https://github.com/pingcap/tidb/issues/20100

#### 1. Root Cause Analysis (RCA) (optional) 
<!-- Write down the reason why this bug occurs -->

#### 2. Symptom (optional)

<!-- What will the user see when this bug occurs. The error message may be in the terminal, log or monitoring -->

#### 3. All Trigger Conditions (optional)

<!-- All the user scenarios that may trigger this bug -->

#### 4. Workaround (optional)

#### 5. Affected versions

<!--
In the format of [start_version:end_version], multiple version ranges are
accepted. If the bug only affects the unreleased version, please input:
"unreleased". For example:

Notes:
  1. Do not use any white spaces in '[]'.
  2. The range in '[]' is a closed interval
  3. The version format is `v$Major.$Minor.$Patch`, the $Majoy and $Minor
     number in a version range should be the same. [v3.0.1:v3.1.2] is
     invalid because the $Minor number of the version range is different.

Example 1: [v3.0.1:v3.0.5], [v4.0.1:v4.0.5]
Example 2: unreleased
-->

#### 6. Fixed versions

<!--
The first released version that contains this fix in each minor version. If the bug's affected version has been released, the fixed version should be a detailed version number; If the bug doesn't affect any released version, the fixed version can be "master";  

Example 1: v3.0.13, v4.0.5
Example 2: master
-->



Patch:
diff --git a/expression/builtin_control.go b/expression/builtin_control.go
index 13f539648e049..9ffc4bfe718a9 100644
--- a/expression/builtin_control.go
+++ b/expression/builtin_control.go
@@ -135,10 +135,16 @@ func InferType4ControlFuncs(lexp, rexp Expression) *types.FieldType {
 	resultEvalType := resultFieldType.EvalType()
 	if resultEvalType == types.ETInt {
 		resultFieldType.Decimal = 0
+		if resultFieldType.Tp == mysql.TypeEnum || resultFieldType.Tp == mysql.TypeSet {
+			resultFieldType.Tp = mysql.TypeLonglong
+		}
 	} else if resultEvalType == types.ETString {
 		if lhs.Tp != mysql.TypeNull || rhs.Tp != mysql.TypeNull {
 			resultFieldType.Decimal = types.UnspecifiedLength
 		}
+		if resultFieldType.Tp == mysql.TypeEnum || resultFieldType.Tp == mysql.TypeSet {
+			resultFieldType.Tp = mysql.TypeVarchar
+		}
 	}
 	return resultFieldType
 }


Test patch:
diff --git a/expression/integration_test.go b/expression/integration_test.go
index d1db4e3cbbd69..a4706629660a0 100644
--- a/expression/integration_test.go
+++ b/expression/integration_test.go
@@ -9586,6 +9586,19 @@ func (s *testIntegrationSuite) TestControlFunctionWithEnumOrSet(c *C) {
 	tk.MustQuery("select elt(1,s) = 'a' from s").Check(testkit.Rows("1"))
 	tk.MustQuery("select elt(1,s) = 4 from s").Check(testkit.Rows("1"))
 	tk.MustQuery("select s from s where elt(1,s)").Check(testkit.Rows("a"))
+
+	// issue 24543
+	tk.MustExec("drop table if exists t;")
+	tk.MustExec("create table t(a int,b enum(\"b\"),c enum(\"c\"));")
+	tk.MustExec("insert into t values(1,1,1),(2,1,1),(1,1,1),(2,1,1);")
+	tk.MustQuery("select if(A, null,b)=1 from t;").Check(testkit.Rows("<nil>", "<nil>", "<nil>", "<nil>"))
+	tk.MustQuery("select if(A, null,b)='a' from t;").Check(testkit.Rows("<nil>", "<nil>", "<nil>", "<nil>"))
+
+	tk.MustExec("drop table if exists t;")
+	tk.MustExec("create table t(a int,b set(\"b\"),c set(\"c\"));")
+	tk.MustExec("insert into t values(1,1,1),(2,1,1),(1,1,1),(2,1,1);")
+	tk.MustQuery("select if(A, null,b)=1 from t;").Check(testkit.Rows("<nil>", "<nil>", "<nil>", "<nil>"))
+	tk.MustQuery("select if(A, null,b)='a' from t;").Check(testkit.Rows("<nil>", "<nil>", "<nil>", "<nil>"))
 }
 
 func (s *testIntegrationSuite) TestComplexShowVariables(c *C) {