Skip to content

Commit

Permalink
Update Row-Level TTL docs to note full support
Browse files Browse the repository at this point in the history
Fixes DOC-4756

Summary of changes:

- Update 'Batch Delete Data with Row-Level TTL' page to note:

  - You can now do per-row TTL using `ttl_expiration_expression`, so we
    mention that and give examples, describe how it's validated

  - Remove at least the resolved limitations from the TTL docs and the
    'Known Limitations' page

  - Remove uses of `ttl_automatic_column' which is no longer used in
    v22.2+

- Update 'WITH storage_parameter' page to use new output / TTL params

- Update 'RESET storage_parameter' page to use new output / TTL params

- Update included table of storage parameters to remove duplication of
  TTL params, instead linking to the canonical location on the TTL docs page
  • Loading branch information
rmloveland committed Oct 13, 2022
1 parent c9c219b commit 8cfdd63
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
- You cannot use [foreign keys](foreign-key.html) to create references to or from a table that uses Row-Level TTL. [cockroachdb/cockroach#76407](https://github.com/cockroachdb/cockroach/issues/76407)
- Any queries you run against tables with Row-Level TTL enabled do not filter out expired rows from the result set (this includes [`UPDATE`s](update.html) and [`DELETE`s](delete.html)). This feature may be added in a future release. For now, follow the instructions in [Filter out expired rows from a selection query](row-level-ttl.html#filter-out-expired-rows-from-a-selection-query).
- <a name="ttl-cannot-be-customized"></a> The TTL cannot be customized based on the values of other columns in the row. [cockroachdb/cockroach#76916](https://github.com/cockroachdb/cockroach/issues/76916)
- Because of the above limitation, adding TTL to large existing tables [can negatively affect performance](row-level-ttl.html#ttl-existing-table-performance-note), since a new column must be created and backfilled for every row. Creating a new table with a TTL is not affected by this limitation.
- The queries executed by Row-Level TTL are not yet optimized for performance:
- They do not use any indexes that may be available on the [`crdb_internal_expiration` column](row-level-ttl.html#crdb-internal-expiration).
- They do not take into account [node localities](cockroach-start.html#locality).
- All deletes are run on a single node, instead of being distributed.
- For details, see [cockroachdb/cockroach#76914](https://github.com/cockroachdb/cockroach/issues/76914)
- If you [override the TTL for a row by setting `crdb_internal_expiration` directly](row-level-ttl.html#set-the-row-level-ttl-for-an-individual-row), and the row is later updated (e.g., using an [`ON UPDATE` expression](create-table.html#on-update-expressions)), the TTL override is lost; it is reset to `now() + ttl_expire_after`.
17 changes: 3 additions & 14 deletions _includes/v22.2/misc/table-storage-parameters.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
| Parameter name | Description | Data type | Default value |
|---------------------+----------------------+-----+------|
| `exclude_data_from_backup` | Excludes the data in this table from any future backups. | Boolean | `false` |
| `ttl` | Signifies if a TTL is active. Automatically set and controls the reset of all TTL-related storage parameters. | N/A | N/A |
| `ttl_automatic_column` | If set, use the value of the `crdb_internal_expiration` hidden column. Always set to `true` and cannot be reset. | Boolean | `true` |
| `ttl_delete_batch_size` | The number of rows to [delete](delete.html) at a time. Minimum: `1`. | Integer | `100` |
| `ttl_delete_rate_limit` | The maximum number of rows to be deleted per second (rate limit). `0` means no limit. | Integer | `0` |
| `ttl_expire_after` | The [interval](interval.html) when a TTL will expire. This parameter is required to enable TTL. Minimum: `'1 microsecond'`.<br/><br/>Use `RESET (ttl)` to remove from the table. | Interval | N/A |
| `ttl_job_cron` | The frequency at which the TTL job runs. | [CRON syntax](https://cron.help) | `'@hourly'` |
| `ttl_label_metrics` | Whether or not [TTL metrics](row-level-ttl.html#ttl-metrics) are labelled by table name (at the risk of added cardinality). | Boolean | `false` |
| `ttl_pause` | If set, stops the TTL job from executing. | Boolean | `false` |
| `ttl_range_concurrency` | The Row-Level TTL queries split up scans by ranges, and this determines how many concurrent ranges are processed at a time. Minimum: `1`. | Integer | `1` |
| `ttl_row_stats_poll_interval` | If set, counts rows and expired rows on the table to report as Prometheus metrics while the TTL job is running. Unset by default, meaning no stats are fetched and reported. | Interval | N/A |
| `ttl_select_batch_size` | The number of rows to [select](select-clause.html) at one time during the row expiration check. Minimum: `1`. | Integer | `500` |
| Parameter name | Description | Data type | Default value |
|----------------------------+----------------------------------------------------------+-----------+---------------|
| `exclude_data_from_backup` | Excludes the data in this table from any future backups. | Boolean | `false` |

The following parameters are included for PostgreSQL compatibility and do not affect how CockroachDB runs:

Expand Down
2 changes: 1 addition & 1 deletion _includes/v22.2/sql/row-level-ttl.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CockroachDB has preview support for Time to Live ("TTL") expiration on table rows, also known as _Row-Level TTL_. Row-Level TTL is a mechanism whereby rows from a table are considered "expired" and can be automatically deleted once those rows have been stored longer than a specified expiration time.
CockroachDB has support for Time to Live ("TTL") expiration on table rows, also known as _Row-Level TTL_. Row-Level TTL is a mechanism whereby rows from a table are considered "expired" and can be automatically deleted once those rows have been stored longer than a specified expiration time.
7 changes: 4 additions & 3 deletions v22.2/reset-storage-parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ SHOW CREATE TABLE ttl_test;
~~~

~~~
table_name | create_statement
-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
table_name | create_statement
-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ttl_test | CREATE TABLE public.ttl_test (
| id UUID NOT NULL DEFAULT gen_random_uuid(),
| description STRING NULL,
| inserted_at TIMESTAMP NULL DEFAULT current_timestamp():::TIMESTAMP,
| crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '3 mons':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '3 mons':::INTERVAL,
| CONSTRAINT ttl_test_pkey PRIMARY KEY (id ASC)
| ) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '3 mons':::INTERVAL)
| ) WITH (ttl = 'on', ttl_expire_after = '3 mons':::INTERVAL, ttl_job_cron = '@hourly')
(1 row)
~~~

Expand Down Expand Up @@ -96,3 +96,4 @@ SHOW CREATE TABLE ttl_test;
- [`RESTORE`](restore.html)
- [`SET` (storage parameter)](set-storage-parameter.html)
- [`WITH` (storage parameter)](with-storage-parameter.html)
- [Batch Delete Expired Data with Row-Level TTL](row-level-ttl.html)
Loading

0 comments on commit 8cfdd63

Please sign in to comment.