Skip to content

Commit

Permalink
cherry pick pingcap#27465 to release-5.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
guo-shaoge authored and ti-srebot committed Aug 24, 2021
1 parent 09d3925 commit 4b5cdb2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
64 changes: 64 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8710,3 +8710,67 @@ func (s *testSuite) TestEmptyTableSampleTemporaryTable(c *C) {
rs.Check(testkit.Rows())
tk.MustExec("commit")
}
<<<<<<< HEAD
=======

func (s *testSuite) TestIssue25506(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists tbl_3, tbl_23")
tk.MustExec("create table tbl_3 (col_15 bit(20))")
tk.MustExec("insert into tbl_3 values (0xFFFF)")
tk.MustExec("insert into tbl_3 values (0xFF)")
tk.MustExec("create table tbl_23 (col_15 bit(15))")
tk.MustExec("insert into tbl_23 values (0xF)")
tk.MustQuery("(select col_15 from tbl_23) union all (select col_15 from tbl_3 for update) order by col_15").Check(testkit.Rows("\x00\x00\x0F", "\x00\x00\xFF", "\x00\xFF\xFF"))
}

func (s *testSuite) TestIssue26532(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustQuery("select greatest(cast(\"2020-01-01 01:01:01\" as datetime), cast(\"2019-01-01 01:01:01\" as datetime) )union select null;").Sort().Check(testkit.Rows("2020-01-01 01:01:01", "<nil>"))
tk.MustQuery("select least(cast(\"2020-01-01 01:01:01\" as datetime), cast(\"2019-01-01 01:01:01\" as datetime) )union select null;").Sort().Check(testkit.Rows("2019-01-01 01:01:01", "<nil>"))
tk.MustQuery("select greatest(\"2020-01-01 01:01:01\" ,\"2019-01-01 01:01:01\" )union select null;").Sort().Check(testkit.Rows("2020-01-01 01:01:01", "<nil>"))
tk.MustQuery("select least(\"2020-01-01 01:01:01\" , \"2019-01-01 01:01:01\" )union select null;").Sort().Check(testkit.Rows("2019-01-01 01:01:01", "<nil>"))
}

func (s *testSuite) TestIssue25447(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2")
tk.MustExec("create table t1(a int, b varchar(8))")
tk.MustExec("insert into t1 values(1,'1')")
tk.MustExec("create table t2(a int , b varchar(8) GENERATED ALWAYS AS (c) VIRTUAL, c varchar(8), PRIMARY KEY (a))")
tk.MustExec("insert into t2(a) values(1)")
tk.MustQuery("select /*+ tidb_inlj(t2) */ t2.b, t1.b from t1 join t2 ON t2.a=t1.a").Check(testkit.Rows("<nil> 1"))
}

func (s *testSuite) TestIssue23602(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("USE test")
tk.Se.GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn
tk.MustExec("CREATE TABLE t (a bigint unsigned PRIMARY KEY)")
defer tk.MustExec("DROP TABLE t")
tk.MustExec("INSERT INTO t VALUES (0),(1),(2),(3),(18446744073709551600),(18446744073709551605),(18446744073709551610),(18446744073709551615)")
tk.MustExec("ANALYZE TABLE t")
tk.MustQuery(`EXPLAIN FORMAT = 'brief' SELECT a FROM t WHERE a >= 0x1 AND a <= 0x2`).Check(testkit.Rows(
"TableReader 2.00 root data:TableRangeScan]\n" +
"[└─TableRangeScan 2.00 cop[tikv] table:t range:[1,2], keep order:false"))
tk.MustQuery(`EXPLAIN FORMAT = 'brief' SELECT a FROM t WHERE a BETWEEN 0x1 AND 0x2`).Check(testkit.Rows(
"TableReader 2.00 root data:TableRangeScan]\n" +
"[└─TableRangeScan 2.00 cop[tikv] table:t range:[1,2], keep order:false"))
tk.MustQuery("SELECT a FROM t WHERE a BETWEEN 0xFFFFFFFFFFFFFFF5 AND X'FFFFFFFFFFFFFFFA'").Check(testkit.Rows("18446744073709551605", "18446744073709551610"))
}

func (s *testSuite) TestCTEWithIndexLookupJoinDeadLock(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table t (a int(11) default null,b int(11) default null,key b (b),key ba (b))")
tk.MustExec("create table t1 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b))")
tk.MustExec("create table t2 (a int(11) default null,b int(11) default null,key idx_ab (a,b),key idx_a (a),key idx_b (b))")
// It's easy to reproduce this problem in 30 times execution of IndexLookUpJoin.
for i := 0; i < 30; i++ {
tk.MustExec("with cte as (with cte1 as (select * from t2 use index(idx_ab) where a > 1 and b > 1) select * from cte1) select /*+use_index(t1 idx_ab)*/ * from cte join t1 on t1.a=cte.a;")
}
}
>>>>>>> 9691e5071... execution: fix cte dead lock when used with IndexLookupJoin (#27465)
4 changes: 2 additions & 2 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1679,10 +1679,10 @@ type execStmtResult struct {

func (rs *execStmtResult) Close() error {
se := rs.se
if err := resetCTEStorageMap(se); err != nil {
if err := rs.RecordSet.Close(); err != nil {
return finishStmt(context.Background(), se, err, rs.sql)
}
if err := rs.RecordSet.Close(); err != nil {
if err := resetCTEStorageMap(se); err != nil {
return finishStmt(context.Background(), se, err, rs.sql)
}
return finishStmt(context.Background(), se, nil, rs.sql)
Expand Down

0 comments on commit 4b5cdb2

Please sign in to comment.