Skip to content

Conversation

@rafiss
Copy link
Collaborator

@rafiss rafiss commented Dec 12, 2025

No description provided.

This allow the function to be used by the declarative schemachanger in a
future commit.

Release note: None
…a changer

Previously, the declarative schema changer did not support the
ttl_expiration_expression storage parameter, requiring a fallback to the
legacy schema changer when users wanted to define custom TTL expressions.

This commit adds support for ttl_expiration_expression by:

1. Adding a ValidateTTLExpirationExpression method to the builder state
   that validates the expression type-checks as TIMESTAMPTZ, is not
   volatile, and references valid columns.

2. Adding CreateRowLevelTTLSchedule as a new deferred mutation operation
   that creates the TTL scheduled job when adding TTL to a table that
   doesn't already have one.

3. Extending metadataUpdater with CreateRowLevelTTLSchedule that creates
   the scheduled job and updates the table descriptor with the schedule ID.

4. Adding a notice when TTL is enabled on tables with inbound foreign keys
   that have cascading delete actions, warning about performance implications.

This is part of the ongoing effort to support all TTL storage parameters
in the declarative schema changer.

Release note: None

Epic: None
This adds end to end tests that make sure rolling back TTL storage
paramters works.

This also adds scplan tests to make sure the correct mutations are
performed.

Release note: None
Refactor the function so it accepts lookup functions rather than a raw
table descriptor. This will allow the schema changer to use it for
validating columns that are added in the same operation.

Release note: None
Previously, the declarative schema changer did not support setting
`ttl_expire_after` storage parameters, which meant tables with TTL
using duration expressions would fall back to the legacy schema changer.
This was a gap in TTL functionality for the declarative schema changer.

To address this, this patch adds support for `ttl_expire_after` by:

1. Adding helper functions to manage the `crdb_internal_expiration`
   hidden column that TTL requires when using `ttl_expire_after`:
   - `addTTLColumn`: Creates the column with proper default and on-update
     expressions using `sanitizeColumnExpression` for type annotation
   - `dropTTLColumn`: Removes the column when TTL is reset
   - `updateTTLColumnExpressions`: Updates expressions when the interval
     changes

2. Updating `applyTTLStorageParamsSet` to detect when `ttl_expire_after`
   is being added, changed, or switched from `ttl_expiration_expression`,
   and performing the appropriate column operations.

3. Updating `applyTTLStorageParamsReset` to drop the TTL column when
   resetting `ttl` or `ttl_expire_after`.

4. Improving error messages in `ValidateTTLExpirationColumn` to show
   both expected and actual expressions for easier debugging.

5. Marking legacy-schema-changer-specific concurrent schema change tests
   with `onlyif config local-legacy-schema-changer` since the declarative
   schema changer handles these cases differently.

Fixes: cockroachdb#122379
Release note: None
@blathers-crl
Copy link

blathers-crl bot commented Dec 12, 2025

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants