Skip to content

Conversation

erimatnor
Copy link
Member

@erimatnor erimatnor commented Aug 19, 2025

Add initial support for (time) partitioning a hypertable on a UUID column. Only version 7 UUIDs are currently supported because of their time ordering properties using the embedded Unix timestamp. Inserting a non-v7 UUID generates an error. This might be relaxed in the future.

Chunk exclusion and filtering on a UUID column work as expected. However, native UUID support for query functions, such as time_bucket and gapfill, is not added as part of this change.

Resolves: #7682

@erimatnor erimatnor added this to the v2.22.0 milestone Aug 19, 2025
@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch from 91eacf6 to 718a991 Compare August 19, 2025 14:24
@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch 2 times, most recently from a9115bd to 0bc32d4 Compare August 19, 2025 15:07
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.36%. Comparing base (3fdd739) to head (f786971).
⚠️ Report is 39 commits behind head on main.

Files with missing lines Patch % Lines
src/time_utils.c 75.00% 2 Missing ⚠️
src/utils.c 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8505      +/-   ##
==========================================
+ Coverage   82.29%   82.36%   +0.06%     
==========================================
  Files         248      248              
  Lines       47544    47533      -11     
  Branches    12077    12076       -1     
==========================================
+ Hits        39128    39149      +21     
- Misses       3507     3529      +22     
+ Partials     4909     4855      -54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch from 0bc32d4 to 4068dfd Compare August 19, 2025 15:27
@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch from 4068dfd to d4a1d77 Compare August 20, 2025 07:46
@erimatnor erimatnor marked this pull request as ready for review August 20, 2025 07:47
@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch 4 times, most recently from 261d0dc to 434cfdc Compare August 20, 2025 09:07
@erimatnor erimatnor changed the title Add support for partitioning on UUIDv7 Support (time) partitioning on UUIDv7 Aug 20, 2025
@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch 2 times, most recently from 618e216 to 4faf618 Compare August 20, 2025 12:31
Copy link
Member

@fabriziomello fabriziomello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch 3 times, most recently from 7254d24 to f8c8577 Compare August 21, 2025 09:24
Add initial support for (time) partitioning a hypertable on a UUID
column. Only version 7 UUIDs are currently supported because of their
time ordering properties using the embedded Unix timestamp. Inserting a
non-v7 UUID generates an error. This might be relaxed in the future.

Chunk exclusion and filtering on a UUID column work as
expected. However, native UUID support for query functions, such as
time_bucket and gapfill, is not added as part of this change.
@erimatnor erimatnor force-pushed the uuid-v7-partitioning branch from f8c8577 to f786971 Compare August 21, 2025 09:49
@erimatnor erimatnor merged commit 9fd6b49 into timescale:main Aug 21, 2025
46 of 47 checks passed
@msqr
Copy link

msqr commented Aug 22, 2025

Hey @erimatnor I'm pleased to see UUIDv7 support making its way in, thank you very much! I noticed your comments in the code:

Since RFC9562 specifies the timestamp as unsigned, the minimum value is
0. Further, the sub-millisecond part cannot be used as time since the bits
are optional and it is not possible to know if they are random or represent
a time fraction. Therefore, the max value is limited to the milliseconds.

and wondered if it would be possible to support the optional fractional millisecond part of the spec by way of some Hypertable configuration, or even a GUC, that asserts that all UUIDs can be treated as such?

@svenklemm svenklemm mentioned this pull request Aug 26, 2025
@erimatnor
Copy link
Member Author

erimatnor commented Aug 27, 2025

Hey @erimatnor I'm pleased to see UUIDv7 support making its way in, thank you very much! I noticed your comments in the code:

Since RFC9562 specifies the timestamp as unsigned, the minimum value is
0. Further, the sub-millisecond part cannot be used as time since the bits
are optional and it is not possible to know if they are random or represent
a time fraction. Therefore, the max value is limited to the milliseconds.

and wondered if it would be possible to support the optional fractional millisecond part of the spec by way of some Hypertable configuration, or even a GUC, that asserts that all UUIDs can be treated as such?

Hey @erimatnor I'm pleased to see UUIDv7 support making its way in, thank you very much! I noticed your comments in the code:

Since RFC9562 specifies the timestamp as unsigned, the minimum value is
0. Further, the sub-millisecond part cannot be used as time since the bits
are optional and it is not possible to know if they are random or represent
a time fraction. Therefore, the max value is limited to the milliseconds.

and wondered if it would be possible to support the optional fractional millisecond part of the spec by way of some Hypertable configuration, or even a GUC, that asserts that all UUIDs can be treated as such?

@msqr The functions we provide to generate UUIDs will add fractional milliseconds by default. There's also an option to extract the higher-precision timestamp if one knows those bits encode time.

philkra pushed a commit that referenced this pull request Sep 2, 2025
## 2.22.0 (2025-09-02)

This release contains performance improvements and bug fixes since the 2.21.3 release. We recommend that you upgrade at the next available opportunity.

