*: add cbo switch. (#3877)
This commit is contained in:
@ -30,7 +30,7 @@ import (
|
||||
|
||||
// UseDAGPlanBuilder checks if we use new DAG planner.
|
||||
func UseDAGPlanBuilder(ctx context.Context) bool {
|
||||
return ctx.GetClient().IsRequestTypeSupported(kv.ReqTypeDAG, kv.ReqSubTypeBasic)
|
||||
return ctx.GetClient().IsRequestTypeSupported(kv.ReqTypeDAG, kv.ReqSubTypeBasic) && ctx.GetSessionVars().CBO
|
||||
}
|
||||
|
||||
// Plan is the description of an execution flow.
|
||||
|
||||
@ -1029,6 +1029,7 @@ const loadCommonGlobalVarsSQL = "select * from mysql.global_variables where vari
|
||||
variable.TiDBIndexLookupConcurrency + quoteCommaQuote +
|
||||
variable.TiDBIndexSerialScanConcurrency + quoteCommaQuote +
|
||||
variable.TiDBMaxRowCountForINLJ + quoteCommaQuote +
|
||||
variable.TiDBCBO + quoteCommaQuote +
|
||||
variable.TiDBDistSQLScanConcurrency + "')"
|
||||
|
||||
// loadCommonGlobalVariablesIfNeeded loads and applies commonly used global variables for the session.
|
||||
|
||||
@ -208,6 +208,9 @@ type SessionVars struct {
|
||||
|
||||
// MaxRowCountForINLJ defines max row count that the outer table of index nested loop join could be without force hint.
|
||||
MaxRowCountForINLJ int
|
||||
|
||||
// CBO indicates if we use new planner with cbo.
|
||||
CBO bool
|
||||
}
|
||||
|
||||
// NewSessionVars creates a session vars object.
|
||||
@ -229,6 +232,7 @@ func NewSessionVars() *SessionVars {
|
||||
IndexSerialScanConcurrency: DefIndexSerialScanConcurrency,
|
||||
DistSQLScanConcurrency: DefDistSQLScanConcurrency,
|
||||
MaxRowCountForINLJ: DefMaxRowCountForINLJ,
|
||||
CBO: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -607,6 +607,7 @@ var defaultSysVars = []*SysVar{
|
||||
{ScopeGlobal | ScopeSession, TiDBIndexLookupConcurrency, strconv.Itoa(DefIndexLookupConcurrency)},
|
||||
{ScopeGlobal | ScopeSession, TiDBIndexSerialScanConcurrency, strconv.Itoa(DefIndexSerialScanConcurrency)},
|
||||
{ScopeGlobal | ScopeSession, TiDBMaxRowCountForINLJ, strconv.Itoa(DefMaxRowCountForINLJ)},
|
||||
{ScopeGlobal | ScopeSession, TiDBCBO, "ON"},
|
||||
{ScopeGlobal | ScopeSession, TiDBSkipUTF8Check, boolToIntStr(DefSkipUTF8Check)},
|
||||
{ScopeSession, TiDBBatchInsert, boolToIntStr(DefBatchInsert)},
|
||||
{ScopeSession, TiDBCurrentTS, strconv.Itoa(DefCurretTS)},
|
||||
|
||||
@ -90,6 +90,9 @@ const (
|
||||
// It controls the max row count of outer table when do index nested loop join without hint.
|
||||
// After the row count of the inner table is accurate, this variable will be removed.
|
||||
TiDBMaxRowCountForINLJ = "tidb_max_row_count_for_inlj"
|
||||
|
||||
// tidb_cbo uses new planner with cost based optimizer.
|
||||
TiDBCBO = "tidb_cbo"
|
||||
)
|
||||
|
||||
// Default TiDB system variable values.
|
||||
|
||||
@ -144,6 +144,8 @@ func SetSessionSystemVar(vars *variable.SessionVars, name string, value types.Da
|
||||
vars.BatchInsert = tidbOptOn(sVal)
|
||||
case variable.TiDBMaxRowCountForINLJ:
|
||||
vars.MaxRowCountForINLJ = tidbOptPositiveInt(sVal, variable.DefMaxRowCountForINLJ)
|
||||
case variable.TiDBCBO:
|
||||
vars.CBO = tidbOptOn(sVal)
|
||||
case variable.TiDBCurrentTS:
|
||||
return variable.ErrReadOnly
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func (c *CopClient) IsRequestTypeSupported(reqType, subType int64) bool {
|
||||
return supportExpr(tipb.ExprType(subType))
|
||||
}
|
||||
case kv.ReqTypeDAG:
|
||||
return c.store.mock
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user