feat(parser): add TTL table option grammar (#24552)#24754
Draft
ck89119 wants to merge 5 commits into
Draft
Conversation
First step of native table-level TTL (auto-expiry), parser layer only,
syntax aligned with TiDB:
CREATE TABLE t (id INT, ts TIMESTAMP)
TTL = `ts` + INTERVAL 7 DAY
TTL_ENABLE = 'ON'
TTL_JOB_INTERVAL = '1h';
ALTER TABLE t TTL = `ts` + INTERVAL 30 DAY;
ALTER TABLE t REMOVE TTL;
Changes:
- New non-reserved keywords TTL / TTL_ENABLE / TTL_JOB_INTERVAL
- table_option branches for the three options; the TTL expression is
stored as a `col + INTERVAL n unit` binary expression
- alter_option `REMOVE TTL` (table_option already flows into
alter_option, so set/modify works for ALTER without extra nodes)
- tree nodes TableOptionTTL / TableOptionTTLEnable /
TableOptionTTLJobInterval and AlterTableRemoveTTL
- unit tests: dialect roundtrip + AST assertions + tree Format/Free
The plan layer still rejects these options as not-supported; persistence
to TableDef and the background expiry job land in later PRs.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
…igin#24552) Address review feedback on PR matrixorigin#24754: - TableOptionTTLEnable / TableOptionTTLJobInterval Format now escape embedded single quotes (' -> '') so the output re-parses - tree test now exercises the real `col + INTERVAL n unit` output path and the quote-escaping path (instead of a plain numeric literal) - dialect test now covers ALTER TABLE TTL options written without `=` Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7 tasks
…atrixorigin#24552) The reset() switches of CreateTable / AlterTable / Partition / SubPartition gained TTL `case` branches in PR-1, but no test freed an AST holding TTL options, so those branches were uncovered and the CI diff-coverage gate failed (create.go / alter.go at 66.7%). Add tests that build CreateTable (Options + DTOptions), AlterTable and Partition / SubPartition holding the TTL options and invoke reset(), covering all the new Free branches. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24552
What this PR does / why we need it:
First step toward native table-level TTL (automatic row expiry). This PR adds
parser and AST support only, with syntax aligned with TiDB:
Changes
mysql_sql.y/ regeneratedmysql_sql.go,keywords.go):TTL/TTL_ENABLE/TTL_JOB_INTERVAL(still usable as identifiers).
table_optionbranches. The TTL expression is parsed as acolumn + INTERVAL n unitbinary expression.=is optional.alter_optionbranchREMOVE TTL. Becausetable_optionalready flowsinto
alter_option, the set/modify forms work forALTER TABLEwithoutextra grammar.
tree/create.go,tree/alter.go):TableOptionTTL/TableOptionTTLEnable/TableOptionTTLJobIntervalAlterTableRemoveTTLinvalid-syntax cases, and
tree-packageFormat/Freeunit tests. Newcode is covered at 100%.
Scope / safety
The plan layer (
build_ddl.go) already rejects any unrecognized table optionwith a clear
not supportederror, so until the follow-up PRs wire uppersistence and the background expiry job, using the new syntax fails cleanly
rather than silently doing nothing. No behavior change for existing SQL.
make,make static-checkandgo test ./pkg/sql/parsers/...all pass withno grammar conflicts.