**Highlighted features in TimescaleDB v2.22.0**
* Sparse indexes on compressed hypertables can now be explicitly configured via `ALTER TABLE` rather than relying only on internal heuristics. Users can define indexes on multiple columns to improve query performance for their specific workloads.
* [Tech Preview] Continuous aggregates now support the `timescaledb.invalidate_using` option, enabling invalidations to be collected either via triggers on the hypertable or directly from WAL using logical decoding. Aggregates inherit the hypertable’s method if none is specified.  
* UUIDv7 compression and vectorization are now supported. The compression algorithm leverages the timestamp portion for delta-delta compression while storing the random portion separately. The vectorized equality/inequality filters with bulk decompression deliver ~2× faster query performance. The feature is disabled by default (`timescaledb.enable_uuid_compression`) to simplify the downgrading experience, and will be enabled out of the box in the next minor release.
* Hypertables can now be partitioned by UUIDv7 columns, leveraging their embedded timestamps for time-based chunking. We’ve also added utility functions to simplify working with UUIDv7, such as generating values or extracting timestamps - e.g., `uuid_timestamp()` returns a PostgreSQL timestamp from a UUIDv7.
* SkipScan now supports multi-column indexes in not-null mode, improving performance for distinct and ordered queries across multiple keys.  

**Removal of the hypercore table access method**
We made the decision to deprecate the hypercore table access method (TAM) with the 2.21.0 release. Hypercore TAM was an experiment and it did not show the performance improvements we hoped for. It is removed with this release. Upgrades to 2.22.0 and higher are blocked if TAM is still in use. Since TAM’s inception in [2.18.0](https://github.com/timescale/timescaledb/releases/tag/2.18.0), we learned that btrees were not the right architecture. Recent advancements in the columnstore, such as more performant backfilling, SkipScan, adding check constraints, and faster point queries, put the [columnstore](https://www.timescale.com/blog/hypercore-a-hybrid-row-storage-engine-for-real-time-analytics) close to or on par with TAM without needing to store an additional index. We apologize for the inconvenience this action potentially causes and are here to assist you during the migration process.

Migration path

```
do $$
declare
   relid regclass;
begin
   for relid in
       select cl.oid from pg_class cl
       join pg_am am on (am.oid = cl.relam)
       where am.amname = 'hypercore'
   loop
       raise notice 'converting % to heap', relid::regclass;
       execute format('alter table %s set access method heap', relid);
   end loop;
end
$$;
```

**Features**
* [#8247](#8247) Add configurable alter settings for sparse indexes
* [#8306](#8306) Add option for invalidation collection using WAL for continuous aggregates
* [#8340](#8340) Improve selectivity estimates for sparse minmax indexes, so that an index scan on a table in the columnstore is chosen more often when it's beneficial.
* [#8360](#8360) Continuous aggregate multi-hypertable invalidation processing
* [#8364](#8364) Remove hypercore table access method
* [#8371](#8371) Show available timescaledb `ALTER` options when encountering unsupported options
* [#8376](#8376) Change `DecompressChunk` custom node name to `ColumnarScan`
* [#8385](#8385) UUID v7 functions for testing pre PG18
* [#8393](#8393) Add specialized compression for UUIDs. Best suited for UUID v7, but still works with other UUID versions. This is experimental at the moment and backward compatibility is not guaranteed.
* [#8398](#8398) Set default compression settings at compress time
* [#8401](#8401) Support `ALTER TABLE RESET` for compression settings
* [#8414](#8414) Vectorised filtering of UUID Eq and Ne filters, plus bulk decompression of UUIDs
* [#8424](#8424) Block downgrade when orderby setting is `NULL`
* [#8454](#8454) Remove internal unused index helper functions
* [#8494](#8494) Improve job stat history retention policy
* [#8496](#8496) Fix dropping chunks with foreign keys
* [#8505](#8505) Add support for partitioning on UUIDv7
* [#8513](#8513) Support multikey SkipScan when all keys are guaranteed to be non-null
* [#8514](#8514) Concurrent continuous aggregates improvements
* [#8528](#8528) Add the `_timescaledb_functions.chunk_status_text` helper function
* [#8529](#8529) Optimize direct compress status handling

**Bugfixes**
* [#8422](#8422) Don't require `columnstore=false` when using the TimescaleDB Apache 2 Edition
* [#8493](#8493) Change log level of `not null` constraint message
* [#8500](#8500) Fix uniqueness check with generated columns and hypercore
* [#8545](#8545) Fix error in LOCF/Interpolate with out-of-order and repeated columns
* [#8558](#8558) Error out on bad args when processing invalidation
* [#8559](#8559) Fix `timestamp out of range` using `end_offset=NULL` on CAgg refresh policy

**GUCs**
* `enable_multikey_skipscan`: Enable SkipScan for multiple distinct keys, default: on
* `enable_uuid_compression`: Enable UUID compression functionality, default: off
* `cagg_processing_wal_batch_size`: Batch size when processing WAL entries, default: 10000
* `cagg_processing_low_work_mem`: Low working memory limit for continuous aggregate invalidation processing, default: 38.4MB
* `cagg_processing_high_work_mem`: High working memory limit for continuous aggregate invalidation processing, default: 51.2MB

**Thanks**
* @CodeTherapist for reporting an issue where foreign key checks did not work after several insert statements
* @moodgorning for reporting a bug in queries with LOCF/Interpolate using out-of-order columns
* @nofalx for reporting an error when using `end_offset=NULL` on CAgg refresh policy
* @pierreforstmann for fixing a bug that happened when dropping chunks with foreign keys
* @Zaczero for reporting a bug with CREATE TABLE WITH when using the TimescaleDB Apache 2 Edition
@timescale-automation timescale-automation added the released-2.22.0 Released in 2.22.0 label Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released-2.22.0 Released in 2.22.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: support uuid v7 as a partition key
6 participants