Skip to content

feat(parser): add TTL table option grammar (#24552)#24754

Draft
ck89119 wants to merge 5 commits into
matrixorigin:4.0-devfrom
ck89119:issue-24552-parser
Draft

feat(parser): add TTL table option grammar (#24552)#24754
ck89119 wants to merge 5 commits into
matrixorigin:4.0-devfrom
ck89119:issue-24552-parser

Conversation

@ck89119
Copy link
Copy Markdown
Contributor

@ck89119 ck89119 commented Jun 1, 2026

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24552

This is PR 1 of a multi-PR series for native table-level TTL. It only
introduces parser/AST support, so it does not close the issue yet.

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:

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 TTL_ENABLE = 'OFF';
ALTER TABLE t REMOVE TTL;

Changes

  • Grammar (mysql_sql.y / regenerated mysql_sql.go, keywords.go):
    • New non-reserved keywords TTL / TTL_ENABLE / TTL_JOB_INTERVAL
      (still usable as identifiers).
    • Three table_option branches. The TTL expression is parsed as a
      column + INTERVAL n unit binary expression. = is optional.
    • alter_option branch REMOVE TTL. Because table_option already flows
      into alter_option, the set/modify forms work for ALTER TABLE without
      extra grammar.
  • AST (tree/create.go, tree/alter.go):
    • TableOptionTTL / TableOptionTTLEnable / TableOptionTTLJobInterval
    • AlterTableRemoveTTL
  • Tests: dialect round-trip (parse -> format -> parse), AST assertions,
    invalid-syntax cases, and tree-package Format/Free unit tests. New
    code is covered at 100%.

Scope / safety

The plan layer (build_ddl.go) already rejects any unrecognized table option
with a clear not supported error, so until the follow-up PRs wire up
persistence 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-check and go test ./pkg/sql/parsers/... all pass with
no grammar conflicts.

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>
@ck89119 ck89119 requested a review from iamlinjunhong as a code owner June 1, 2026 08:02
@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot requested a review from XuPeng-SH June 1, 2026 08:02
…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>
…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-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants