Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ebnf select #17275

Merged
merged 8 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 23 additions & 59 deletions sql-statements/sql-statement-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,84 +10,48 @@ The `SELECT` statement is used to read data from TiDB.

## Synopsis

**SelectStmt:**

![SelectStmt](/media/sqlgram/SelectStmt.png)

**FromDual:**

![FromDual](/media/sqlgram/FromDual.png)

**SelectStmtOpts:**
```ebnf+diagram
SelectStmt ::=
( SelectStmtBasic | SelectStmtFromDualTable | SelectStmtFromTable )
OrderBy? SelectStmtLimit? SelectLockOpt? SelectStmtIntoOption

![SelectStmtOpts](/media/sqlgram/SelectStmtOpts.png)
SelectStmtBasic ::=
"SELECT" SelectStmtOpts Field ("," Field)* ( "HAVING" Expression)?

**SelectStmtFieldList:**
SelectStmtFromDualTable ::=
"SELECT" SelectStmtOpts Field ("," Field)* "FROM" "DUAL" WhereClause?

![SelectStmtFieldList](/media/sqlgram/SelectStmtFieldList.png)
SelectStmtFromTable ::=
"SELECT" SelectStmtOpts Field ("," Field)* "FROM" TableRefsClause
WhereClause? GroupByClause? ( "HAVING" Expression)? WindowClause?

**TableRefsClause:**
SelectStmtOpts ::=
TableOptimizerHints DefaultFalseDistictOpt PriorityOpt SelectStmtSQLSmallResult
SelectStmtSQLBigResult SelectStmtSQLBufferResult SelectStmtSQLCache SelectStmtCalcFoundRows
SelectStmtStraightJoin

```ebnf+diagram
TableRefsClause ::=
TableRef AsOfClause? ( ',' TableRef AsOfClause? )*

AsOfClause ::=
'AS' 'OF' 'TIMESTAMP' Expression
```

**WhereClauseOptional:**

![WhereClauseOptional](/media/sqlgram/WhereClauseOptional.png)

**SelectStmtGroup:**

![SelectStmtGroup](/media/sqlgram/SelectStmtGroup.png)

**HavingClause:**

![HavingClause](/media/sqlgram/HavingClause.png)

**OrderByOptional:**

![OrderByOptional](/media/sqlgram/OrderByOptional.png)
SelectStmtLimit ::=
("LIMIT" LimitOption ( ("," | "OFFSET") LimitOption )?
| "FETCH" ("FIRST" | "NEXT") LimitOption? ("ROW" | "ROWS") "ONLY" )

**SelectStmtLimit:**

![SelectStmtLimit](/media/sqlgram/SelectStmtLimit.png)

**FirstOrNext:**

![FirstOrNext](/media/sqlgram/FirstOrNext.png)

**FetchFirstOpt:**

![FetchFirstOpt](/media/sqlgram/FetchFirstOpt.png)

**RowOrRows:**

![RowOrRows](/media/sqlgram/RowOrRows.png)

**SelectLockOpt:**

```ebnf+diagram
SelectLockOpt ::=
( ( 'FOR' 'UPDATE' ( 'OF' TableList )? 'NOWAIT'? )
| ( 'LOCK' 'IN' 'SHARE' 'MODE' ) )?
( 'FOR' 'UPDATE' ( 'OF' TableList )? 'NOWAIT'?
| 'LOCK' 'IN' 'SHARE' 'MODE' )

TableList ::=
TableName ( ',' TableName )*
```

**WindowClauseOptional**
WindowClause ::=
"WINDOW" WindowDefinition ("," WindowDefinition)*

![WindowClauseOptional](/media/sqlgram/WindowClauseOptional.png)

**TableSampleOpt**

```ebnf+diagram
TableSampleOpt ::=
'TABLESAMPLE' 'REGIONS()'
'TABLESAMPLE' 'REGIONS' '(' ')'
```

## Description of the syntax elements
Expand Down
Loading