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 3 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
81 changes: 25 additions & 56 deletions sql-statements/sql-statement-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,51 @@ 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" WhereClauseOptional

![SelectStmtFieldList](/media/sqlgram/SelectStmtFieldList.png)
SelectStmtFromTable ::=
"SELECT" SelectStmtOpts Field ("," Field)* "FROM" TableRefsClause WhereClauseOptional SelectStmtGroup HavingClause WindowClauseOptional
dveeden marked this conversation as resolved.
Show resolved Hide resolved

**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:**
WhereClauseOptional ::=
WhereClause?

![OrderByOptional](/media/sqlgram/OrderByOptional.png)
SelectStmtGroup ::=
GroupByClause?

**SelectStmtLimit:**
SelectStmtLimit ::=
("LIMIT" LimitOption ( ("," | "OFFSET") LimitOption )?
| "FETCH" ("FIRST" | "NEXT") LimitOption ("ROW" | "ROWS") "ONLY" )
dveeden marked this conversation as resolved.
Show resolved Hide resolved

![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**
WindowClauseOptional ::=
"WINDOW" WindowDefinition ("," WindowDefinition)*

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

**TableSampleOpt**

```ebnf+diagram
TableSampleOpt ::=
'TABLESAMPLE' 'REGIONS()'
dveeden marked this conversation as resolved.
Show resolved Hide resolved
```
Expand Down
Loading