Skip to content

Commit

Permalink
Merge branch 'master' into baderrmsgfornumericconversion
Browse files Browse the repository at this point in the history
  • Loading branch information
fanrenhoo committed May 7, 2022
2 parents b8e20f7 + 1f9d34a commit a5b1446
Show file tree
Hide file tree
Showing 715 changed files with 31,687 additions and 29,600 deletions.
2 changes: 1 addition & 1 deletion .github/licenserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ header:
- '**/*.key'
- '**/*.md'
- '**/*.json'
- '**/*.toml'
- '**/*.pem'
- '**/*.crt'
- '**/*.test'
- '**/*.result'
- '**/*.example'
- '.codecov.yml'
- 'errors.toml'
- 'Jenkinsfile'
- '.editorconfig'
- 'hooks/pre-commit'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@ on:
- '!br/docker/**'
# disable pull request only keep the merge action since it is very costly to run those tests
# pull_request:
# branches:
# - master
# - 'release-[0-9].[0-9]*'
# paths:
# - 'br/**'
# - '!**.html'
# - '!**.md'
# - '!CNAME'
# - '!LICENSE'
# - '!br/docs/**'
# - '!br/tests/**'
# - '!br/docker/**'

# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency.
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
Expand All @@ -57,6 +44,7 @@ jobs:
TAG=nightly PORT_SUFFIX=1 docker-compose -f br/compatibility/backup_cluster.yaml rm -s -v
TAG=nightly PORT_SUFFIX=1 docker-compose -f br/compatibility/backup_cluster.yaml build
TAG=nightly PORT_SUFFIX=1 docker-compose -f br/compatibility/backup_cluster.yaml up --remove-orphans -d
TAG=nightly PORT_SUFFIX=1 docker-compose -f br/compatibility/backup_cluster.yaml exec -T control go mod tidy
TAG=nightly PORT_SUFFIX=1 docker-compose -f br/compatibility/backup_cluster.yaml exec -T control make build_br
TAG=nightly PORT_SUFFIX=1 docker-compose -f br/compatibility/backup_cluster.yaml exec -T control br/tests/run_compatible.sh run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ on:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency.
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ on:
- 'util/codec/**'
- 'parser/model/**'

# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency.
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/integration-test-with-real-tikv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Real TiKV Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
pessimistic-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Setup TiKV cluster
run: |
# Disable pipelined pessimistic lock temporarily until tikv#11649 is resolved
echo -e "[pessimistic-txn]\npipelined = false\n" > tikv.toml
echo -e "[raftdb]\nmax-open-files = 10240\n" >> tikv.toml
echo -e "[rocksdb]\nmax-open-files = 10240\n" >> tikv.toml
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
$HOME/.tiup/bin/tiup playground nightly --mode tikv-slim --kv 3 --pd 3 --without-monitor --kv.config tikv.toml &
curl --retry-connrefused --retry 5 --retry-delay 5 http://127.0.0.1:2379
- name: Run Tests
run: |
export log_level=error
make failpoint-enable
go test ./tests/pessimistictest -v -with-real-tikv -timeout 20m
1,267 changes: 0 additions & 1,267 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion bindinfo/bind_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"errors"
"sync"

"github.com/cznic/mathutil"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/kvcache"
"github.com/pingcap/tidb/util/mathutil"
"github.com/pingcap/tidb/util/memory"
)

Expand Down
97 changes: 23 additions & 74 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package bindinfo_test

import (
"context"
"crypto/tls"
"fmt"
"strconv"
"testing"
Expand All @@ -29,61 +28,11 @@ import (
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/terror"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session/txninfo"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util"
"github.com/stretchr/testify/require"
)

// mockSessionManager is a mocked session manager which is used for test.
type mockSessionManager1 struct {
PS []*util.ProcessInfo
}

func (msm *mockSessionManager1) ShowTxnList() []*txninfo.TxnInfo {
return nil
}

// ShowProcessList implements the SessionManager.ShowProcessList interface.
func (msm *mockSessionManager1) ShowProcessList() map[uint64]*util.ProcessInfo {
ret := make(map[uint64]*util.ProcessInfo)
for _, item := range msm.PS {
ret[item.ID] = item
}
return ret
}

func (msm *mockSessionManager1) GetProcessInfo(id uint64) (*util.ProcessInfo, bool) {
for _, item := range msm.PS {
if item.ID == id {
return item, true
}
}
return &util.ProcessInfo{}, false
}

// Kill implements the SessionManager.Kill interface.
func (msm *mockSessionManager1) Kill(cid uint64, query bool) {
}

func (msm *mockSessionManager1) KillAllConnections() {
}

func (msm *mockSessionManager1) UpdateTLSConfig(cfg *tls.Config) {
}

func (msm *mockSessionManager1) ServerID() uint64 {
return 1
}

func (msm *mockSessionManager1) StoreInternalSession(se interface{}) {}

func (msm *mockSessionManager1) DeleteInternalSession(se interface{}) {}

func (msm *mockSessionManager1) GetInternalSessionStartTSList() []uint64 {
return nil
}

func TestPrepareCacheWithBinding(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
Expand All @@ -105,7 +54,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t1:idx_b", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess := tk.Session().ShowProcess()
ps := []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res := tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_b(b)"), res.Rows())
tk.MustExec("execute stmt1;")
Expand All @@ -117,15 +66,15 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t1:idx_c", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_c(c)"), res.Rows())

