diff --git a/executor/explain_test.go b/executor/explain_test.go index c5d23628dfbaa..a26f373e10b71 100644 --- a/executor/explain_test.go +++ b/executor/explain_test.go @@ -365,3 +365,24 @@ func (s *testSuite) TestExplainStatementsSummary(c *C) { tk.MustQuery("desc select * from information_schema.statements_summary where digest in ('a','b','c')").Check(testutil.RowsWithSep(" ", `MemTableScan_5 10000.00 root table:STATEMENTS_SUMMARY digests: ["a","b","c"]`)) } + +func (s *testSuite) TestFix29401(c *C) { + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("drop table if exists tt123;") + tk.MustExec(`CREATE TABLE tt123 ( + id int(11) NOT NULL, + a bigint(20) DEFAULT NULL, + b char(20) DEFAULT NULL, + c datetime DEFAULT NULL, + d double DEFAULT NULL, + e json DEFAULT NULL, + f decimal(40,6) DEFAULT NULL, + PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */, + KEY a (a), + KEY b (b), + KEY c (c), + KEY d (d), + KEY f (f) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`) + tk.MustExec(" explain select /*+ inl_hash_join(t1) */ * from tt123 t1 join tt123 t2 on t1.b=t2.e;") +} diff --git a/planner/core/rule_predicate_push_down.go b/planner/core/rule_predicate_push_down.go index 793dbc0d31cbb..f59fedc25ba28 100644 --- a/planner/core/rule_predicate_push_down.go +++ b/planner/core/rule_predicate_push_down.go @@ -288,10 +288,14 @@ func (p *LogicalProjection) appendExpr(expr expression.Expression) *expression.C col := &expression.Column{ UniqueID: p.ctx.GetSessionVars().AllocPlanColumnID(), - RetType: expr.GetType(), + RetType: expr.GetType().Clone(), } col.SetCoercibility(expr.Coercibility()) p.schema.Append(col) + // reset ParseToJSONFlag in order to keep the flag away from json column + if col.GetType().Tp == mysql.TypeJSON { + col.GetType().Flag &= ^mysql.ParseToJSONFlag + } return col }