diff --git a/executor/prepared.go b/executor/prepared.go index bdf1e5288d..c8d14d1fce 100644 --- a/executor/prepared.go +++ b/executor/prepared.go @@ -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) diff --git a/go.mod b/go.mod index 0b9abad995..3b73b6b37e 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 64cff9abb8..49b803b9f1 100644 --- a/go.sum +++ b/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= diff --git a/session/session.go b/session/session.go index 3ed02bc721..98184192e9 100644 --- a/session/session.go +++ b/session/session.go @@ -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 { diff --git a/session/tidb.go b/session/tidb.go index 6fafe9caed..08703d12ae 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -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 { diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 4b413bec8d..31ce4ed71e 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -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 diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 7ac771a579..40a4b7cf6c 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -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)}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 7a01356e32..2038881a50 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -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. diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index ed601b9f86..ad81e0ff4d 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -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 }