tk.MustExec("prepare stmt2 from 'delete t1, t2 from t1 inner join t2 on t1.b = t2.b';")
tk.MustExec("execute stmt2;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "HashJoin"), res.Rows())
tk.MustExec("execute stmt2;")
Expand All @@ -136,7 +85,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt2;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "IndexJoin"), res.Rows())

Expand All @@ -145,7 +94,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t1:idx_b", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_b(b)"), res.Rows())
tk.MustExec("execute stmt3;")
Expand All @@ -157,15 +106,15 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t1:idx_c", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_c(c)"), res.Rows())

tk.MustExec("prepare stmt4 from 'update t1, t2 set t1.a = 1 where t1.b = t2.b';")
tk.MustExec("execute stmt4;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "HashJoin"), res.Rows())
tk.MustExec("execute stmt4;")
Expand All @@ -176,7 +125,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt4;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "IndexJoin"), res.Rows())

Expand All @@ -185,7 +134,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t2:idx_b", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_b(b)"), res.Rows())
tk.MustExec("execute stmt5;")
Expand All @@ -197,7 +146,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t2:idx_b", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_b(b)"), res.Rows())

Expand All @@ -208,7 +157,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t2:idx_c", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_c(c)"), res.Rows())

Expand All @@ -217,7 +166,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t2:idx_b", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_b(b)"), res.Rows())
tk.MustExec("execute stmt6;")
Expand All @@ -229,7 +178,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t2:idx_c", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "idx_c(c)"), res.Rows())

Expand All @@ -243,7 +192,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt1;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "HashJoin"))
tk.MustExec("execute stmt1;")
Expand All @@ -253,7 +202,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt2;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "MergeJoin"))
tk.MustExec("execute stmt2;")
Expand All @@ -264,7 +213,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt1;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "MergeJoin"))

Expand All @@ -275,7 +224,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt1;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "IndexReader"))
tk.MustExec("execute stmt1;")
Expand All @@ -285,7 +234,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt1;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.False(t, tk.HasPlan4ExplainFor(res, "IndexReader"))
tk.MustExec("execute stmt1;")
Expand All @@ -296,7 +245,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt1;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.False(t, tk.HasPlan4ExplainFor(res, "IndexReader"))
tk.MustExec("execute stmt1;")
Expand All @@ -306,7 +255,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt2;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "IndexReader"))
tk.MustExec("execute stmt2;")
Expand All @@ -317,7 +266,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
tk.MustExec("execute stmt1;")
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.HasPlan4ExplainFor(res, "IndexReader"))

Expand All @@ -332,7 +281,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t:ia", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "ia(a)"), res.Rows())
tk.MustExec("execute stmt1;")
Expand All @@ -345,7 +294,7 @@ func TestPrepareCacheWithBinding(t *testing.T) {
require.Equal(t, "t:ib", tk.Session().GetSessionVars().StmtCtx.IndexNames[0])
tkProcess = tk.Session().ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&mockSessionManager1{PS: ps})
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
require.True(t, tk.MustUseIndex4ExplainFor(res, "ib(b)"), res.Rows())
}
Expand Down
3 changes: 1 addition & 2 deletions bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,7 @@ func GenerateBindSQL(ctx context.Context, stmtNode ast.StmtNode, planHint string
withIdx := strings.Index(bindSQL, "WITH")
restoreCtx := format.NewRestoreCtx(format.RestoreStringSingleQuotes|format.RestoreSpacesAroundBinaryOperation|format.RestoreStringWithoutCharset|format.RestoreNameBackQuotes, &withSb)
restoreCtx.DefaultDB = defaultDB
err := n.With.Restore(restoreCtx)
if err != nil {
if err := n.With.Restore(restoreCtx); err != nil {
logutil.BgLogger().Debug("[sql-bind] restore SQL failed", zap.Error(err))
return ""
}
Expand Down
Loading

0 comments on commit a5b1446

Please sign in to comment.