Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/ranger: consider good non-point ranges from CNF item (#44384) #44394

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 249 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,259 @@ type SessionVars struct {
// ReadStaleness indicates the staleness duration for the following query
ReadStaleness time.Duration

<<<<<<< HEAD
// cached is used to optimze the object allocation.
cached struct {
curr int8
data [2]stmtctx.StatementContext
=======
// cachedStmtCtx is used to optimze the object allocation.
cachedStmtCtx [2]stmtctx.StatementContext

// Rng stores the rand_seed1 and rand_seed2 for Rand() function
Rng *mathutil.MysqlRng

// EnablePaging indicates whether enable paging in coprocessor requests.
EnablePaging bool

// EnableLegacyInstanceScope says if SET SESSION can be used to set an instance
// scope variable. The default is TRUE.
EnableLegacyInstanceScope bool

// ReadConsistency indicates the read consistency requirement.
ReadConsistency ReadConsistencyLevel

// StatsLoadSyncWait indicates how long to wait for stats load before timeout.
StatsLoadSyncWait int64

// SysdateIsNow indicates whether Sysdate is an alias of Now function
SysdateIsNow bool
// EnableMutationChecker indicates whether to check data consistency for mutations
EnableMutationChecker bool
// AssertionLevel controls how strict the assertions on data mutations should be.
AssertionLevel AssertionLevel
// IgnorePreparedCacheCloseStmt controls if ignore the close-stmt command for prepared statement.
IgnorePreparedCacheCloseStmt bool
// EnableNewCostInterface is a internal switch to indicates whether to use the new cost calculation interface.
EnableNewCostInterface bool
// CostModelVersion is a internal switch to indicates the Cost Model Version.
CostModelVersion int
// IndexJoinDoubleReadPenaltyCostRate indicates whether to add some penalty cost to IndexJoin and how much of it.
IndexJoinDoubleReadPenaltyCostRate float64

// BatchPendingTiFlashCount shows the threshold of pending TiFlash tables when batch adding.
BatchPendingTiFlashCount int
// RcWriteCheckTS indicates whether some special write statements don't get latest tso from PD at RC
RcWriteCheckTS bool
// RemoveOrderbyInSubquery indicates whether to remove ORDER BY in subquery.
RemoveOrderbyInSubquery bool
// NonTransactionalIgnoreError indicates whether to ignore error in non-transactional statements.
// When set to false, returns immediately when it meets the first error.
NonTransactionalIgnoreError bool

// MaxAllowedPacket indicates the maximum size of a packet for the MySQL protocol.
MaxAllowedPacket uint64

// TiFlash related optimization, only for MPP.
TiFlashFineGrainedShuffleStreamCount int64
TiFlashFineGrainedShuffleBatchSize uint64

// RequestSourceType is the type of inner request.
RequestSourceType string

// MemoryDebugModeMinHeapInUse indicated the minimum heapInUse threshold that triggers the memoryDebugMode.
MemoryDebugModeMinHeapInUse int64
// MemoryDebugModeAlarmRatio indicated the allowable bias ratio of memory tracking accuracy check.
// When `(memory trakced by tidb) * (1+MemoryDebugModeAlarmRatio) < actual heapInUse`, an alarm log will be recorded.
MemoryDebugModeAlarmRatio int64

// EnableAnalyzeSnapshot indicates whether to read data on snapshot when collecting statistics.
// When it is false, ANALYZE reads the latest data.
// When it is true, ANALYZE reads data on the snapshot at the beginning of ANALYZE.
EnableAnalyzeSnapshot bool

// DefaultStrMatchSelectivity adjust the estimation strategy for string matching expressions that can't be estimated by building into range.
// when > 0: it's the selectivity for the expression.
// when = 0: try to use TopN to evaluate the like expression to estimate the selectivity.
DefaultStrMatchSelectivity float64

// TiFlashFastScan indicates whether use fast scan in TiFlash
TiFlashFastScan bool

// PrimaryKeyRequired indicates if sql_require_primary_key sysvar is set
PrimaryKeyRequired bool

// EnablePreparedPlanCache indicates whether to enable prepared plan cache.
EnablePreparedPlanCache bool

// PreparedPlanCacheSize controls the size of prepared plan cache.
PreparedPlanCacheSize uint64

// PreparedPlanCacheMonitor indicates whether to enable prepared plan cache monitor.
EnablePreparedPlanCacheMemoryMonitor bool

// EnablePlanCacheForParamLimit controls whether the prepare statement with parameterized limit can be cached
EnablePlanCacheForParamLimit bool

// EnablePlanCacheForSubquery controls whether the prepare statement with sub query can be cached
EnablePlanCacheForSubquery bool

// EnableNonPreparedPlanCache indicates whether to enable non-prepared plan cache.
EnableNonPreparedPlanCache bool

// EnableNonPreparedPlanCacheForDML indicates whether to enable non-prepared plan cache for DML statements.
EnableNonPreparedPlanCacheForDML bool

// PlanCacheInvalidationOnFreshStats controls if plan cache will be invalidated automatically when
// related stats are analyzed after the plan cache is generated.
PlanCacheInvalidationOnFreshStats bool

// NonPreparedPlanCacheSize controls the size of non-prepared plan cache.
NonPreparedPlanCacheSize uint64

// PlanCacheMaxPlanSize controls the maximum size of a plan that can be cached.
PlanCacheMaxPlanSize uint64

// SessionPlanCacheSize controls the size of session plan cache.
SessionPlanCacheSize uint64

// ConstraintCheckInPlacePessimistic controls whether to skip the locking of some keys in pessimistic transactions.
// Postpone the conflict check and constraint check to prewrite or later pessimistic locking requests.
ConstraintCheckInPlacePessimistic bool

// EnableTiFlashReadForWriteStmt indicates whether to enable TiFlash to read for write statements.
EnableTiFlashReadForWriteStmt bool

// EnableUnsafeSubstitute indicates whether to enable generate column takes unsafe substitute.
EnableUnsafeSubstitute bool

// ForeignKeyChecks indicates whether to enable foreign key constraint check.
ForeignKeyChecks bool

// RangeMaxSize is the max memory limit for ranges. When the optimizer estimates that the memory usage of complete
// ranges would exceed the limit, it chooses less accurate ranges such as full range. 0 indicates that there is no
// memory limit for ranges.
RangeMaxSize int64

// LastPlanReplayerToken indicates the last plan replayer token
LastPlanReplayerToken string

// InPlanReplayer means we are now executing a statement for a PLAN REPLAYER SQL.
// Note that PLAN REPLAYER CAPTURE is not included here.
InPlanReplayer bool

// AnalyzePartitionConcurrency indicates concurrency for partitions in Analyze
AnalyzePartitionConcurrency int
// AnalyzePartitionMergeConcurrency indicates concurrency for merging partition stats
AnalyzePartitionMergeConcurrency int

// EnableExternalTSRead indicates whether to enable read through external ts
EnableExternalTSRead bool

HookContext

// MemTracker indicates the memory tracker of current session.
MemTracker *memory.Tracker
// MemDBDBFootprint tracks the memory footprint of memdb, and is attached to `MemTracker`
MemDBFootprint *memory.Tracker
DiskTracker *memory.Tracker

// OptPrefixIndexSingleScan indicates whether to do some optimizations to avoid double scan for prefix index.
// When set to true, `col is (not) null`(`col` is index prefix column) is regarded as index filter rather than table filter.
OptPrefixIndexSingleScan bool

// ChunkPool Several chunks and columns are cached
ChunkPool ReuseChunkPool
// EnableReuseCheck indicates request chunk whether use chunk alloc
EnableReuseCheck bool

// EnableAdvancedJoinHint indicates whether the join method hint is compatible with join order hint.
EnableAdvancedJoinHint bool

// preuseChunkAlloc indicates whether pre statement use chunk alloc
// like select @@last_sql_use_alloc
preUseChunkAlloc bool

// EnablePlanReplayerCapture indicates whether enabled plan replayer capture
EnablePlanReplayerCapture bool

// EnablePlanReplayedContinuesCapture indicates whether enabled plan replayer continues capture
EnablePlanReplayedContinuesCapture bool

// PlanReplayerFinishedTaskKey used to record the finished plan replayer task key in order not to record the
// duplicate task in plan replayer continues capture
PlanReplayerFinishedTaskKey map[replayer.PlanReplayerTaskKey]struct{}

// StoreBatchSize indicates the batch size limit of store batch, set this field to 0 to disable store batch.
StoreBatchSize int

// shardRand is used by TxnCtx, for the GetCurrentShard() method.
shardRand *rand.Rand

// Resource group name
ResourceGroupName string

// PessimisticTransactionFairLocking controls whether fair locking for pessimistic transaction
// is enabled.
PessimisticTransactionFairLocking bool

// EnableINLJoinInnerMultiPattern indicates whether enable multi pattern for index join inner side
// For now it is not public to user
EnableINLJoinInnerMultiPattern bool

// Enable late materialization: push down some selection condition to tablescan.
EnableLateMaterialization bool

// EnableRowLevelChecksum indicates whether row level checksum is enabled.
EnableRowLevelChecksum bool

// TiFlashComputeDispatchPolicy indicates how to dipatch task to tiflash_compute nodes.
// Only for disaggregated-tiflash mode.
TiFlashComputeDispatchPolicy tiflashcompute.DispatchPolicy

// SlowTxnThreshold is the threshold of slow transaction logs
SlowTxnThreshold uint64

// LoadBasedReplicaReadThreshold is the threshold for the estimated wait duration of a store.
// If exceeding the threshold, try other stores using replica read.
LoadBasedReplicaReadThreshold time.Duration

// OptOrderingIdxSelThresh is the threshold for optimizer to consider the ordering index.
// If there exists an index whose estimated selectivity is smaller than this threshold, the optimizer won't
// use the ExpectedCnt to adjust the estimated row count for index scan.
OptOrderingIdxSelThresh float64

// EnableMPPSharedCTEExecution indicates whether we enable the shared CTE execution strategy on MPP side.
EnableMPPSharedCTEExecution bool

// OptimizerFixControl control some details of the optimizer behavior through the tidb_opt_fix_control variable.
OptimizerFixControl map[uint64]string

// HypoIndexes are for the Index Advisor.
HypoIndexes map[string]map[string]map[string]*model.IndexInfo // dbName -> tblName -> idxName -> idxInfo

// Runtime Filter Group
// Runtime filter type: only support IN or MIN_MAX now.
// Runtime filter type can take multiple values at the same time.
runtimeFilterTypes []RuntimeFilterType
// Runtime filter mode: only support OFF, LOCAL now
runtimeFilterMode RuntimeFilterMode
}

var (
// variables below are for the optimizer fix control.

// TiDBOptFixControl44262 controls whether to allow to use dynamic-mode to access partitioning tables without global-stats (#44262).
TiDBOptFixControl44262 uint64 = 44262
// TiDBOptFixControl44389 controls whether to consider non-point ranges of some CNF item when building ranges.
TiDBOptFixControl44389 uint64 = 44389
)

// GetOptimizerFixControlValue returns the specified value of the optimizer fix control.
func (s *SessionVars) GetOptimizerFixControlValue(key uint64) (value string, exist bool) {
if s.OptimizerFixControl == nil {
return "", false
>>>>>>> 85d6323e3a3 (util/ranger: consider good non-point ranges from CNF item (#44384))
}
}

Expand Down
70 changes: 70 additions & 0 deletions util/ranger/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "ranger",
srcs = [
"checker.go",
"detacher.go",
"points.go",
"ranger.go",
"types.go",
],
importpath = "github.com/pingcap/tidb/util/ranger",
visibility = ["//visibility:public"],
deps = [
"//errno",
"//expression",
"//kv",
"//parser/ast",
"//parser/charset",
"//parser/format",
"//parser/model",
"//parser/mysql",
"//parser/terror",
"//sessionctx",
"//sessionctx/stmtctx",
"//sessionctx/variable",
"//types",
"//types/parser_driver",
"//util/chunk",
"//util/codec",
"//util/collate",
"//util/dbterror",
"//util/mathutil",
"@com_github_pingcap_errors//:errors",
"@org_golang_x_exp//slices",
],
)

go_test(
name = "ranger_test",
timeout = "short",
srcs = [
"bench_test.go",
"main_test.go",
"ranger_test.go",
"types_test.go",
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 26,
deps = [
":ranger",
"//config",
"//expression",
"//parser/ast",
"//parser/model",
"//parser/mysql",
"//planner/core",
"//session",
"//sessionctx",
"//sessionctx/variable",
"//testkit",
"//testkit/testdata",
"//testkit/testsetup",
"//types",
"//util/collate",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
],
)
Loading