Skip to content

Use the collation of unique index on compressed chunks - #10693

Merged
dbeck merged 1 commit into
mainfrom
dbeck/bug_10297
Sep 28, 2026
Merged

dbeck merged 1 commit into
mainfrom
dbeck/bug_10297

Conversation

@dbeck

@dbeck dbeck commented Sep 28, 2026

Copy link
Copy Markdown
Member

During INSERT we need to use the collation of the UNIQUE index to check for dups, and not the columns collation. With non-determinitic collation we can't use vector predicates. This change fixes these for DMLs.

The collations of the index key columns are now collected with the key columns. The in-memory key and the segmentby heap key compare with the index collation. The min/max range keys, the bloom filter and the vector predicates are skipped for a non-deterministic key collation, and the compressed chunk index is used only when its collation equals the key collation or both are deterministic. The last rule also stops rejecting byte-different rows when the column has a non-deterministic collation and the index a deterministic one.

Fixes #10297

@github-actions

Copy link
Copy Markdown

@antekresic, @melihmutlu: please review this pull request.

Powered by pull-review

@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.

πŸ“’ Thoughts on this report? Let us know!

Comment thread tsl/src/compression/compression_dml.c Resolved

@akuzm akuzm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An adjacent thing, do we have proper tests for min/max metadata collation? IIRC I added them but not sure it's enough.

@dbeck

dbeck commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

An adjacent thing, do we have proper tests for min/max metadata collation? IIRC I added them but not sure it's enough.

I added a min/max test

During INSERT we need to use the collation of the UNIQUE index to
check for dups, and not the columns collation. With non-determinitic
collation we can't use vector predicates. This change fixes these
for DMLs.

The collations of the index key columns are now collected with the key
columns. The in-memory key and the segmentby heap key compare with the
index collation. The min/max range keys, the bloom filter and the
vector predicates are skipped for a non-deterministic key collation,
and the compressed chunk index is used only when its collation equals
the key collation or both are deterministic. The last rule also stops
rejecting byte-different rows when the column has a non-deterministic
collation and the index a deterministic one.

Fixes #10297
@dbeck
dbeck merged commit bf849f6 into main Sep 28, 2026
65 of 67 checks passed
@dbeck
dbeck deleted the dbeck/bug_10297 branch September 28, 2026 15:47
@dbeck dbeck added the bug label Sep 28, 2026
@dbeck dbeck added this to the v2.30.2 milestone Sep 28, 2026
@dbeck dbeck added the force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" label Sep 28, 2026
@timescale-automation

Copy link
Copy Markdown
Member

Automated backport to 2.30.x not done: cherry-pick failed.

Git status

HEAD detached at origin/2.30.x
You are currently cherry-picking commit bf849f604.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   .unreleased/fix_10297
	modified:   tsl/src/compression/compression_dml.h
	modified:   tsl/src/compression/compression_scankey.c
	modified:   tsl/test/expected/compressed_collation.out

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   tsl/src/compression/compression_dml.c
	deleted by us:   tsl/test/expected/compressed_collation_icu.out
	both modified:   tsl/test/sql/compressed_collation.sql
	deleted by us:   tsl/test/sql/compressed_collation_icu.sql


Job log

@timescale-automation timescale-automation added the auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) label Sep 28, 2026
@dbeck dbeck removed auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" labels Sep 28, 2026
@timescale-automation

Copy link
Copy Markdown
Member

Automated backport to 2.30.x not done: cherry-pick failed.

Git status

HEAD detached at origin/2.30.x
You are currently cherry-picking commit bf849f604.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   .unreleased/fix_10297
	modified:   tsl/src/compression/compression_dml.h
	modified:   tsl/src/compression/compression_scankey.c

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   tsl/src/compression/compression_dml.c
	both modified:   tsl/test/expected/compressed_collation.out
	deleted by us:   tsl/test/expected/compressed_collation_icu.out
	both modified:   tsl/test/sql/compressed_collation.sql
	deleted by us:   tsl/test/sql/compressed_collation_icu.sql


Job log

