Repository: pingcap/tidb (Go)

Issue:
Show the casted type of `cast` in `explain`/`explain analyze` result in cop task.
## Feature Request

**Describe the feature you'd like:**
Show the casted type of `cast` in explain result.

This is an explain result:
```sql
mysql> explain select count(*) from t group by microsecond(a);
+---------------------------+----------+--------------+---------------+----------------------------------------------------------------+
| id                        | estRows  | task         | access object | operator info                                                  |
+---------------------------+----------+--------------+---------------+----------------------------------------------------------------+
| HashAgg_9                 | 8000.00  | root         |               | group by:Column#7, funcs:count(Column#8)->Column#6             |
| └─TableReader_10          | 8000.00  | root         |               | data:HashAgg_5                                                 |
|   └─HashAgg_5             | 8000.00  | cop[tiflash] |               | group by:microsecond(cast(test.t.a)), funcs:count(1)->Column#8 |
|     └─TableFullScan_8     | 10000.00 | cop[tiflash] | table:t       | keep order:false, stats:pseudo                                 |
+---------------------------+----------+--------------+---------------+----------------------------------------------------------------+
4 rows in set (0.00 sec)
```

I want to know what type `test.t.a` is converted into from the `explain` result, like `cast(test.t.a, Duration)`.



Discussion:
/label sig-planner
/label good-first-issue
seems https://github.com/pingcap/tidb/pull/14942 has already done part of this.

```sql
create table t(a int);
alter table t set tiflash replica 1;

mysql> explain select count(*) from t group by cast(a as char);
+----------------------------+----------+--------------+---------------+---------------------------------------------+
| id                         | estRows  | task         | access object | operator info                               |
+----------------------------+----------+--------------+---------------+---------------------------------------------+
| HashAgg_7                  | 8000.00  | root         |               | group by:Column#6, funcs:count(1)->Column#3 |
| └─Projection_16            | 10000.00 | root         |               | cast(test.t.a, var_string(5))->Column#6     |
|   └─TableReader_15         | 10000.00 | root         |               | data:TableFullScan_14                       |
|     └─TableFullScan_14     | 10000.00 | cop[tiflash] | table:t       | keep order:false, stats:pseudo              |
+----------------------------+----------+--------------+---------------+---------------------------------------------+
4 rows in set (0.00 sec)

mysql> explain select /*+ agg_to_cop() */ count(*) from t group by cast(a as char);
+---------------------------+----------+--------------+---------------+----------------------------------------------------+
| id                        | estRows  | task         | access object | operator info                                      |
+---------------------------+----------+--------------+---------------+----------------------------------------------------+
| HashAgg_9                 | 8000.00  | root         |               | group by:Column#4, funcs:count(Column#5)->Column#3 |
| └─TableReader_10          | 8000.00  | root         |               | data:HashAgg_5                                     |
|   └─HashAgg_5             | 8000.00  | cop[tiflash] |               | group by:cast(test.t.a), funcs:count(1)->Column#5  |
|     └─TableFullScan_8     | 10000.00 | cop[tiflash] | table:t       | keep order:false, stats:pseudo                     |
+---------------------------+----------+--------------+---------------+----------------------------------------------------+
4 rows in set (0.00 sec)

mysql> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                            |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v4.0.0-beta.2-1941-gdad3b5e87
Edition: Community
Git Commit Hash: dad3b5e87d21caf29bd7f0c7d968cd410e7a5cdd
Git Branch: master
UTC Build Time: 2020-12-30 14:16:40
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec

```
/assign @TszKitLo40 
@LittleFall: GitHub didn't allow me to assign the following users: TszKitLo40.

