Skip to content

feat(plan): persist and reflect TTL table options (#24552)#24779

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

feat(plan): persist and reflect TTL table options (#24552)#24779
ck89119 wants to merge 5 commits into
matrixorigin:4.0-devfrom
ck89119:issue-24552-tabledef

Conversation

@ck89119
Copy link
Copy Markdown
Contributor

@ck89119 ck89119 commented Jun 2, 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

PR 2 of a multi-PR series for native table-level TTL. Depends on #24754
(parser layer). Until #24754 merges, this PR's diff also contains the parser
commits from #24754 — please review only the plan-layer commit here, or review
after #24754 is merged (the diff will then reduce to PR-2 only). Does not close
the issue.

What this PR does / why we need it:

Second step of native table-level TTL: persist the TTL table options into the
table metadata on CREATE TABLE, and reflect them back in SHOW CREATE TABLE.

Changes

  • buildCreateTable (build_ddl.go): validate and persist TTL /
    TTL_ENABLE / TTL_JOB_INTERVAL as table properties
    (rel_ttl / rel_ttl_enable / rel_ttl_job_interval), reusing the same
    property mechanism as COMMENT. Defaults are applied (enable=on,
    job_interval=1h). Invalid usage is rejected:
    • TTL column must exist and be DATE / DATETIME / TIMESTAMP
    • TTL_JOB_INTERVAL must be a positive duration (e.g. 1h, 30m)
    • TTL_ENABLE must be on / off
    • TTL_ENABLE / TTL_JOB_INTERVAL without a TTL expression is an error
    • TTL is rejected on temporary / cluster / dynamic / external tables
  • ConstructCreateTableSQL (build_show_util.go): reflect the TTL clause,
    round-trippable through the parser; the TTL keys are excluded from the
    generic PROPERTIES() clause.
  • ttl_util.go: TTL expression / option validation helpers.
  • pkg/catalog/types.go: new SystemRelAttr_TTL* property-key constants.
  • Tests: validation, persistence with defaults, error cases, and
    SHOW CREATE TABLE round-trip.

Scope / safety

ALTER TABLE ... TTL is still rejected as not-supported (lands in a later PR),
as is the background expiry job. No behavior change for tables without TTL.

make, make static-check and go test ./pkg/sql/plan/... all pass.

ck89119 and others added 4 commits June 1, 2026 14:40
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>
…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>
PR-2 of native table-level TTL, building on the parser layer (PR-1).

- buildCreateTable: validate and persist TTL / TTL_ENABLE /
  TTL_JOB_INTERVAL as table properties (rel_ttl / rel_ttl_enable /
  rel_ttl_job_interval), applying defaults (enable=on, job_interval=1h)
  and rejecting invalid combinations (non-time column, bad interval,
  a sub-option without TTL, temporary/cluster/dynamic/external tables)
- SHOW CREATE TABLE: reflect the TTL clause, round-trippable through
  the parser
- ttl_util.go: TTL expression / option validation helpers
- tests: validation, persistence with defaults, error cases, SHOW
  round-trip

ALTER TABLE TTL persistence and the background expiry job land in
later PRs.

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