diff --git a/executor/explain_test.go b/executor/explain_test.go index a0ce1a1eb2e0c..ca7923e11049b 100644 --- a/executor/explain_test.go +++ b/executor/explain_test.go @@ -351,3 +351,24 @@ func (s *testSuite2) TestExplainAnalyzeCTEMemoryAndDiskInfo(c *C) { c.Assert(rows[4][7].(string), Not(Equals), "N/A") c.Assert(rows[4][8].(string), Not(Equals), "N/A") } + +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 c4a350420b3ee..c49c7a21e73a3 100644 --- a/planner/core/rule_predicate_push_down.go +++ b/planner/core/rule_predicate_push_down.go @@ -286,10 +286,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 }