Note that only [pingcap members](https://github.com/orgs/pingcap/people), repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see [the contributor guide](https://git.k8s.io/community/contributors/guide/first-contribution.md#issue-assignment-in-github)

<details>

In response to [this](https://github.com/pingcap/tidb/issues/23100#issuecomment-790566233):

>/assign @TszKitLo40 


Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>
/assign
/sig planner



Patch:
diff --git a/expression/explain.go b/expression/explain.go
index 296b1c9de28d9..c1f80571ea871 100644
--- a/expression/explain.go
+++ b/expression/explain.go
@@ -19,6 +19,7 @@ import (
 	"sort"
 	"strings"
 
+	"github.com/pingcap/parser/ast"
 	"github.com/pingcap/tidb/types"
 	"github.com/pingcap/tidb/util/chunk"
 )
@@ -31,14 +32,27 @@ func (expr *ScalarFunction) ExplainInfo() string {
 func (expr *ScalarFunction) explainInfo(normalized bool) string {
 	var buffer bytes.Buffer
 	fmt.Fprintf(&buffer, "%s(", expr.FuncName.L)
-	for i, arg := range expr.GetArgs() {
-		if normalized {
-			buffer.WriteString(arg.ExplainNormalizedInfo())
-		} else {
-			buffer.WriteString(arg.ExplainInfo())
-		}
-		if i+1 < len(expr.GetArgs()) {
+	switch expr.FuncName.L {
+	case ast.Cast:
+		for _, arg := range expr.GetArgs() {
+			if normalized {
+				buffer.WriteString(arg.ExplainNormalizedInfo())
+			} else {
+				buffer.WriteString(arg.ExplainInfo())
+			}
 			buffer.WriteString(", ")
+			buffer.WriteString(expr.RetType.String())
+		}
+	default:
+		for i, arg := range expr.GetArgs() {
+			if normalized {
+				buffer.WriteString(arg.ExplainNormalizedInfo())
+			} else {
+				buffer.WriteString(arg.ExplainInfo())
+			}
+			if i+1 < len(expr.GetArgs()) {
+				buffer.WriteString(", ")
+			}
 		}
 	}
 	buffer.WriteString(")")


Test patch:
diff --git a/cmd/ddltest/index_test.go b/cmd/ddltest/index_test.go
index 1101486de37b2..dcb2280f231e9 100644
--- a/cmd/ddltest/index_test.go
+++ b/cmd/ddltest/index_test.go
@@ -104,7 +104,7 @@ func (s *TestDDLSuite) checkDropIndex(c *C, indexInfo *model.IndexInfo) {
 	c.Assert(err, IsNil)
 	txn, err := ctx.Txn(false)
 	c.Assert(err, IsNil)
-	defer func(){
+	defer func() {
 		err := txn.Rollback()
 		c.Assert(err, IsNil)
 	}()
diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result
index 0d7bc00eccddb..b91c3f156661f 100644
--- a/cmd/explaintest/r/explain_easy.result
+++ b/cmd/explaintest/r/explain_easy.result
@@ -467,7 +467,7 @@ insert tb values ('1');
 explain format = 'brief' select * from ta where a = 1;
 id	estRows	task	access object	operator info
 TableReader	8000.00	root		data:Selection
-└─Selection	8000.00	cop[tikv]		eq(cast(test.ta.a), 1)
+└─Selection	8000.00	cop[tikv]		eq(cast(test.ta.a, double BINARY), 1)
   └─TableFullScan	10000.00	cop[tikv]	table:ta	keep order:false, stats:pseudo
 rollback;
 drop table if exists t1, t2;
@@ -507,7 +507,7 @@ StreamAgg	1.00	root		funcs:count(1)->Column#22
         ├─TableDual	8000.00	root		rows:0
         └─Projection	0.01	root		test.test01.stat_date, test.test01.show_date, test.test01.region_id
           └─TableReader	0.01	root		data:Selection
-            └─Selection	0.01	cop[tikv]		eq(test.test01.period, 1), ge(test.test01.stat_date, 20191202), ge(test.test01.stat_date, 20191202), gt(cast(test.test01.registration_num), 0), le(test.test01.stat_date, 20191202), le(test.test01.stat_date, 20191202)
+            └─Selection	0.01	cop[tikv]		eq(test.test01.period, 1), ge(test.test01.stat_date, 20191202), ge(test.test01.stat_date, 20191202), gt(cast(test.test01.registration_num, bigint(20) BINARY), 0), le(test.test01.stat_date, 20191202), le(test.test01.stat_date, 20191202)
               └─TableFullScan	10000.00	cop[tikv]	table:test01	keep order:false, stats:pseudo
 drop table if exists t;
 create table t(a int, nb int not null, nc int not null);
@@ -744,7 +744,7 @@ create table t(a int, b int);
 explain format = 'brief' select a, b from (select a, b, avg(b) over (partition by a)as avg_b from t) as tt where a > 10 and b < 10 and a > avg_b;
 id	estRows	task	access object	operator info
 Projection	2666.67	root		test.t.a, test.t.b
-└─Selection	2666.67	root		gt(cast(test.t.a), Column#5), lt(test.t.b, 10)
+└─Selection	2666.67	root		gt(cast(test.t.a, decimal(20,0) BINARY), Column#5), lt(test.t.b, 10)
   └─Window	3333.33	root		avg(cast(test.t.b, decimal(15,4) BINARY))->Column#5 over(partition by test.t.a)
     └─Sort	3333.33	root		test.t.a
       └─TableReader	3333.33	root		data:Selection
diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result
index 902834b9c3ef3..d4133abd647fc 100644
--- a/cmd/explaintest/r/select.result
+++ b/cmd/explaintest/r/select.result
@@ -398,7 +398,7 @@ drop table if exists s;
 create table s(a varchar(20), b varchar(20));
 explain format = 'brief' select a in (select a from s where s.b = t.b) from t;
 id	estRows	task	access object	operator info
-HashJoin	10000.00	root		left outer semi join, equal:[eq(Column#8, Column#9)], other cond:eq(cast(test.t.a), cast(test.s.a))
+HashJoin	10000.00	root		left outer semi join, equal:[eq(Column#8, Column#9)], other cond:eq(cast(test.t.a, double BINARY), cast(test.s.a, double BINARY))
 ├─Projection(Build)	10000.00	root		test.s.a, cast(test.s.b, double BINARY)->Column#9
 │ └─TableReader	10000.00	root		data:TableFullScan
 │   └─TableFullScan	10000.00	cop[tikv]	table:s	keep order:false, stats:pseudo
diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result
index bb6a2e6201ee0..11a84495b2b37 100644
--- a/cmd/explaintest/r/tpch.result
+++ b/cmd/explaintest/r/tpch.result
@@ -1161,7 +1161,7 @@ Sort	20000.00	root		tpch.supplier.s_name
   │   └─TableFullScan	500000.00	cop[tikv]	table:supplier	keep order:false
   └─HashAgg(Probe)	257492.04	root		group by:tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey
     └─Projection	257492.04	root		tpch.partsupp.ps_suppkey
-      └─Selection	257492.04	root		gt(cast(tpch.partsupp.ps_availqty), mul(0.5, Column#44))
+      └─Selection	257492.04	root		gt(cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY), mul(0.5, Column#44))
         └─HashAgg	321865.05	root		group by:tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_availqty)->tpch.partsupp.ps_availqty, funcs:sum(tpch.lineitem.l_quantity)->Column#44
           └─HashJoin	9711455.06	root		left outer join, equal:[eq(tpch.partsupp.ps_partkey, tpch.lineitem.l_partkey) eq(tpch.partsupp.ps_suppkey, tpch.lineitem.l_suppkey)]
             ├─IndexHashJoin(Build)	321865.05	root		inner join, inner:IndexLookUp, outer key:tpch.part.p_partkey, inner key:tpch.partsupp.ps_partkey, equal cond:eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey)
diff --git a/executor/explainfor_test.go b/executor/explainfor_test.go
index 06478ee0184a4..6589144a60669 100644
--- a/executor/explainfor_test.go
+++ b/executor/explainfor_test.go
@@ -238,7 +238,7 @@ func (s *testPrepareSerialSuite) TestExplainForConnPlanCache(c *C) {
 	explainQuery := "explain for connection " + strconv.FormatUint(tk1.Se.ShowProcess().ID, 10)
 	explainResult := testkit.Rows(
 		"TableReader_7 8000.00 root  data:Selection_6",
-		"└─Selection_6 8000.00 cop[tikv]  eq(cast(test.t.a), 1)",
+		"└─Selection_6 8000.00 cop[tikv]  eq(cast(test.t.a, double BINARY), 1)",
 		"  └─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo",
 	)
 
diff --git a/executor/testdata/executor_suite_out.json b/executor/testdata/executor_suite_out.json
index ba85bc0a8ca62..791171ddccf63 100644
--- a/executor/testdata/executor_suite_out.json
+++ b/executor/testdata/executor_suite_out.json
@@ -305,7 +305,7 @@
       {
         "SQL": "select * from t1 except select * from t3",
         "Plan": [
-          "HashJoin_7 6400.00 root  anti semi join, equal:[nulleq(test.t1.a, test.t3.a)], other cond:nulleq(cast(test.t1.b), test.t3.b)",
+          "HashJoin_7 6400.00 root  anti semi join, equal:[nulleq(test.t1.a, test.t3.a)], other cond:nulleq(cast(test.t1.b, decimal(20,0) BINARY), test.t3.b)",
           "├─TableReader_18(Build) 10000.00 root  data:TableFullScan_17",
           "│ └─TableFullScan_17 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo",
           "└─HashAgg_10(Probe) 8000.00 root  group by:test.t1.a, test.t1.b, funcs:firstrow(test.t1.a)->test.t1.a, funcs:firstrow(test.t1.b)->test.t1.b",
@@ -321,7 +321,7 @@
       {
         "SQL": "select * from t1 intersect select * from t2",
         "Plan": [
-          "HashJoin_7 6400.00 root  semi join, equal:[nulleq(test.t1.a, test.t2.a)], other cond:nulleq(cast(test.t1.b), cast(test.t2.b))",
+          "HashJoin_7 6400.00 root  semi join, equal:[nulleq(test.t1.a, test.t2.a)], other cond:nulleq(cast(test.t1.b, double BINARY), cast(test.t2.b, double BINARY))",
           "├─TableReader_18(Build) 10000.00 root  data:TableFullScan_17",
           "│ └─TableFullScan_17 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
           "└─HashAgg_10(Probe) 8000.00 root  group by:test.t1.a, test.t1.b, funcs:firstrow(test.t1.a)->test.t1.a, funcs:firstrow(test.t1.b)->test.t1.b",
@@ -365,7 +365,7 @@
       {
         "SQL": "select * from t1 union all select * from t2 except select * from t3",
         "Plan": [
-          "HashJoin_12 12800.00 root  anti semi join, equal:[nulleq(Column#10, test.t3.a)], other cond:nulleq(cast(Column#11), cast(test.t3.b))",
+          "HashJoin_12 12800.00 root  anti semi join, equal:[nulleq(Column#10, test.t3.a)], other cond:nulleq(cast(Column#11, double BINARY), cast(test.t3.b, double BINARY))",
           "├─TableReader_23(Build) 10000.00 root  data:TableFullScan_22",
           "│ └─TableFullScan_22 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo",
           "└─HashAgg_13(Probe) 16000.00 root  group by:Column#10, Column#11, funcs:firstrow(Column#10)->Column#10, funcs:firstrow(Column#11)->Column#11",
@@ -389,7 +389,7 @@
           "HashJoin_12 5120.00 root  semi join, equal:[nulleq(test.t1.a, test.t1.a) nulleq(test.t1.b, test.t1.b)]",
           "├─TableReader_27(Build) 10000.00 root  data:TableFullScan_26",
           "│ └─TableFullScan_26 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
-          "└─HashJoin_14(Probe) 6400.00 root  semi join, equal:[nulleq(test.t1.a, test.t2.a)], other cond:nulleq(cast(test.t1.b), cast(test.t2.b))",
+          "└─HashJoin_14(Probe) 6400.00 root  semi join, equal:[nulleq(test.t1.a, test.t2.a)], other cond:nulleq(cast(test.t1.b, double BINARY), cast(test.t2.b, double BINARY))",
           "  ├─TableReader_24(Build) 10000.00 root  data:TableFullScan_23",
           "  │ └─TableFullScan_23 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
           "  └─HashAgg_17(Probe) 8000.00 root  group by:test.t1.a, test.t1.b, funcs:firstrow(test.t1.a)->test.t1.a, funcs:firstrow(test.t1.b)->test.t1.b",
@@ -409,7 +409,7 @@
           "├─Projection_13 10000.00 root  test.t1.a, cast(test.t1.b, varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin)->Column#11",
           "│ └─TableReader_15 10000.00 root  data:TableFullScan_14",
           "│   └─TableFullScan_14 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
-          "└─HashJoin_17 6400.00 root  semi join, equal:[nulleq(test.t2.a, test.t3.a)], other cond:nulleq(cast(test.t2.b), cast(test.t3.b))",
+          "└─HashJoin_17 6400.00 root  semi join, equal:[nulleq(test.t2.a, test.t3.a)], other cond:nulleq(cast(test.t2.b, double BINARY), cast(test.t3.b, double BINARY))",
           "  ├─TableReader_27(Build) 10000.00 root  data:TableFullScan_26",
           "  │ └─TableFullScan_26 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo",
           "  └─HashAgg_20(Probe) 8000.00 root  group by:test.t2.a, test.t2.b, funcs:firstrow(test.t2.a)->test.t2.a, funcs:firstrow(test.t2.b)->test.t2.b",
@@ -427,8 +427,8 @@
       {
         "SQL": "select * from t1 except select * from t2 intersect select * from t3",
         "Plan": [
-          "HashJoin_11 6400.00 root  anti semi join, equal:[nulleq(test.t1.a, test.t2.a)], other cond:nulleq(cast(test.t1.b), cast(test.t2.b))",
-          "├─HashJoin_20(Build) 6400.00 root  semi join, equal:[nulleq(test.t2.a, test.t3.a)], other cond:nulleq(cast(test.t2.b), cast(test.t3.b))",
+          "HashJoin_11 6400.00 root  anti semi join, equal:[nulleq(test.t1.a, test.t2.a)], other cond:nulleq(cast(test.t1.b, double BINARY), cast(test.t2.b, double BINARY))",
+          "├─HashJoin_20(Build) 6400.00 root  semi join, equal:[nulleq(test.t2.a, test.t3.a)], other cond:nulleq(cast(test.t2.b, double BINARY), cast(test.t3.b, double BINARY))",
           "│ ├─TableReader_31(Build) 10000.00 root  data:TableFullScan_30",
           "│ │ └─TableFullScan_30 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo",
           "│ └─HashAgg_23(Probe) 8000.00 root  group by:test.t2.a, test.t2.b, funcs:firstrow(test.t2.a)->test.t2.a, funcs:firstrow(test.t2.b)->test.t2.b",
diff --git a/executor/testdata/prepare_suite_out.json b/executor/testdata/prepare_suite_out.json
index aa1e06d2ab465..ef215f33597be 100644
--- a/executor/testdata/prepare_suite_out.json
+++ b/executor/testdata/prepare_suite_out.json
@@ -120,7 +120,7 @@
             "Plan": [
               "Projection_4 8000.00 root  test.t1.a",
               "└─IndexReader_10 8000.00 root  index:Selection_9",
-              "  └─Selection_9 8000.00 cop[tikv]  eq(cast(test.t1.b), 0)",
+              "  └─Selection_9 8000.00 cop[tikv]  eq(cast(test.t1.b, double BINARY), 0)",
               "    └─IndexFullScan_8 10000.00 cop[tikv] table:t1, index:b(b, a) keep order:false, stats:pseudo"
             ],
             "LastPlanUseCache": "0",
@@ -188,10 +188,10 @@
             "Plan": [
               "HashJoin_38 63744383.74 root  inner join, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)]",
               "├─TableReader_59(Build) 7984.01 root  data:Selection_58",
-              "│ └─Selection_58 7984.01 cop[tikv]  eq(cast(test.t2.b), 0), not(isnull(test.t2.a)), not(isnull(test.t2.b))",
+              "│ └─Selection_58 7984.01 cop[tikv]  eq(cast(test.t2.b, double BINARY), 0), not(isnull(test.t2.a)), not(isnull(test.t2.b))",
               "│   └─TableFullScan_57 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
               "└─TableReader_52(Probe) 7984.01 root  data:Selection_51",
-              "  └─Selection_51 7984.01 cop[tikv]  eq(cast(test.t1.b), 0), not(isnull(test.t1.a)), not(isnull(test.t1.b))",
+              "  └─Selection_51 7984.01 cop[tikv]  eq(cast(test.t1.b, double BINARY), 0), not(isnull(test.t1.a)), not(isnull(test.t1.b))",
               "    └─TableFullScan_50 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
             ],
             "LastPlanUseCache": "0",
diff --git a/expression/integration_test.go b/expression/integration_test.go
index 9ab916720810f..f16efa2c1095e 100644
--- a/expression/integration_test.go
+++ b/expression/integration_test.go
@@ -5451,7 +5451,7 @@ func (s *testIntegrationSuite) TestExprPushdownBlacklist(c *C) {
 	rows := tk.MustQuery("explain format = 'brief' select * from test.t where b > date'1988-01-01' and b < date'1994-01-01' " +
 		"and cast(a as decimal(10,2)) > 10.10 and date_format(b,'%m') = '11'").Rows()
 	c.Assert(fmt.Sprintf("%v", rows[0][4]), Equals, "lt(test.t.b, 1994-01-01)")
-	c.Assert(fmt.Sprintf("%v", rows[1][4]), Equals, "gt(cast(test.t.a), 10.10)")
+	c.Assert(fmt.Sprintf("%v", rows[1][4]), Equals, "gt(cast(test.t.a, decimal(10,2) BINARY), 10.10)")
 	c.Assert(fmt.Sprintf("%v", rows[3][4]), Equals, "eq(date_format(test.t.b, \"%m\"), \"11\"), gt(test.t.b, 1988-01-01)")
 
 	tk.MustExec("set @@session.tidb_isolation_read_engines = 'tikv'")
@@ -5459,7 +5459,7 @@ func (s *testIntegrationSuite) TestExprPushdownBlacklist(c *C) {
 		"and cast(a as decimal(10,2)) > 10.10 and date_format(b,'%m') = '11'").Rows()
 	c.Assert(fmt.Sprintf("%v", rows[0][4]), Equals, "lt(test.t.b, 1994-01-01)")
 	c.Assert(fmt.Sprintf("%v", rows[1][4]), Equals, "eq(date_format(test.t.b, \"%m\"), \"11\")")
-	c.Assert(fmt.Sprintf("%v", rows[3][4]), Equals, "gt(cast(test.t.a), 10.10), gt(test.t.b, 1988-01-01)")
+	c.Assert(fmt.Sprintf("%v", rows[3][4]), Equals, "gt(cast(test.t.a, decimal(10,2) BINARY), 10.10), gt(test.t.b, 1988-01-01)")
 
 	tk.MustExec("delete from mysql.expr_pushdown_blacklist where name = '<' and store_type = 'tikv,tiflash,tidb' and reason = 'for test'")
 	tk.MustExec("delete from mysql.expr_pushdown_blacklist where name = 'date_format' and store_type = 'tikv' and reason = 'for test'")
diff --git a/planner/cascades/testdata/integration_suite_out.json b/planner/cascades/testdata/integration_suite_out.json
index 3de732f419ed1..f7ac52e543f2b 100644
--- a/planner/cascades/testdata/integration_suite_out.json
+++ b/planner/cascades/testdata/integration_suite_out.json
@@ -51,7 +51,7 @@
         "Plan": [
           "Projection_13 8000.00 root  test.t.a",
           "└─TableReader_14 8000.00 root  data:Selection_15",
-          "  └─Selection_15 8000.00 cop[tikv]  gt(cast(test.t.b), 4)",
+          "  └─Selection_15 8000.00 cop[tikv]  gt(cast(test.t.b, decimal(32,0) BINARY), 4)",
           "    └─TableFullScan_16 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
         ],
         "Result": [
@@ -393,7 +393,7 @@
         "Plan": [
           "HashAgg_18 1.00 root  funcs:sum(Column#4)->Column#3",
           "└─TableReader_19 1.00 root  data:HashAgg_20",
-          "  └─HashAgg_20 1.00 cop[tikv]  funcs:sum(cast(test.t.b))->Column#4",
+          "  └─HashAgg_20 1.00 cop[tikv]  funcs:sum(cast(test.t.b, decimal(33,1) BINARY))->Column#4",
           "    └─TableRangeScan_17 250.00 cop[tikv] table:t range:(0,1000], keep order:false, stats:pseudo"
         ],
         "Result": [
@@ -453,7 +453,7 @@
           "└─Projection_15 8000.00 root  if(isnull(test.t.b), 0, 1)->Column#3, cast(test.t.b, decimal(32,0) BINARY)->Column#4, cast(test.t.b, decimal(15,4) BINARY)->Column#5, test.t.b, cast(test.t.b, int(11))->Column#6, cast(test.t.b, int(11))->Column#7, ifnull(cast(test.t.b, bigint(21) UNSIGNED BINARY), 18446744073709551615)->Column#8, ifnull(cast(test.t.b, bigint(21) UNSIGNED BINARY), 0)->Column#9, ifnull(cast(test.t.b, bigint(21) UNSIGNED BINARY), 0)->Column#10, cast(test.t.b, decimal(32,0) BINARY)->Column#4, if(isnull(test.t.b), 0, 1)->Column#3",
           "  └─Sort_22 8000.00 root  test.t.b",
           "    └─TableReader_19 8000.00 root  data:Selection_20",
-          "      └─Selection_20 8000.00 cop[tikv]  ge(cast(test.t.b), 0), ge(if(isnull(test.t.b), 0, 1), 0)",
+          "      └─Selection_20 8000.00 cop[tikv]  ge(cast(test.t.b, decimal(32,0) BINARY), 0), ge(if(isnull(test.t.b), 0, 1), 0)",
           "        └─TableFullScan_21 10000.00 cop[tikv] table:t keep order:false, stats:pseudo"
         ],
         "Result": [
diff --git a/planner/cascades/testdata/transformation_rules_suite_out.json b/planner/cascades/testdata/transformation_rules_suite_out.json
index 22e877c07c181..6dc0ca30024ac 100644
--- a/planner/cascades/testdata/transformation_rules_suite_out.json
+++ b/planner/cascades/testdata/transformation_rules_suite_out.json
@@ -352,7 +352,7 @@
           "Group#0 Schema:[test.t.b,Column#13]",
           "    Projection_3 input:[Group#1], test.t.b, Column#13",
           "Group#1 Schema:[Column#13,test.t.b]",
-          "    Aggregation_2 input:[Group#2], group by:plus(sin(cast(test.t.b)), sin(cast(test.t.c))), test.t.b, funcs:sum(test.t.a), firstrow(test.t.b)",
+          "    Aggregation_2 input:[Group#2], group by:plus(sin(cast(test.t.b, double BINARY)), sin(cast(test.t.c, double BINARY))), test.t.b, funcs:sum(test.t.a), firstrow(test.t.b)",
           "Group#2 Schema:[test.t.a,test.t.b,test.t.c], UniqueKey:[test.t.a]",
           "    TiKVSingleGather_5 input:[Group#3], table:t",
           "Group#3 Schema:[test.t.a,test.t.b,test.t.c], UniqueKey:[test.t.a]",
@@ -1011,53 +1011,53 @@
           "Group#4 Schema:[test.t.a]",
           "    Projection_2 input:[Group#5], test.t.a",
           "Group#5 Schema:[test.t.a]",
-          "    TopN_15 input:[Group#6], cast(test.t.a), offset:0, count:2",
-          "    TopN_15 input:[Group#7], cast(test.t.a), offset:0, count:2",
-          "    TopN_15 input:[Group#8], cast(test.t.a), offset:0, count:2",
-          "    TopN_15 input:[Group#9], cast(test.t.a), offset:0, count:2",
-          "    TopN_15 input:[Group#10], cast(test.t.a), offset:0, count:2",
-          "    TopN_15 input:[Group#11], cast(test.t.a), offset:0, count:2",
-          "    TopN_15 input:[Group#12], cast(test.t.a), offset:0, count:2",
+          "    TopN_15 input:[Group#6], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
+          "    TopN_15 input:[Group#7], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
+          "    TopN_15 input:[Group#8], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
+          "    TopN_15 input:[Group#9], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
+          "    TopN_15 input:[Group#10], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
+          "    TopN_15 input:[Group#11], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
+          "    TopN_15 input:[Group#12], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#6 Schema:[test.t.a]",
           "    TiKVSingleGather_21 input:[Group#13], table:t, index:c_d_e",
           "Group#13 Schema:[test.t.a]",
-          "    TopN_38 input:[Group#14], cast(test.t.a), offset:0, count:2",
+          "    TopN_38 input:[Group#14], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#14 Schema:[test.t.a]",
           "    IndexScan_20 table:t, index:c, d, e",
           "Group#7 Schema:[test.t.a]",
           "    TiKVSingleGather_23 input:[Group#15], table:t, index:f",
           "Group#15 Schema:[test.t.a]",
-          "    TopN_37 input:[Group#16], cast(test.t.a), offset:0, count:2",
+          "    TopN_37 input:[Group#16], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#16 Schema:[test.t.a]",
           "    IndexScan_22 table:t, index:f",
           "Group#8 Schema:[test.t.a]",
           "    TiKVSingleGather_25 input:[Group#17], table:t, index:g",
           "Group#17 Schema:[test.t.a]",
-          "    TopN_36 input:[Group#18], cast(test.t.a), offset:0, count:2",
+          "    TopN_36 input:[Group#18], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#18 Schema:[test.t.a]",
           "    IndexScan_24 table:t, index:g",
           "Group#9 Schema:[test.t.a]",
           "    TiKVSingleGather_27 input:[Group#19], table:t, index:f_g",
           "Group#19 Schema:[test.t.a]",
-          "    TopN_35 input:[Group#20], cast(test.t.a), offset:0, count:2",
+          "    TopN_35 input:[Group#20], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#20 Schema:[test.t.a]",
           "    IndexScan_26 table:t, index:f, g",
           "Group#10 Schema:[test.t.a]",
           "    TiKVSingleGather_29 input:[Group#21], table:t, index:c_d_e_str",
           "Group#21 Schema:[test.t.a]",
-          "    TopN_34 input:[Group#22], cast(test.t.a), offset:0, count:2",
+          "    TopN_34 input:[Group#22], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#22 Schema:[test.t.a]",
           "    IndexScan_28 table:t, index:c_str, d_str, e_str",
           "Group#11 Schema:[test.t.a]",
           "    TiKVSingleGather_31 input:[Group#23], table:t, index:e_d_c_str_prefix",
           "Group#23 Schema:[test.t.a]",
-          "    TopN_33 input:[Group#24], cast(test.t.a), offset:0, count:2",
+          "    TopN_33 input:[Group#24], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#24 Schema:[test.t.a]",
           "    IndexScan_30 table:t, index:e_str, d_str, c_str",
           "Group#12 Schema:[test.t.a]",
           "    TiKVSingleGather_19 input:[Group#25], table:t",
           "Group#25 Schema:[test.t.a]",
-          "    TopN_32 input:[Group#26], cast(test.t.a), offset:0, count:2",
+          "    TopN_32 input:[Group#26], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:2",
           "Group#26 Schema:[test.t.a]",
           "    TableScan_18 table:t, pk col:test.t.a",
           "Group#3 Schema:[Column#26]",
@@ -1065,7 +1065,7 @@
           "Group#27 Schema:[Column#25]",
           "    Projection_6 input:[Group#28], Column#25",
           "Group#28 Schema:[Column#25]",
-          "    TopN_17 input:[Group#29], cast(Column#25), offset:0, count:2",
+          "    TopN_17 input:[Group#29], cast(Column#25, decimal(65,0) BINARY), offset:0, count:2",
           "Group#29 Schema:[Column#25]",
           "    Aggregation_5 input:[Group#30], group by:test.t.b, funcs:sum(test.t.a)",
           "Group#30 Schema:[test.t.a,test.t.b]",
@@ -1088,53 +1088,53 @@
           "Group#4 Schema:[test.t.a]",
           "    Projection_2 input:[Group#5], test.t.a",
           "Group#5 Schema:[test.t.a]",
-          "    TopN_15 input:[Group#6], cast(test.t.a), offset:0, count:3",
-          "    TopN_15 input:[Group#7], cast(test.t.a), offset:0, count:3",
-          "    TopN_15 input:[Group#8], cast(test.t.a), offset:0, count:3",
-          "    TopN_15 input:[Group#9], cast(test.t.a), offset:0, count:3",
-          "    TopN_15 input:[Group#10], cast(test.t.a), offset:0, count:3",
-          "    TopN_15 input:[Group#11], cast(test.t.a), offset:0, count:3",
-          "    TopN_15 input:[Group#12], cast(test.t.a), offset:0, count:3",
+          "    TopN_15 input:[Group#6], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
+          "    TopN_15 input:[Group#7], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
+          "    TopN_15 input:[Group#8], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
+          "    TopN_15 input:[Group#9], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
+          "    TopN_15 input:[Group#10], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
+          "    TopN_15 input:[Group#11], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
+          "    TopN_15 input:[Group#12], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#6 Schema:[test.t.a]",
           "    TiKVSingleGather_21 input:[Group#13], table:t, index:c_d_e",
           "Group#13 Schema:[test.t.a]",
-          "    TopN_38 input:[Group#14], cast(test.t.a), offset:0, count:3",
+          "    TopN_38 input:[Group#14], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#14 Schema:[test.t.a]",
           "    IndexScan_20 table:t, index:c, d, e",
           "Group#7 Schema:[test.t.a]",
           "    TiKVSingleGather_23 input:[Group#15], table:t, index:f",
           "Group#15 Schema:[test.t.a]",
-          "    TopN_37 input:[Group#16], cast(test.t.a), offset:0, count:3",
+          "    TopN_37 input:[Group#16], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#16 Schema:[test.t.a]",
           "    IndexScan_22 table:t, index:f",
           "Group#8 Schema:[test.t.a]",
           "    TiKVSingleGather_25 input:[Group#17], table:t, index:g",
           "Group#17 Schema:[test.t.a]",
-          "    TopN_36 input:[Group#18], cast(test.t.a), offset:0, count:3",
+          "    TopN_36 input:[Group#18], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#18 Schema:[test.t.a]",
           "    IndexScan_24 table:t, index:g",
           "Group#9 Schema:[test.t.a]",
           "    TiKVSingleGather_27 input:[Group#19], table:t, index:f_g",
           "Group#19 Schema:[test.t.a]",
-          "    TopN_35 input:[Group#20], cast(test.t.a), offset:0, count:3",
+          "    TopN_35 input:[Group#20], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#20 Schema:[test.t.a]",
           "    IndexScan_26 table:t, index:f, g",
           "Group#10 Schema:[test.t.a]",
           "    TiKVSingleGather_29 input:[Group#21], table:t, index:c_d_e_str",
           "Group#21 Schema:[test.t.a]",
-          "    TopN_34 input:[Group#22], cast(test.t.a), offset:0, count:3",
+          "    TopN_34 input:[Group#22], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#22 Schema:[test.t.a]",
           "    IndexScan_28 table:t, index:c_str, d_str, e_str",
           "Group#11 Schema:[test.t.a]",
           "    TiKVSingleGather_31 input:[Group#23], table:t, index:e_d_c_str_prefix",
           "Group#23 Schema:[test.t.a]",
-          "    TopN_33 input:[Group#24], cast(test.t.a), offset:0, count:3",
+          "    TopN_33 input:[Group#24], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#24 Schema:[test.t.a]",
           "    IndexScan_30 table:t, index:e_str, d_str, c_str",
           "Group#12 Schema:[test.t.a]",
           "    TiKVSingleGather_19 input:[Group#25], table:t",
           "Group#25 Schema:[test.t.a]",
-          "    TopN_32 input:[Group#26], cast(test.t.a), offset:0, count:3",
+          "    TopN_32 input:[Group#26], cast(test.t.a, decimal(65,0) BINARY), offset:0, count:3",
           "Group#26 Schema:[test.t.a]",
           "    TableScan_18 table:t, pk col:test.t.a",
           "Group#3 Schema:[Column#26]",
@@ -1142,7 +1142,7 @@
           "Group#27 Schema:[Column#25]",
           "    Projection_6 input:[Group#28], Column#25",
           "Group#28 Schema:[Column#25]",
-          "    TopN_17 input:[Group#29], cast(Column#25), offset:0, count:3",
+          "    TopN_17 input:[Group#29], cast(Column#25, decimal(65,0) BINARY), offset:0, count:3",
           "Group#29 Schema:[Column#25]",
           "    Aggregation_5 input:[Group#30], group by:test.t.b, funcs:sum(test.t.a)",
           "Group#30 Schema:[test.t.a,test.t.b]",
@@ -2044,7 +2044,7 @@
           "Group#0 Schema:[Column#13]",
           "    Projection_3 input:[Group#1], Column#13",
           "Group#1 Schema:[Column#13]",
-          "    Aggregation_2 input:[Group#2], group by:concat(cast(test.t.c), cast(test.t.a)), funcs:count(case(gt(test.t.a, 10), test.t.b))",
+          "    Aggregation_2 input:[Group#2], group by:concat(cast(test.t.c, var_string(20)), cast(test.t.a, var_string(20))), funcs:count(case(gt(test.t.a, 10), test.t.b))",
           "Group#2 Schema:[test.t.a,test.t.b,test.t.c]",
           "    DataSource_1 table:t"
         ]
@@ -2055,7 +2055,7 @@
           "Group#0 Schema:[Column#13]",
           "    Projection_3 input:[Group#1], Column#13",
           "Group#1 Schema:[Column#13]",
-          "    Aggregation_2 input:[Group#2], group by:concat(cast(test.t.c), \"a\"), funcs:count(case(gt(test.t.a, 10), test.t.b))",
+          "    Aggregation_2 input:[Group#2], group by:concat(cast(test.t.c, var_string(20)), \"a\"), funcs:count(case(gt(test.t.a, 10), test.t.b))",
           "Group#2 Schema:[test.t.a,test.t.b,test.t.c]",
           "    DataSource_1 table:t"
         ]
@@ -2138,7 +2138,7 @@
           "Group#0 Schema:[Column#13]",
           "    Projection_3 input:[Group#1], Column#13",
           "Group#1 Schema:[Column#13]",
-          "    Aggregation_5 input:[Group#2], funcs:sum(cast(test.t.c))",
+          "    Aggregation_5 input:[Group#2], funcs:sum(cast(test.t.c, decimal(20,0) BINARY))",
           "Group#2 Schema:[test.t.a,test.t.c]",
           "    Selection_4 input:[Group#3], gt(test.t.a, 10)",
           "Group#3 Schema:[test.t.a,test.t.c]",
diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go
index e4e8d55975a6a..1ce68cc2aa797 100644
--- a/planner/core/integration_test.go
+++ b/planner/core/integration_test.go
@@ -1539,7 +1539,7 @@ func (s *testIntegrationSerialSuite) TestIndexMerge(c *C) {
 		"Projection 1.80 root  test.t.a, test.t.b",
 		"└─IndexMerge 2.00 root  ",
 		"  ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:a(a) range:[1,1], keep order:false, stats:pseudo",
-		"  ├─Selection(Build) 0.80 cop[tikv]  eq(length(cast(1)), 1)",
+		"  ├─Selection(Build) 0.80 cop[tikv]  eq(length(cast(1, var_string(20))), 1)",
 		"  │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:b(b) range:[1,1], keep order:false, stats:pseudo",
 		"  └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo"))
 	tk.MustQuery("show warnings").Check(testkit.Rows())
@@ -1547,9 +1547,9 @@ func (s *testIntegrationSerialSuite) TestIndexMerge(c *C) {
 	tk.MustQuery("desc format='brief' select /*+ use_index_merge(t) */ * from t where (a=1 and length(a)=1) or (b=1 and length(b)=1)").Check(testkit.Rows(
 		"Projection 1.60 root  test.t.a, test.t.b",
 		"└─IndexMerge 2.00 root  ",
-		"  ├─Selection(Build) 0.80 cop[tikv]  eq(length(cast(1)), 1)",
+		"  ├─Selection(Build) 0.80 cop[tikv]  eq(length(cast(1, var_string(20))), 1)",
 		"  │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:a(a) range:[1,1], keep order:false, stats:pseudo",
-		"  ├─Selection(Build) 0.80 cop[tikv]  eq(length(cast(1)), 1)",
+		"  ├─Selection(Build) 0.80 cop[tikv]  eq(length(cast(1, var_string(20))), 1)",
 		"  │ └─IndexRangeScan 1.00 cop[tikv] table:t, index:b(b) range:[1,1], keep order:false, stats:pseudo",
 		"  └─TableRowIDScan(Probe) 2.00 cop[tikv] table:t keep order:false, stats:pseudo"))
 	tk.MustQuery("show warnings").Check(testkit.Rows())
@@ -1559,7 +1559,7 @@ func (s *testIntegrationSerialSuite) TestIndexMerge(c *C) {
 		"└─IndexMerge 0.00 root  ",
 		"  ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:a(a) range:[1,1], keep order:false, stats:pseudo",
 		"  ├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:b(b) range:[1,1], keep order:false, stats:pseudo",
-		"  └─Selection(Probe) 0.00 cop[tikv]  or(and(eq(test.t.a, 1), eq(length(cast(test.t.b)), 1)), and(eq(test.t.b, 1), eq(length(cast(test.t.a)), 1)))",
+		"  └─Selection(Probe) 0.00 cop[tikv]  or(and(eq(test.t.a, 1), eq(length(cast(test.t.b, var_string(20))), 1)), and(eq(test.t.b, 1), eq(length(cast(test.t.a, var_string(20))), 1)))",
 		"    └─TableRowIDScan 2.00 cop[tikv] table:t keep order:false, stats:pseudo",
 	))
 	tk.MustQuery("show warnings").Check(testkit.Rows())
diff --git a/planner/core/testdata/integration_serial_suite_out.json b/planner/core/testdata/integration_serial_suite_out.json
index 63fc11c2a2a59..09df62e2b7d27 100644
--- a/planner/core/testdata/integration_serial_suite_out.json
+++ b/planner/core/testdata/integration_serial_suite_out.json
@@ -13,7 +13,7 @@
       {
         "SQL": "explain format = 'brief' select * from t where cast(t.a as float) + 3 = 5.1",
         "Plan": [
-          "Selection 10000.00 root  eq(plus(cast(test.t.a), 3), 5.1)",
+          "Selection 10000.00 root  eq(plus(cast(test.t.a, float BINARY), 3), 5.1)",
           "└─TableReader 10000.00 root  data:TableFullScan",
           "  └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
         ]
@@ -25,7 +25,7 @@
           "└─TopN 2.00 root  Column#3, offset:0, count:2",
           "  └─Projection 2.00 root  test.t.a, test.t.b, cast(test.t.b, bigint(22) UNSIGNED BINARY)->Column#3",
           "    └─TableReader 2.00 root  data:TopN",
-          "      └─TopN 2.00 batchCop[tiflash]  cast(test.t.b), offset:0, count:2",
+          "      └─TopN 2.00 batchCop[tiflash]  cast(test.t.b, bigint(22) UNSIGNED BINARY), offset:0, count:2",
           "        └─Selection 3333.33 batchCop[tiflash]  gt(test.t.b, \"a\")",
           "          └─TableFullScan 10000.00 batchCop[tiflash] table:t keep order:false, stats:pseudo"
         ]
@@ -1838,7 +1838,7 @@
           "    └─HashJoin 7992.00 batchCop[tiflash]  inner join, equal:[eq(test.t.id, test.t.id)]",
           "      ├─ExchangeReceiver(Build) 6393.60 batchCop[tiflash]  ",
           "      │ └─ExchangeSender 6393.60 batchCop[tiflash]  ExchangeType: Broadcast",
-          "      │   └─Selection 6393.60 batchCop[tiflash]  lt(plus(test.t.value, cast(Column#7)), 10)",
+          "      │   └─Selection 6393.60 batchCop[tiflash]  lt(plus(test.t.value, cast(Column#7, decimal(20,0) BINARY)), 10)",
           "      │     └─Projection 7992.00 batchCop[tiflash]  Column#7, test.t.id, test.t.value",
           "      │       └─HashAgg 7992.00 batchCop[tiflash]  group by:test.t.id, test.t.value, funcs:sum(Column#10)->Column#7, funcs:firstrow(test.t.id)->test.t.id, funcs:firstrow(test.t.value)->test.t.value",
           "      │         └─ExchangeReceiver 7992.00 batchCop[tiflash]  ",
diff --git a/planner/core/testdata/integration_suite_out.json b/planner/core/testdata/integration_suite_out.json
index eec13a9ee1dd5..5cda7110658b0 100644
--- a/planner/core/testdata/integration_suite_out.json
+++ b/planner/core/testdata/integration_suite_out.json
@@ -52,7 +52,7 @@
         "Plan": [
           "Projection 9990.00 root  test.t.a, test.t.b, test.t.a, test.t.b",
           "└─HashJoin 9990.00 root  inner join, equal:[eq(test.t.a, test.t.a)]",
-          "  ├─Selection(Build) 7992.00 root  from_unixtime(cast(test.t.b))",
+          "  ├─Selection(Build) 7992.00 root  from_unixtime(cast(test.t.b, decimal(20,0) BINARY))",
           "  │ └─TableReader 7992.00 root  data:Selection",
           "  │   └─Selection 7992.00 cop[tikv]  not(isnull(test.t.a))",
           "  │     └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo",
@@ -87,7 +87,7 @@
         "Plan": [
           "HashJoin 10000.00 root  left outer join, equal:[eq(test.t.a, test.t.a)]",
           "├─TableReader(Build) 8000.00 root  data:Selection",
-          "│ └─Selection 8000.00 cop[tikv]  ge(cast(test.t.b), 2019-01-01 00:00:00.000000)",
+          "│ └─Selection 8000.00 cop[tikv]  ge(cast(test.t.b, date BINARY), 2019-01-01 00:00:00.000000)",
           "│   └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo",
           "└─TableReader(Probe) 10000.00 root  data:TableFullScan",
           "  └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo"
diff --git a/planner/core/testdata/plan_normalized_suite_out.json b/planner/core/testdata/plan_normalized_suite_out.json
index 9c7c085610dd9..8c656d9b60b40 100644
--- a/planner/core/testdata/plan_normalized_suite_out.json
+++ b/planner/core/testdata/plan_normalized_suite_out.json
@@ -56,7 +56,7 @@
         "Plan": [
           " Projection                 root test.t1.a, test.t1.b, test.t1.c",
           " └─Apply                    root semi join, equal:eq(?, ?)",
-          "   ├─Projection             root cast(test.t1.a), test.t1.a, test.t1.b, test.t1.c",
+          "   ├─Projection             root cast(test.t1.a, decimal(20,0) BINARY), test.t1.a, test.t1.b, test.t1.c",
           "   │ └─TableReader          root ",
           "   │   └─Selection          cop  gt(test.t1.b, ?)",
           "   │     └─TableFullScan    cop  table:t1, range:[?,?], keep order:false",
diff --git a/planner/core/testdata/point_get_plan_out.json b/planner/core/testdata/point_get_plan_out.json
index 7681045160215..b0053fde6044d 100644
--- a/planner/core/testdata/point_get_plan_out.json
+++ b/planner/core/testdata/point_get_plan_out.json
@@ -5,7 +5,7 @@
       {
         "SQL": "select * from t where t.a in ('1','2','4') and t.a+1=2 order by t.a desc",
         "Plan": [
-          "Selection 2.40 root  eq(plus(cast(test.t.a), 1), 2)",
+          "Selection 2.40 root  eq(plus(cast(test.t.a, double BINARY), 1), 2)",
           "└─Batch_Point_Get 3.00 root table:t, index:PRIMARY(a) keep order:true, desc:true"
         ],
         "Res": [
@@ -75,7 +75,7 @@
         "SQL": "select * from t1 where id = 0",
         "Plan": [
           "TableReader 8000.00 root  data:Selection",
-          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t1.id), 0)",
+          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t1.id, double BINARY), 0)",
           "  └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
         ],
         "Res": [
@@ -100,7 +100,7 @@
         "SQL": "select * from t1 where id = 0.0",
         "Plan": [
           "TableReader 8000.00 root  data:Selection",
-          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t1.id), 0)",
+          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t1.id, double BINARY), 0)",
           "  └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
         ],
         "Res": [
@@ -111,7 +111,7 @@
         "SQL": "select * from t1 where id = 1.0",
         "Plan": [
           "TableReader 8000.00 root  data:Selection",
-          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t1.id), 1)",
+          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t1.id, double BINARY), 1)",
           "  └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
         ],
         "Res": [
@@ -122,7 +122,7 @@
         "SQL": "select * from t1 where id in (0, 1)",
         "Plan": [
           "TableReader 9600.00 root  data:Selection",
-          "└─Selection 9600.00 cop[tikv]  or(eq(cast(test.t1.id), 0), eq(cast(test.t1.id), 1))",
+          "└─Selection 9600.00 cop[tikv]  or(eq(cast(test.t1.id, double BINARY), 0), eq(cast(test.t1.id, double BINARY), 1))",
           "  └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"
         ],
         "Res": [
@@ -134,7 +134,7 @@
         "SQL": "select * from t2 where id = 0",
         "Plan": [
           "IndexReader 8000.00 root  index:Selection",
-          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t2.id), 0)",
+          "└─Selection 8000.00 cop[tikv]  eq(cast(test.t2.id, double BINARY), 0)",
           "  └─IndexFullScan 10000.00 cop[tikv] table:t2, index:id(id) keep order:false, stats:pseudo"
         ],
         "Res": [
@@ -145,7 +145,7 @@
         "SQL": "select * from t2 where id in (0, 1)",
         "Plan": [
           "IndexReader 9600.00 root  index:Selection",
-          "└─Selection 9600.00 cop[tikv]  or(eq(cast(test.t2.id), 0), eq(cast(test.t2.id), 1))",
+          "└─Selection 9600.00 cop[tikv]  or(eq(cast(test.t2.id, double BINARY), 0), eq(cast(test.t2.id, double BINARY), 1))",
           "  └─IndexFullScan 10000.00 cop[tikv] table:t2, index:id(id) keep order:false, stats:pseudo"
         ],
         "Res": [
@@ -157,7 +157,7 @@
         "SQL": "select * from t3 where (id, d) in ((0, 't'), (1, 't'))",
         "Plan": [
           "IndexReader 15.99 root  index:Selection",
-          "└─Selection 15.99 cop[tikv]  or(and(eq(cast(test.t3.id), 0), eq(test.t3.d, \"t\")), and(eq(cast(test.t3.id), 1), eq(test.t3.d, \"t\")))",
+          "└─Selection 15.99 cop[tikv]  or(and(eq(cast(test.t3.id, double BINARY), 0), eq(test.t3.d, \"t\")), and(eq(cast(test.t3.id, double BINARY), 1), eq(test.t3.d, \"t\")))",
           "  └─IndexFullScan 10000.00 cop[tikv] table:t3, index:id(id, d) keep order:false, stats:pseudo"
         ],
         "Res": [
@@ -168,7 +168,7 @@
       {
         "SQL": "select * from t4 where (id, d, c) in ((1, 'b', 0))",
         "Plan": [
-          "Selection 0.80 root  eq(cast(test.t4.c), 0)",
+          "Selection 0.80 root  eq(cast(test.t4.c, double BINARY), 0)",
           "└─Point_Get 1.00 root table:t4, index:id(id, d) "
         ],
         "Res": [
@@ -179,9 +179,9 @@
         "SQL": "select * from t4 where (id, d, c) in ((1, 0, 0))",
         "Plan": [
           "IndexLookUp 8.00 root  ",
-          "├─Selection(Build) 8.00 cop[tikv]  eq(cast(test.t4.d), 0)",
+          "├─Selection(Build) 8.00 cop[tikv]  eq(cast(test.t4.d, double BINARY), 0)",
           "│ └─IndexRangeScan 10.00 cop[tikv] table:t4, index:id(id, d) range:[1,1], keep order:false, stats:pseudo",
-          "└─Selection(Probe) 8.00 cop[tikv]  eq(cast(test.t4.c), 0)",
+          "└─Selection(Probe) 8.00 cop[tikv]  eq(cast(test.t4.c, double BINARY), 0)",
           "  └─TableRowIDScan 8.00 cop[tikv] table:t4 keep order:false, stats:pseudo"
         ],
         "Res": [
diff --git a/util/ranger/testdata/ranger_suite_out.json b/util/ranger/testdata/ranger_suite_out.json
index c0127b7f76e2f..b7ad880d894d7 100644
--- a/util/ranger/testdata/ranger_suite_out.json
+++ b/util/ranger/testdata/ranger_suite_out.json
@@ -57,7 +57,7 @@
         "SQL": "explain format = 'brief' select * from t0 where c0 is true",
         "Result": [
           "TableReader 0.80 root  data:Selection",
-          "└─Selection 0.80 cop[tikv]  istrue(cast(test.t0.c0))",
+          "└─Selection 0.80 cop[tikv]  istrue(cast(test.t0.c0, double BINARY))",
           "  └─TableFullScan 1.00 cop[tikv] table:t0 keep order:false"
         ]
       },
@@ -65,7 +65,7 @@
         "SQL": "explain format = 'brief' select * from t0 where c0 is false",
         "Result": [
           "TableReader 0.80 root  data:Selection",
-          "└─Selection 0.80 cop[tikv]  isfalse(cast(test.t0.c0))",
+          "└─Selection 0.80 cop[tikv]  isfalse(cast(test.t0.c0, double BINARY))",
           "  └─TableFullScan 1.00 cop[tikv] table:t0 keep order:false"
         ]
       },