*: add cbo switch. (#3877)

This commit is contained in:
Han Fei
2017-08-03 19:28:17 +08:00
committed by GitHub
parent 9a40975437
commit 8a1e93bc8e
7 changed files with 13 additions and 2 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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,
}
}

View File

@ -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)},

View File

@ -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.

View File

@ -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
}

View File

@ -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
}