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
support SELECT FROM TABLESAMPLE syntax #1071
Conversation
parser.y
Outdated
@@ -7280,6 +7291,74 @@ SelectStmtFromTable: | |||
$$ = st | |||
} | |||
|
|||
SelectStmtFromTableSample: | |||
SelectStmtBasic "FROM" TableName PartitionNameListOpt TableAsNameOpt "TABLESAMPLE" TableSampleMethodOpt '(' Expression TableSampleUnitOpt ')' RepeatableOpt WhereClauseOptional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better attach this to this line to support JOIN:
TableFactor:
TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt TableSampleOpt # <--
this means the TableSample is part of the ast.TableSource
or ast.TableName
.
their use in UPDATE and DELETE can be rejected after parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest LGTM
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
@@ -7805,11 +7888,14 @@ TableRef: | |||
| JoinTable | |||
|
|||
TableFactor: | |||
TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt | |||
TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt TableSampleOpt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should append a warning? since we don't support them all in TiDB actually...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related work is done in TiDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* support SELECT FROM TABLESAMPLE syntax * refine naming * make table sample clause as a part of TableFactor * address comment
What problem does this PR solve?
See pingcap/tidb#20567.
What is changed and how it works?
The syntax for "TABLESAMPLE" is as follows:
I putSampleClause
as a special part of rule inSelectStmt
instead ofTableRef
, becauseTableRef
is also used inUPDATE/DELETE
statements and we don't want to supportTABLESAMPLE
for them.However, this also prevent theJOIN
clause to be syntax-checked:Check List
Tests
Code changes
N/A
Side effects
N/A
Related changes
N/A