*: add a session variable for window function parser (#8511)
This commit is contained in:
@ -112,7 +112,9 @@ func (e *PrepareExec) Next(ctx context.Context, chk *chunk.Chunk) error {
|
||||
if sqlParser, ok := e.ctx.(sqlexec.SQLParser); ok {
|
||||
stmts, err = sqlParser.ParseSQL(e.sqlText, charset, collation)
|
||||
} else {
|
||||
stmts, err = parser.New().Parse(e.sqlText, charset, collation)
|
||||
p := parser.New()
|
||||
p.EnableWindowFunc(vars.EnableWindowFunction)
|
||||
stmts, err = p.Parse(e.sqlText, charset, collation)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Trace(err)
|
||||
|
||||
2
go.mod
2
go.mod
@ -47,7 +47,7 @@ require (
|
||||
github.com/pingcap/errors v0.11.0
|
||||
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e
|
||||
github.com/pingcap/kvproto v0.0.0-20181105061835-1b5d69cd1d26
|
||||
github.com/pingcap/parser v0.0.0-20181126111651-a38036a60de7
|
||||
github.com/pingcap/parser v0.0.0-20181204031237-721bcaad1aeb
|
||||
github.com/pingcap/pd v2.1.0-rc.4+incompatible
|
||||
github.com/pingcap/tidb-tools v0.0.0-20181112132202-4860a0d5de03
|
||||
github.com/pingcap/tipb v0.0.0-20181012112600-11e33c750323
|
||||
|
||||
4
go.sum
4
go.sum
@ -107,8 +107,8 @@ github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e h1:P73/4dPCL96rG
|
||||
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw=
|
||||
github.com/pingcap/kvproto v0.0.0-20181105061835-1b5d69cd1d26 h1:JK4VLNYbSn36QSbCnqALi2ySXdH0DfcMssT/zmLf4Ls=
|
||||
github.com/pingcap/kvproto v0.0.0-20181105061835-1b5d69cd1d26/go.mod h1:0gwbe1F2iBIjuQ9AH0DbQhL+Dpr5GofU8fgYyXk+ykk=
|
||||
github.com/pingcap/parser v0.0.0-20181126111651-a38036a60de7 h1:E/T5kIrtzipWJhN/YREI+f3PiP6Uw5boE4KRcD+zVvo=
|
||||
github.com/pingcap/parser v0.0.0-20181126111651-a38036a60de7/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
|
||||
github.com/pingcap/parser v0.0.0-20181204031237-721bcaad1aeb h1:GDXh3Y82QF1mRB1nQi2+4QJsIsPEk3BIbl6YSRJIVk0=
|
||||
github.com/pingcap/parser v0.0.0-20181204031237-721bcaad1aeb/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
|
||||
github.com/pingcap/pd v2.1.0-rc.4+incompatible h1:/buwGk04aHO5odk/+O8ZOXGs4qkUjYTJ2UpCJXna8NE=
|
||||
github.com/pingcap/pd v2.1.0-rc.4+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E=
|
||||
github.com/pingcap/tidb-tools v0.0.0-20181112132202-4860a0d5de03 h1:xVuo5U+l6XAWHsb+xhkZ8zz3jerIwDfCHAO6kR2Kaog=
|
||||
|
||||
@ -803,6 +803,7 @@ func (s *session) ParseSQL(ctx context.Context, sql, charset, collation string)
|
||||
defer span1.Finish()
|
||||
}
|
||||
s.parser.SetSQLMode(s.sessionVars.SQLMode)
|
||||
s.parser.EnableWindowFunc(s.sessionVars.EnableWindowFunction)
|
||||
return s.parser.Parse(sql, charset, collation)
|
||||
}
|
||||
|
||||
@ -1406,7 +1407,8 @@ const loadCommonGlobalVarsSQL = "select HIGH_PRIORITY * from mysql.global_variab
|
||||
variable.TiDBMaxChunkSize + quoteCommaQuote +
|
||||
variable.TiDBEnableCascadesPlanner + quoteCommaQuote +
|
||||
variable.TiDBRetryLimit + quoteCommaQuote +
|
||||
variable.TiDBDisableTxnAutoRetry + "')"
|
||||
variable.TiDBDisableTxnAutoRetry + quoteCommaQuote +
|
||||
variable.TiDBEnableWindowFunction + "')"
|
||||
|
||||
// loadCommonGlobalVariablesIfNeeded loads and applies commonly used global variables for the session.
|
||||
func (s *session) loadCommonGlobalVariablesIfNeeded() error {
|
||||
|
||||
@ -124,6 +124,7 @@ func Parse(ctx sessionctx.Context, src string) ([]ast.StmtNode, error) {
|
||||
log.Debug("compiling", src)
|
||||
charset, collation := ctx.GetSessionVars().GetCharsetInfo()
|
||||
p := parser.New()
|
||||
p.EnableWindowFunc(ctx.GetSessionVars().EnableWindowFunction)
|
||||
p.SetSQLMode(ctx.GetSessionVars().SQLMode)
|
||||
stmts, err := p.Parse(src, charset, collation)
|
||||
if err != nil {
|
||||
|
||||
@ -311,6 +311,9 @@ type SessionVars struct {
|
||||
// EnableCascadesPlanner enables the cascades planner.
|
||||
EnableCascadesPlanner bool
|
||||
|
||||
// EnableWindowFunction enables the window function.
|
||||
EnableWindowFunction bool
|
||||
|
||||
// DDLReorgPriority is the operation priority of adding indices.
|
||||
DDLReorgPriority int
|
||||
|
||||
@ -692,6 +695,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error {
|
||||
atomic.StoreInt32(&ForcePriority, int32(mysql.Str2Priority(val)))
|
||||
case TiDBEnableRadixJoin:
|
||||
s.EnableRadixJoin = TiDBOptOn(val)
|
||||
case TiDBEnableWindowFunction:
|
||||
s.EnableWindowFunction = TiDBOptOn(val)
|
||||
}
|
||||
s.systems[name] = val
|
||||
return nil
|
||||
|
||||
@ -664,6 +664,7 @@ var defaultSysVars = []*SysVar{
|
||||
{ScopeGlobal | ScopeSession, TiDBDisableTxnAutoRetry, boolToIntStr(DefTiDBDisableTxnAutoRetry)},
|
||||
{ScopeGlobal | ScopeSession, TiDBConstraintCheckInPlace, boolToIntStr(DefTiDBConstraintCheckInPlace)},
|
||||
{ScopeSession, TiDBOptimizerSelectivityLevel, strconv.Itoa(DefTiDBOptimizerSelectivityLevel)},
|
||||
{ScopeGlobal | ScopeSession, TiDBEnableWindowFunction, boolToIntStr(DefEnableWindowFunction)},
|
||||
/* The following variable is defined as session scope but is actually server scope. */
|
||||
{ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)},
|
||||
{ScopeSession, TiDBSlowLogThreshold, strconv.Itoa(logutil.DefaultSlowThreshold)},
|
||||
|
||||
@ -215,6 +215,9 @@ const (
|
||||
// tidb_constraint_check_in_place indicates to check the constraint when the SQL executing.
|
||||
// It could hurt the performance of bulking insert when it is ON.
|
||||
TiDBConstraintCheckInPlace = "tidb_constraint_check_in_place"
|
||||
|
||||
// tidb_enable_window_function is used to control whether to enable the window function.
|
||||
TiDBEnableWindowFunction = "tidb_enable_window_function"
|
||||
)
|
||||
|
||||
// Default TiDB system variable values.
|
||||
@ -261,6 +264,7 @@ const (
|
||||
DefTiDBHashAggFinalConcurrency = 4
|
||||
DefTiDBForcePriority = mysql.NoPriority
|
||||
DefTiDBUseRadixJoin = false
|
||||
DefEnableWindowFunction = false
|
||||
)
|
||||
|
||||
// Process global variables.
|
||||
|
||||
@ -314,7 +314,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
|
||||
case AutocommitVar, TiDBSkipUTF8Check, TiDBOptAggPushDown,
|
||||
TiDBOptInSubqToJoinAndAgg,
|
||||
TiDBBatchInsert, TiDBDisableTxnAutoRetry, TiDBEnableStreaming,
|
||||
TiDBBatchDelete, TiDBEnableCascadesPlanner:
|
||||
TiDBBatchDelete, TiDBEnableCascadesPlanner, TiDBEnableWindowFunction:
|
||||
if strings.EqualFold(value, "ON") || value == "1" || strings.EqualFold(value, "OFF") || value == "0" {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user