Skip to content

Commit

Permalink
Merge branch 'issue-27177-staging-2' of github.com:w169q169/tidb into…
Browse files Browse the repository at this point in the history
… issue-27177-staging-2
  • Loading branch information
w169q169 committed Sep 22, 2021
2 parents 8848c3b + 6893d4e commit 7c1628c
Show file tree
Hide file tree
Showing 27 changed files with 1,461 additions and 1,136 deletions.
3 changes: 1 addition & 2 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,11 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
}()

failpoint.Inject("assertStaleTSO", func(val failpoint.Value) {
if n, ok := val.(int); ok {
if n, ok := val.(int); ok && a.IsStaleness {
startTS := oracle.ExtractPhysical(a.SnapshotTS) / 1000
if n != int(startTS) {
panic(fmt.Sprintf("different tso %d != %d", n, startTS))
}
failpoint.Return()
}
})
sctx := a.Ctx
Expand Down
1 change: 1 addition & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,7 @@ func (b *executorBuilder) buildIndexLookUpJoin(v *plannercore.PhysicalIndexJoin)
for i, col := range v.OuterHashKeys {
outerTypes[col.Index] = outerTypes[col.Index].Clone()
outerTypes[col.Index].Collate = innerTypes[v.InnerHashKeys[i].Index].Collate
outerTypes[col.Index].Flag = col.RetType.Flag
}

var (
Expand Down
13 changes: 13 additions & 0 deletions executor/index_lookup_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ func (s *testSuite5) TestIssue24547(c *C) {
tk.MustExec("delete a from a inner join b on a.k1 = b.k1 and a.k2 = b.k2 where b.k2 <> '333'")
}

func (s *testSuite5) TestIssue27893(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec("drop table if exists t2")
tk.MustExec("create table t1 (a enum('x','y'))")
tk.MustExec("create table t2 (a int, key(a))")
tk.MustExec("insert into t1 values('x')")
tk.MustExec("insert into t2 values(1)")
tk.MustQuery("select /*+ inl_join(t2) */ count(*) from t1 join t2 on t1.a = t2.a").Check(testkit.Rows("1"))
tk.MustQuery("select /*+ inl_hash_join(t2) */ count(*) from t1 join t2 on t1.a = t2.a").Check(testkit.Rows("1"))
}

func (s *testSuite5) TestPartitionTableIndexJoinAndIndexReader(c *C) {
if israce.RaceEnabled {
c.Skip("exhaustive types test, skip race test")
Expand Down
40 changes: 39 additions & 1 deletion executor/stale_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ func (s *testStaleTxnSerialSuite) TestStaleReadPrepare(c *C) {
c.Assert("execute p1", NotNil)
}

func (s *testStaleTxnSuite) TestStmtCtxStaleFlag(c *C) {
func (s *testStaleTxnSerialSuite) TestStmtCtxStaleFlag(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
Expand Down Expand Up @@ -1106,3 +1106,41 @@ func (s *testStaleTxnSuite) TestStmtCtxStaleFlag(c *C) {
c.Assert(tk.Se.GetSessionVars().StmtCtx.IsStaleness, IsFalse)
}
}

func (s *testStaleTxnSerialSuite) TestStaleSessionQuery(c *C) {
tk := testkit.NewTestKit(c, s.store)
// For mocktikv, safe point is not initialized, we manually insert it for snapshot to use.
safePointName := "tikv_gc_safe_point"
safePointValue := "20160102-15:04:05 -0700"
safePointComment := "All versions after safe point can be accessed. (DO NOT EDIT)"
updateSafePoint := fmt.Sprintf(`INSERT INTO mysql.tidb VALUES ('%[1]s', '%[2]s', '%[3]s')
ON DUPLICATE KEY
UPDATE variable_value = '%[2]s', comment = '%[3]s'`, safePointName, safePointValue, safePointComment)
tk.MustExec(updateSafePoint)
tk.MustExec("use test")
tk.MustExec("create table t10 (id int);")
tk.MustExec("insert into t10 (id) values (1)")
time.Sleep(2 * time.Second)
now := time.Now()
tk.MustExec(`set @@tidb_read_staleness="-1s"`)
// query will use stale read
c.Assert(failpoint.Enable("github.com/pingcap/tidb/expression/injectNow", fmt.Sprintf(`return(%d)`, now.Unix())), IsNil)
c.Assert(failpoint.Enable("github.com/pingcap/tidb/executor/assertStaleTSO", fmt.Sprintf(`return(%d)`, now.Unix()-1)), IsNil)
c.Assert(tk.MustQuery("select * from t10;").Rows(), HasLen, 1)
c.Assert(failpoint.Disable("github.com/pingcap/tidb/executor/assertStaleTSO"), IsNil)
c.Assert(failpoint.Disable("github.com/pingcap/tidb/expression/injectNow"), IsNil)
// begin transaction won't be affected by read staleness
tk.MustExec("begin")
tk.MustExec("insert into t10(id) values (2);")
tk.MustExec("commit")
tk.MustExec("insert into t10(id) values (3);")
// query will still use staleness read
c.Assert(failpoint.Enable("github.com/pingcap/tidb/expression/injectNow", fmt.Sprintf(`return(%d)`, now.Unix())), IsNil)
c.Assert(failpoint.Enable("github.com/pingcap/tidb/executor/assertStaleTSO", fmt.Sprintf(`return(%d)`, now.Unix()-1)), IsNil)
c.Assert(tk.MustQuery("select * from t10").Rows(), HasLen, 1)
c.Assert(failpoint.Disable("github.com/pingcap/tidb/executor/assertStaleTSO"), IsNil)
c.Assert(failpoint.Disable("github.com/pingcap/tidb/expression/injectNow"), IsNil)
// assert stale read is not exist after empty the variable
tk.MustExec(`set @@tidb_read_staleness=""`)
c.Assert(tk.MustQuery("select * from t10").Rows(), HasLen, 3)
}
Loading

0 comments on commit 7c1628c

Please sign in to comment.