Skip to content

Commit

Permalink
planner: fix panic when the join key is scalarFunction (#30002) (#30776)
Browse files Browse the repository at this point in the history
close #29401
  • Loading branch information
ti-srebot authored Apr 12, 2022
1 parent 4910fb9 commit a37ad32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions executor/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
}
6 changes: 5 additions & 1 deletion planner/core/rule_predicate_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a37ad32

Please sign in to comment.