@timescale-automation timescale-automation added the auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) label Sep 28, 2026
@dbeck dbeck added the force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" label Sep 28, 2026
@dbeck dbeck removed this from the v2.30.2 milestone Sep 28, 2026
@dbeck dbeck removed auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" labels Sep 28, 2026
@dbeck

dbeck commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

I added this bugfix because the surface area of the bug has increased by the UPDATE/DELETE vectorization change. As we do not backport that feature, I will skip backporting this change too.

@timescale-automation

Copy link
Copy Markdown
Member

Automated backport to 2.30.x not done: cherry-pick failed.

Git status

HEAD detached at origin/2.30.x
You are currently cherry-picking commit bf849f604.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   .unreleased/fix_10297
	modified:   tsl/src/compression/compression_dml.h
	modified:   tsl/src/compression/compression_scankey.c
	modified:   tsl/test/expected/compressed_collation.out
	modified:   tsl/test/expected/compressed_collation_icu.out
	modified:   tsl/test/sql/compressed_collation.sql
	modified:   tsl/test/sql/compressed_collation_icu.sql

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   tsl/src/compression/compression_dml.c


Job log

@timescale-automation timescale-automation added the auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) label Sep 28, 2026
@philkra philkra mentioned this pull request Oct 13, 2026
surister added a commit that referenced this pull request Oct 20, 2026
## 2.31.0 (2026-10-20)

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

**Highlighted features in TimescaleDB v2.31.0**
* Improved performance for `UPDATE` and `DELETE` queries on the
columnstore with vectorized key processing for bulk decompression. The
vectorized aggregation makes DML and recompression operations faster
through parallelism, when a single-chunk query groups by an expression,
resulting in up to 6.5 times faster queries.
* Preview of the new Adaptive Integer Compressor (AIC), which chooses
the best encoding for each block of integer values. This results in the
up to 20% improvement in compression ratios for integers, while queries
benefiting from faster decompression perform up to two times better. AIC
is disabled by default in this release and will be enabled by default in
the `2.32.0` release.

**Loader changes**
This release allows controlling extension hook order to improve
compatibility with other extensions. To ensure pgaudit hooks work
together with timescaledb, pgaudit must come after timescaledb in
`shared_preload_libraries` setting. This loader change, requires a
PostgreSQL restart to enable the compatibility, but if you have no need
to control the hook order, the previous loader version is enough, and
you don't require a service restart.

