Skip to content

Commit

Permalink
cherry pick #30002 to release-5.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
Yisaer authored and ti-srebot committed Dec 16, 2021
1 parent 90ae7cc commit c1380a1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
56 changes: 56 additions & 0 deletions executor/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,59 @@ func (s *testSuite1) TestCheckActRowsWithUnistore(c *C) {
checkActRows(c, tk, test.sql, test.expected)
}
}
<<<<<<< HEAD
=======

func (s *testSuite2) TestExplainAnalyzeCTEMemoryAndDiskInfo(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int)")
tk.MustExec("insert into t with recursive cte(a) as (select 1 union select a + 1 from cte where a < 1000) select * from cte;")

rows := tk.MustQuery("explain analyze with recursive cte(a) as (select 1 union select a + 1 from cte where a < 1000)" +
" select * from cte, t;").Rows()

c.Assert(rows[4][7].(string), Not(Equals), "N/A")
c.Assert(rows[4][8].(string), Equals, "0 Bytes")

tk.MustExec("set @@tidb_mem_quota_query=10240;")
rows = tk.MustQuery("explain analyze with recursive cte(a) as (select 1 union select a + 1 from cte where a < 1000)" +
" select * from cte, t;").Rows()

c.Assert(rows[4][7].(string), Not(Equals), "N/A")
c.Assert(rows[4][8].(string), Not(Equals), "N/A")
}

func (s *testSuite) TestExplainStatementsSummary(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustQuery("desc select * from information_schema.statements_summary").Check(testkit.Rows(
`MemTableScan_4 10000.00 root table:STATEMENTS_SUMMARY `))
tk.MustQuery("desc select * from information_schema.statements_summary where digest is null").Check(testutil.RowsWithSep("|",
`Selection_5|8000.00|root| isnull(Column#5)`, `└─MemTableScan_6|10000.00|root|table:STATEMENTS_SUMMARY|`))
tk.MustQuery("desc select * from information_schema.statements_summary where digest = 'abcdefg'").Check(testutil.RowsWithSep(" ",
`MemTableScan_5 10000.00 root table:STATEMENTS_SUMMARY digests: ["abcdefg"]`))
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;")
}
>>>>>>> 05ccb8a20... planner: fix panic when the join key is scalarFunction (#30002)
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 @@ -287,10 +287,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 c1380a1

Please sign in to comment.