executor: let analyze isolevel controlled by tidb_enable_analyze_snapshot (#37193)

ref pingcap/tidb#36983
This commit is contained in:
Song Gao
2022-08-18 14:18:53 +08:00
committed by GitHub
parent 7586ba021c
commit b7797db46c
5 changed files with 13 additions and 7 deletions

View File

@ -157,7 +157,7 @@ func TestAnalyze(t *testing.T) {
sctx := newMockSessionContext()
sctx.GetSessionVars().EnableChunkRPC = false
request, err := (&RequestBuilder{}).SetKeyRanges(nil).
SetAnalyzeRequest(&tipb.AnalyzeReq{}).
SetAnalyzeRequest(&tipb.AnalyzeReq{}, kv.RC).
SetKeepOrder(true).
Build()
require.NoError(t, err)

View File

@ -158,12 +158,12 @@ func (builder *RequestBuilder) SetDAGRequest(dag *tipb.DAGRequest) *RequestBuild
}
// SetAnalyzeRequest sets the request type to "ReqTypeAnalyze" and construct request data.
func (builder *RequestBuilder) SetAnalyzeRequest(ana *tipb.AnalyzeReq) *RequestBuilder {
func (builder *RequestBuilder) SetAnalyzeRequest(ana *tipb.AnalyzeReq, isoLevel kv.IsoLevel) *RequestBuilder {
if builder.err == nil {
builder.Request.Tp = kv.ReqTypeAnalyze
builder.Request.Data, builder.err = ana.Marshal()
builder.Request.NotFillCache = true
builder.Request.IsolationLevel = kv.SI
builder.Request.IsolationLevel = isoLevel
builder.Request.Priority = kv.PriorityLow
}

View File

@ -481,7 +481,7 @@ func TestRequestBuilder5(t *testing.T) {
}
actual, err := (&RequestBuilder{}).SetKeyRanges(keyRanges).
SetAnalyzeRequest(&tipb.AnalyzeReq{}).
SetAnalyzeRequest(&tipb.AnalyzeReq{}, kv.RC).
SetKeepOrder(true).
SetConcurrency(15).
Build()
@ -494,7 +494,7 @@ func TestRequestBuilder5(t *testing.T) {
KeepOrder: true,
Desc: false,
Concurrency: 15,
IsolationLevel: kv.SI,
IsolationLevel: kv.RC,
Priority: 1,
NotFillCache: true,
ReadReplicaScope: kv.GlobalReplicaScope,

View File

@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/distsql"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
@ -109,13 +110,15 @@ func (e *AnalyzeColumnsExec) buildResp(ranges []*ranger.Range) (distsql.SelectRe
reqBuilder := builder.SetHandleRangesForTables(e.ctx.GetSessionVars().StmtCtx, []int64{e.TableID.GetStatisticsID()}, e.handleCols != nil && !e.handleCols.IsInt(), ranges, nil)
builder.SetResourceGroupTagger(e.ctx.GetSessionVars().StmtCtx.GetResourceGroupTagger())
startTS := uint64(math.MaxUint64)
isoLevel := kv.RC
if e.ctx.GetSessionVars().EnableAnalyzeSnapshot {
startTS = e.snapshot
isoLevel = kv.SI
}
// Always set KeepOrder of the request to be true, in order to compute
// correct `correlation` of columns.
kvReq, err := reqBuilder.
SetAnalyzeRequest(e.analyzePB).
SetAnalyzeRequest(e.analyzePB, isoLevel).
SetStartTS(startTS).
SetKeepOrder(true).
SetConcurrency(e.concurrency).

View File

@ -24,6 +24,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/distsql"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
@ -144,11 +145,13 @@ func (e *AnalyzeIndexExec) fetchAnalyzeResult(ranges []*ranger.Range, isNullRang
}
kvReqBuilder.SetResourceGroupTagger(e.ctx.GetSessionVars().StmtCtx.GetResourceGroupTagger())
startTS := uint64(math.MaxUint64)
isoLevel := kv.RC
if e.ctx.GetSessionVars().EnableAnalyzeSnapshot {
startTS = e.snapshot
isoLevel = kv.SI
}
kvReq, err := kvReqBuilder.
SetAnalyzeRequest(e.analyzePB).
SetAnalyzeRequest(e.analyzePB, isoLevel).
SetStartTS(startTS).
SetKeepOrder(true).
SetConcurrency(e.concurrency).