From f54250f00dca333e50eb7628997cc69b94606fd3 Mon Sep 17 00:00:00 2001 From: ireneontheway Date: Thu, 16 Jul 2020 11:14:59 +0800 Subject: [PATCH 1/4] Update expression-syntax.md --- expression-syntax.md | 90 ++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 61 deletions(-) diff --git a/expression-syntax.md b/expression-syntax.md index a84fe36fc4ab7..85a0841791c02 100644 --- a/expression-syntax.md +++ b/expression-syntax.md @@ -1,68 +1,36 @@ --- title: Expression Syntax summary: Learn about the expression syntax in TiDB. -aliases: ['/docs/dev/expression-syntax/','/docs/dev/reference/sql/language-structure/expression-syntax/'] --- # Expression Syntax -The following rules define the expression syntax in TiDB. You can find the definition in `parser/parser.y`. The syntax parsing in TiDB is based on Yacc. - -``` -Expression: - singleAtIdentifier assignmentEq Expression - | Expression logOr Expression - | Expression "XOR" Expression - | Expression logAnd Expression - | "NOT" Expression - | Factor IsOrNotOp trueKwd - | Factor IsOrNotOp falseKwd - | Factor IsOrNotOp "UNKNOWN" - | Factor - -Factor: - Factor IsOrNotOp "NULL" - | Factor CompareOp PredicateExpr - | Factor CompareOp singleAtIdentifier assignmentEq PredicateExpr - | Factor CompareOp AnyOrAll SubSelect - | PredicateExpr - -PredicateExpr: - PrimaryFactor InOrNotOp '(' ExpressionList ')' - | PrimaryFactor InOrNotOp SubSelect - | PrimaryFactor BetweenOrNotOp PrimaryFactor "AND" PredicateExpr - | PrimaryFactor LikeOrNotOp PrimaryExpression LikeEscapeOpt - | PrimaryFactor RegexpOrNotOp PrimaryExpression - | PrimaryFactor - -PrimaryFactor: - PrimaryFactor '|' PrimaryFactor - | PrimaryFactor '&' PrimaryFactor - | PrimaryFactor "<<" PrimaryFactor - | PrimaryFactor ">>" PrimaryFactor - | PrimaryFactor '+' PrimaryFactor - | PrimaryFactor '-' PrimaryFactor - | PrimaryFactor '*' PrimaryFactor - | PrimaryFactor '/' PrimaryFactor - | PrimaryFactor '%' PrimaryFactor - | PrimaryFactor "DIV" PrimaryFactor - | PrimaryFactor "MOD" PrimaryFactor - | PrimaryFactor '^' PrimaryFactor - | PrimaryExpression - -PrimaryExpression: - Operand - | FunctionCallKeyword - | FunctionCallNonKeyword - | FunctionCallAgg - | FunctionCallGeneric - | Identifier jss stringLit - | Identifier juss stringLit - | SubSelect - | '!' PrimaryExpression - | '~' PrimaryExpression - | '-' PrimaryExpression - | '+' PrimaryExpression - | "BINARY" PrimaryExpression - | PrimaryExpression "COLLATE" StringName -``` +An expression is a combination of one or more values, operators, or functions. In TiDB, expressions are mainly used in various clauses of the `SELECT` statement, including Group by clause, Where clause, Having clause, Join condition and window function. In addition, some DDL statements will also use expressions, such as the setting of the default values, columns, and partition rules when creating tables. + +The expressions contain the following types: + +- Identifier: For reference, see [Schema object names](/schema-object-names.md). + +- Predicates, numeric values, strings, date expressions: The [Literal values](/literal-values.md) of these types are also expressions. + +- Function calls and window functions: For reference, see [Functions and operators overview](/functions-and-operators/functions-and-operators-overview.md) and [Window functions](/functions-and-operators/window-functions.md) + +- Others: ParamMarker (`?`), system variables, user variables and CASE expressions. + +The following rules are the expression syntax , which is based on the [parser.y](https://github.com/pingcap/parser/blob/master/parser.y) rules of TiDB parser. For the navigable version of the following syntax diagram, please refer to [TiDB SQL Syntax Diagram](https://pingcap.github.io/sqlgram/#Expression). + +**Expression:** + +![Expression](/media/sqlgram/Expression.png) + +**PredicateExpr:** + +![PredicateExpr](/media/sqlgram/PredicateExpr.png) + +**BitExpr:** + +![BitExpr](/media/sqlgram/BitExpr.png) + +**SimpleExpr:** + +![SimpleExpr](/media/sqlgram/SimpleExpr.png) \ No newline at end of file From af7528650271c78a1ee3ef124b9f14dfe16f6378 Mon Sep 17 00:00:00 2001 From: ireneontheway <48651140+ireneontheway@users.noreply.github.com> Date: Thu, 16 Jul 2020 11:21:54 +0800 Subject: [PATCH 2/4] Update expression-syntax.md delete spaces --- expression-syntax.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/expression-syntax.md b/expression-syntax.md index 85a0841791c02..12f3e0186a7d8 100644 --- a/expression-syntax.md +++ b/expression-syntax.md @@ -9,15 +9,15 @@ An expression is a combination of one or more values, operators, or functions. I The expressions contain the following types: -- Identifier: For reference, see [Schema object names](/schema-object-names.md). +- Identifier. For reference, see [Schema object names](/schema-object-names.md). -- Predicates, numeric values, strings, date expressions: The [Literal values](/literal-values.md) of these types are also expressions. +- Predicates, numeric values, strings, date expressions. The [Literal values](/literal-values.md) of these types are also expressions. -- Function calls and window functions: For reference, see [Functions and operators overview](/functions-and-operators/functions-and-operators-overview.md) and [Window functions](/functions-and-operators/window-functions.md) +- Function calls and window functions. For reference, see [Functions and operators overview](/functions-and-operators/functions-and-operators-overview.md) and [Window functions](/functions-and-operators/window-functions.md) -- Others: ParamMarker (`?`), system variables, user variables and CASE expressions. +- ParamMarker (`?`), system variables, user variables and CASE expressions. -The following rules are the expression syntax , which is based on the [parser.y](https://github.com/pingcap/parser/blob/master/parser.y) rules of TiDB parser. For the navigable version of the following syntax diagram, please refer to [TiDB SQL Syntax Diagram](https://pingcap.github.io/sqlgram/#Expression). +The following rules are the expression syntax, which is based on the [parser.y](https://github.com/pingcap/parser/blob/master/parser.y) rules of TiDB parser. For the navigable version of the following syntax diagram, please refer to [TiDB SQL Syntax Diagram](https://pingcap.github.io/sqlgram/#Expression). **Expression:** @@ -33,4 +33,4 @@ The following rules are the expression syntax , which is based on the [parser.y] **SimpleExpr:** -![SimpleExpr](/media/sqlgram/SimpleExpr.png) \ No newline at end of file +![SimpleExpr](/media/sqlgram/SimpleExpr.png) From 87285c2e7149877e4f43eb522b911e7147f79e0b Mon Sep 17 00:00:00 2001 From: ireneontheway <48651140+ireneontheway@users.noreply.github.com> Date: Fri, 17 Jul 2020 13:48:36 +0800 Subject: [PATCH 3/4] Update expression-syntax.md --- expression-syntax.md | 1 + 1 file changed, 1 insertion(+) diff --git a/expression-syntax.md b/expression-syntax.md index 12f3e0186a7d8..a201328eefd86 100644 --- a/expression-syntax.md +++ b/expression-syntax.md @@ -1,6 +1,7 @@ --- title: Expression Syntax summary: Learn about the expression syntax in TiDB. +aliases: ['/docs/dev/expression-syntax/','/docs/dev/reference/sql/language-structure/expression-syntax/'] --- # Expression Syntax From b64b0fdefcbb48bc443a4d267577687001465292 Mon Sep 17 00:00:00 2001 From: ireneontheway <48651140+ireneontheway@users.noreply.github.com> Date: Mon, 20 Jul 2020 10:17:10 +0800 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- expression-syntax.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/expression-syntax.md b/expression-syntax.md index a201328eefd86..782010a16bd9c 100644 --- a/expression-syntax.md +++ b/expression-syntax.md @@ -6,9 +6,9 @@ aliases: ['/docs/dev/expression-syntax/','/docs/dev/reference/sql/language-struc # Expression Syntax -An expression is a combination of one or more values, operators, or functions. In TiDB, expressions are mainly used in various clauses of the `SELECT` statement, including Group by clause, Where clause, Having clause, Join condition and window function. In addition, some DDL statements will also use expressions, such as the setting of the default values, columns, and partition rules when creating tables. +An expression is a combination of one or more values, operators, or functions. In TiDB, expressions are mainly used in various clauses of the `SELECT` statement, including Group by clause, Where clause, Having clause, Join condition and window function. In addition, some DDL statements also use expressions, such as the setting of the default values, columns, and partition rules when creating tables. -The expressions contain the following types: +The expressions can be divided into the following types: - Identifier. For reference, see [Schema object names](/schema-object-names.md). @@ -18,7 +18,7 @@ The expressions contain the following types: - ParamMarker (`?`), system variables, user variables and CASE expressions. -The following rules are the expression syntax, which is based on the [parser.y](https://github.com/pingcap/parser/blob/master/parser.y) rules of TiDB parser. For the navigable version of the following syntax diagram, please refer to [TiDB SQL Syntax Diagram](https://pingcap.github.io/sqlgram/#Expression). +The following rules are the expression syntax, which is based on the [parser.y](https://github.com/pingcap/parser/blob/master/parser.y) rules of TiDB parser. For the navigable version of the following syntax diagram, refer to [TiDB SQL Syntax Diagram](https://pingcap.github.io/sqlgram/#Expression). **Expression:**