**Backward-Incompatible Changes**
* [#10666](#10666) Rename
`timescaledb.enable_columnarscan` to
`timescaledb.debug_enable_columnarscan` to make its debugging-only
purpose explicit
* [#10772](#10772) Make the
direct-compress batch sorting GUCs available only in debug builds

**Features**
* [#9737](#9737) Speed up
aggregation with `time_bucket_gapfill()` by performing aggregation per
chunk
* [#10412](#10412) Exclude
chunks at execution time when a hypertable is on the parameterized side
of a nested-loop join
* [#10512](#10512) Block
`ALTER` and `DROP` operations on a granular-refresh tracking column
* [#10517](#10517) Block
granular refresh on a continuous aggregate's materialization hypertable
* [#10546](#10546) Add an
API to disable granular refresh on a hypertable
* [#10588](#10588) Allow
changing the granular refresh offsets of a hypertable
* [#10589](#10589) Add
informational views for granular refresh
* [#10626](#10626) Add the
experimental Adaptive Integer Compressor (AIC)
* [#10632](#10632) Add
`move_to_columnstore()` to compress chunk rows without blocking
concurrent DML
* [#10647](#10647) Report
continuous aggregate refresh statistics
* [#10678](#10678) Use
vectorized key processing for `UPDATE` and `DELETE`
* [#10705](#10705) Use
vectorized aggregation when a single-chunk query groups by an expression
* [#10724](#10724) Use bulk
decompression in `UPDATE`, `DELETE`, and recompression
* [#10730](#10730) Add
`timescaledb.cagg_refresh_stats_level` to control continuous aggregate
refresh statistics
* [#10770](#10770) Answer
eligible `LIMIT 1` queries on compressed chunks from batch metadata
without decompression
* [#10780](#10780) Report
materialized and deleted row counts in the continuous aggregate refresh
statistics
* [#10781](#10781) Flush
continuous aggregate tenant tracking only once per refresh call

**Bugfixes**
* [#10418](#10418) Fix a
hypertable `COPY` crash when pgAudit is enabled
* [#10454](#10454) Make
`SkipScan` use the correct index column when distinct columns are
equivalent
* [#10558](#10558) Fix
wrong query results for chunk skipping columns at the maximum value of a
chunk or after DML on a compressed chunk
* [#10616](#10616) Harden
the `DeferredChunkAppend` deparse and parse cycle
* [#10617](#10617) Use
compressed indexes for joins on segment-by columns with explicit casts,
and prevent sort pushdown when the query and compression keys use
different operator families
* [#10630](#10630) Exclude
hash-partitioned chunks at execution time on the parameterized side of a
nested loop, while respecting nondeterministic collations
* [#10635](#10635) Use the
default B-tree operator when evaluating `first()` and `last()`
aggregates
* [#10639](#10639) Report
rows moved to the columnstore clearly
* [#10651](#10651) Avoid
evaluating expressions over `GROUP BY` columns twice in single-chunk
vectorized aggregation
* [#10693](#10693) Use the
unique index's collation when checking compressed inserts for conflicts
* [#10701](#10701) Mark the
result of `merge_chunks()` unordered when merged chunks can contain
overlapping batches
* [#10715](#10715) Truncate
both the rowstore and columnstore parts of a partially compressed chunk
* [#10718](#10718) Preserve
foreign keys that reference a hypertable during `TRUNCATE ... CASCADE`,
and allow `compress_chunk()` on referenced hypertables
* [#10749](#10749) Fix an
infinite refresh loop for continuous aggregates with variable-sized
buckets and negative offsets
* [#10747](#10747)
Propagate changed parameters when rescanning a `ColumnarIndexScan`
* [#10748](#10748)
Propagate changed parameters when rescanning a `ConstraintAwareAppend`
* [#10795](#10795) Preserve
compression order for rows written before adding an order-by column with
a default
* [#10763](#10763) Fix a
potential `ChunkAppend` segfault when parameterized clauses are removed
from every chunk
* [#10765](#10765) Allow
negative day offsets for the `date` variant of `time_bucket()`
* [#10778](#10778) Do not
use `SkipScan` below a subquery with pseudoconstant qualifiers on the
subquery result
* [#10791](#10791) Fix
potential data loss when direct compression automatically selects
segment-by columns
* [#10797](#10797) Preserve
default values when splitting or merging compressed chunks after `ADD
COLUMN`
* [#10806](#10806) Do not
push parallel-unsafe aggregate expressions below a `Gather` during
chunkwise aggregation
* [#10808](#10808) Speed up
chunk creation in databases with many constraints
* [#10817](#10817) Fix
`DeferredChunkAppend` planning chunk queries with a restricted
`search_path`
* [#10783](#10783) Fix
missing continuous aggregate invalidation when dropping a chunk by
unqualified name
* [#10827](#10827) Validate
the full 64-bit version of statement-tracking callbacks
* [#10830](#10830) Fix
`split_chunk` routing rows to the wrong chunk
* [#10883](#10838) Fix
bloom filters not being used on compressed chunks after renaming a
column
* [#10508](#10508) Fix
missing CAgg invalidations during MERGE UPDATE/DELETE
* [#10844](#10844) Keep
owner of user-defined jobs when hypertable owner changes

**New Settings**
* `timescaledb.cagg_refresh_stats_level`: controls continuous aggregate
refresh statistics. Valid values are `off` (the default), `summary`, and
`verbose_log`.
* `timescaledb.enable_aic_compression`: enables the experimental
Adaptive Integer Compressor. Off by default.
* `timescaledb.enable_columnarscan_metadata_only`: answers eligible
`LIMIT 1` queries on compressed chunks from batch metadata. On by
default.
* `timescaledb.move_to_columnstore_tuple_sort_limit`: limits how many
tuples `move_to_columnstore()` sorts at once to bound memory usage.
Defaults to 0 for no limit.

**Thanks**
* @AdrianAcala for fixing a crash with hypertable `COPY` when pgAudit is
enabled [#10418](#10418)
* @hyeokhee for reporting an error with parallel chunkwise aggregation
and subqueries in aggregates
[#10804](#10804) fixed
via [#10806](#10806)
* @igor2x for reporting a performance regression with joins on
segment-by columns with explicit casts
[#10591](#10591) fixed
via [#10617](#10617)
* @salmanazmat666 for reporting a refresh that could not be cancelled
and ran out of memory
[#10746](#10749) fixed
via [#10806](#10749)
* @jf0x3f for reporting a security issue when changing hypertable owner
fixed via [#10844](#10844)
surister added a commit that referenced this pull request Oct 20, 2026
## 2.31.0 (2026-10-20)

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

**Highlighted features in TimescaleDB v2.31.0**
* Improved performance for `UPDATE` and `DELETE` queries on the
columnstore with vectorized key processing for bulk decompression. The
vectorized aggregation makes DML and recompression operations faster
through parallelism, when a single-chunk query groups by an expression,
resulting in up to 6.5 times faster queries.
* Preview of the new Adaptive Integer Compressor (AIC), which chooses
the best encoding for each block of integer values. This results in the
up to 20% improvement in compression ratios for integers, while queries
benefiting from faster decompression perform up to two times better. AIC
is disabled by default in this release and will be enabled by default in
the `2.32.0` release.

**Loader changes**
This release allows controlling extension hook order to improve
compatibility with other extensions. To ensure pgaudit hooks work
together with timescaledb, pgaudit must come after timescaledb in
`shared_preload_libraries` setting. This loader change, requires a
PostgreSQL restart to enable the compatibility, but if you have no need
to control the hook order, the previous loader version is enough, and
you don't require a service restart.

**Backward-Incompatible Changes**
* [#10666](#10666) Rename
`timescaledb.enable_columnarscan` to
`timescaledb.debug_enable_columnarscan` to make its debugging-only
purpose explicit
* [#10772](#10772) Make the
direct-compress batch sorting GUCs available only in debug builds

**Features**
* [#9737](#9737) Speed up
aggregation with `time_bucket_gapfill()` by performing aggregation per
chunk
* [#10412](#10412) Exclude
chunks at execution time when a hypertable is on the parameterized side
of a nested-loop join
* [#10512](#10512) Block
`ALTER` and `DROP` operations on a granular-refresh tracking column
* [#10517](#10517) Block
granular refresh on a continuous aggregate's materialization hypertable
* [#10546](#10546) Add an
API to disable granular refresh on a hypertable
* [#10588](#10588) Allow
changing the granular refresh offsets of a hypertable
* [#10589](#10589) Add
informational views for granular refresh
* [#10626](#10626) Add the
experimental Adaptive Integer Compressor (AIC)
* [#10632](#10632) Add
`move_to_columnstore()` to compress chunk rows without blocking
concurrent DML
* [#10647](#10647) Report
continuous aggregate refresh statistics
* [#10678](#10678) Use
vectorized key processing for `UPDATE` and `DELETE`
* [#10705](#10705) Use
vectorized aggregation when a single-chunk query groups by an expression
* [#10724](#10724) Use bulk
decompression in `UPDATE`, `DELETE`, and recompression
* [#10730](#10730) Add
`timescaledb.cagg_refresh_stats_level` to control continuous aggregate
refresh statistics
* [#10770](#10770) Answer
eligible `LIMIT 1` queries on compressed chunks from batch metadata
without decompression
* [#10780](#10780) Report
materialized and deleted row counts in the continuous aggregate refresh
statistics
* [#10781](#10781) Flush
continuous aggregate tenant tracking only once per refresh call

**Bugfixes**
* [#10418](#10418) Fix a
hypertable `COPY` crash when pgAudit is enabled
* [#10454](#10454) Make
`SkipScan` use the correct index column when distinct columns are
equivalent
* [#10558](#10558) Fix
wrong query results for chunk skipping columns at the maximum value of a
chunk or after DML on a compressed chunk
* [#10616](#10616) Harden
the `DeferredChunkAppend` deparse and parse cycle
* [#10617](#10617) Use
compressed indexes for joins on segment-by columns with explicit casts,
and prevent sort pushdown when the query and compression keys use
different operator families
* [#10630](#10630) Exclude
hash-partitioned chunks at execution time on the parameterized side of a
nested loop, while respecting nondeterministic collations
* [#10635](#10635) Use the
default B-tree operator when evaluating `first()` and `last()`
aggregates
* [#10639](#10639) Report
rows moved to the columnstore clearly
* [#10651](#10651) Avoid
evaluating expressions over `GROUP BY` columns twice in single-chunk
vectorized aggregation
* [#10693](#10693) Use the
unique index's collation when checking compressed inserts for conflicts
* [#10701](#10701) Mark the
result of `merge_chunks()` unordered when merged chunks can contain
overlapping batches
* [#10715](#10715) Truncate
both the rowstore and columnstore parts of a partially compressed chunk
* [#10718](#10718) Preserve
foreign keys that reference a hypertable during `TRUNCATE ... CASCADE`,
and allow `compress_chunk()` on referenced hypertables
* [#10749](#10749) Fix an
infinite refresh loop for continuous aggregates with variable-sized
buckets and negative offsets
* [#10747](#10747)
Propagate changed parameters when rescanning a `ColumnarIndexScan`
* [#10748](#10748)
Propagate changed parameters when rescanning a `ConstraintAwareAppend`
* [#10795](#10795) Preserve
compression order for rows written before adding an order-by column with
a default
* [#10763](#10763) Fix a
potential `ChunkAppend` segfault when parameterized clauses are removed
from every chunk
* [#10765](#10765) Allow
negative day offsets for the `date` variant of `time_bucket()`
* [#10778](#10778) Do not
use `SkipScan` below a subquery with pseudoconstant qualifiers on the
subquery result
* [#10791](#10791) Fix
potential data loss when direct compression automatically selects
segment-by columns
* [#10797](#10797) Preserve
default values when splitting or merging compressed chunks after `ADD
COLUMN`
* [#10806](#10806) Do not
push parallel-unsafe aggregate expressions below a `Gather` during
chunkwise aggregation
* [#10808](#10808) Speed up
chunk creation in databases with many constraints
* [#10817](#10817) Fix
`DeferredChunkAppend` planning chunk queries with a restricted
`search_path`
* [#10783](#10783) Fix
missing continuous aggregate invalidation when dropping a chunk by
unqualified name
* [#10827](#10827) Validate
the full 64-bit version of statement-tracking callbacks
* [#10830](#10830) Fix
`split_chunk` routing rows to the wrong chunk
* [#10883](#10838) Fix
bloom filters not being used on compressed chunks after renaming a
column
* [#10508](#10508) Fix
missing CAgg invalidations during MERGE UPDATE/DELETE
* [#10844](#10844) Keep
owner of user-defined jobs when hypertable owner changes

**New Settings**
* `timescaledb.cagg_refresh_stats_level`: controls continuous aggregate
refresh statistics. Valid values are `off` (the default), `summary`, and
`verbose_log`.
* `timescaledb.enable_aic_compression`: enables the experimental
Adaptive Integer Compressor. Off by default.
* `timescaledb.enable_columnarscan_metadata_only`: answers eligible
`LIMIT 1` queries on compressed chunks from batch metadata. On by
default.
* `timescaledb.move_to_columnstore_tuple_sort_limit`: limits how many
tuples `move_to_columnstore()` sorts at once to bound memory usage.
Defaults to 0 for no limit.

**Thanks**
* @AdrianAcala for fixing a crash with hypertable `COPY` when pgAudit is
enabled [#10418](#10418)
* @hyeokhee for reporting an error with parallel chunkwise aggregation
and subqueries in aggregates
[#10804](#10804) fixed
via [#10806](#10806)
* @igor2x for reporting a performance regression with joins on
segment-by columns with explicit casts
[#10591](#10591) fixed
via [#10617](#10617)
* @salmanazmat666 for reporting a refresh that could not be cancelled
and ran out of memory
[#10746](#10749) fixed
via [#10806](#10749)
* @jf0x3f for reporting a security issue when changing hypertable owner
fixed via [#10844](#10844)
@timescale-automation timescale-automation added the released-2.31.0 Released in 2.31.0 label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) bug released-2.31.0 Released in 2.31.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unique constraint broken with compressed INSERT and non-deterministic collation

4 participants