Repository navigation
Chimp compression for floating point data - #66467
panagiotisl wants to merge 77 commits into
Conversation
|
Need to add functional tests (with CREATE TABLE), not only unit tests. |
|
I've copied an existing functional test of Gorilla to create a new functional test for Chimp. We can discuss in Slack if more tests are required. |
|
Ok, it will be enough for tests. |
|
I have fixed the bug that was causing the previous test to fail, and I've also added Chimp in more tests where Gorilla and FPC are used. One of them is failing, so I will try to figure out why. |
|
After the updates I can execute all new tests successfully locally and I also see a successful execution in CI logs. However, there is a failed new test in the Stateless tests flaky check (asan) which I am not sure how to explain or reproduce. The same tests passes in Stateless tests (release, old analyzer, s3, DatabaseReplicated) and Fast test so I doubt it has to do something with the code of this PR. Logs below: |
|
It means that the code is not memory-safe: https://s3.amazonaws.com/clickhouse-test-reports/66467/6b5097aed70edbd54f6167399005907fd3c6c02a/stateless_tests__asan__[2_2]/stderr.log It should be fixed (or rewritten in Rust). |
|
There was indeed a memory-related bug in the new code. I have fixed it and I have also fixed an issue with an old test I have extended, that was creating and removing files with a fixed name and could not run successfully in parallel. |
|
Update (pushed
Verified locally on the merged branch: full codec gtest suite (11306 tests) passes, |
# Conflicts: # tests/queries/0_stateless/01222_system_codecs.reference
The `Chimp` method-byte paragraph left two consecutive blank lines before the `Checksum` section, which the docs `markdownlint` check rejects with `MD012/no-multiple-blanks`.
`isReadyToCompress` was only checked in `validateCodecAndGetPreprocessedAST`, so codecs built through `CompressionCodecFactory::get(ast, nullptr)` bypassed it. Every no-column codec built there is a write codec — the marks, primary key and default compression codec settings, `temporary_files_codec`, the text index marks codec and `TTL ... RECOMPRESS CODEC(...)` at merge time — and a `Chimp` built without a column type has an undetermined data width, so it can describe and decompress itself but cannot compress. Rejecting it in the factory makes the failure happen where the codec is configured, instead of serializing `CODEC(Chimp(0))` and failing on the first write, merge or spill. The check sits next to the existing lossy-codec check: after the `only_generic` filter, so it does not fire for the structural substreams that skip non-generic codecs, and inside the per-element loop, so a chained `Chimp, LZ4` is rejected too. The decompression path (`CompressionCodecFactory::get(uint8_t)`) and `fillCodecDescriptions` build codecs directly through the creator and never reach this point, so reading existing data and `system.codecs` are unaffected. Added `ChimpTest.NoColumnWriteCodecIsRejected`: bare `Chimp` and both chain positions are rejected without a column type, while an explicit width (`Chimp(4)`, `Chimp(8)`) or a `Float32`/`Float64` column type is accepted, and width-independent codecs are untouched.
|
Update (pushed
Verified locally on the merged branch: |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 380/407 (93.37%) · Uncovered code |
A floating-point time series codec (`Chimp`, `Gorilla`, `FPC`, `ALP`, `SZ3`) is resolved and applied per substream, so for `Tuple(Float64, UInt64)` the codec is applied to the `UInt64` element as well. `innerDataTypeIsFloat` accepted a tuple as soon as *any* element was floating-point, so such a column was created with default settings and the `allow_suspicious_codecs` check was bypassed for the remaining elements — contradicting the documented contract. Require every tuple element to be floating-point instead. Homogeneous composites (`Nullable`, `Array`, `Tuple` of `Float32`/`Float64`) are unaffected; a mixed composite now needs `allow_suspicious_codecs`, like any other non-floating-point type. `ATTACH` is unaffected because the sanity check is disabled there, so existing tables keep loading. Address AI review on ClickHouse#66467
|
🕵 Update (pushed
Verified locally on the merged branch: The only thread still open is @scanhex12's |
| /// constructible for method-byte decoding and `system.codecs`, but cannot compress. | ||
| /// Reject them now, instead of persisting a codec that would only fail later during | ||
| /// a background recompression merge. | ||
| if (!result_codec->isReadyToCompress()) |
There was a problem hiding this comment.
TTL ... RECOMPRESS CODEC(Chimp(8)) still slips through this no-column path even with the default allow_suspicious_codecs = 0. An explicit width makes isReadyToCompress() true, so the new guard does not fire, and the floating-point sanity check below only runs when column_type is known.
That means a definition like
SET allow_experimental_codecs = 1;
CREATE TABLE t
(
dt DateTime,
s String
)
ENGINE = MergeTree ORDER BY tuple()
TTL dt + INTERVAL 1 DAY RECOMPRESS CODEC(Chimp(8));is accepted today even though the docs and the new mixed-composite tightening both say applying a floating-point time-series codec to non-floating-point data requires allow_suspicious_codecs. TTLDescription validates RECOMPRESS with column_type = {}, MergeTreeData::getCompressionCodecForPart later uses that AST as the part default codec, and the writer only filters out structural substreams, so regular non-float streams still get Chimp(8).
Can we add an analogous no-column suspicious-codec check here for isFloatingPointTimeSeriesCodec() (or otherwise make RECOMPRESS/default write codecs require allow_suspicious_codecs for explicit-width Chimp(4|8) too), plus a negative regression for a non-float RECOMPRESS CODEC(Chimp(8)) case?
`master` moved the documentation from the Docusaurus tree under `docs/en/**/*.md` to the Mintlify tree at `docs/**/*.mdx`, deleting every file this branch edits. The edits are replayed at the new paths: - `docs/en/interfaces/specs/NativeFormat.md` -> `docs/reference/interfaces/specs/NativeFormat.mdx` - `docs/en/sql-reference/statements/create/table.md` -> `docs/reference/statements/create/table.mdx`
|
We are in a strange situation here: Chimp is better than Gorilla, but ALP is even better. We can't remove Gorilla. We will recommend ALP instead of Gorilla. The only potential reasons to have Chimp are:
If none of these is true, we will go with ALP, consider this PR as an experiment, and close it. |
Maybe we should try Kangaroo? |
|
To clarify the three points with data: 1. Simplicity and elegance. In this repository, 2. Natural succession of 3. Popularity. The main adoption story is a precedent for exactly this decision: DuckDB added So of the three conditions, only "natural successor of |
|
Follow-up: newer codecs in this family — Since Chimp (VLDB 2022), the XOR family has kept evolving:
Two observations relevant to this PR:
|
What a strange paper! Sounds very wrong. |
|
@panagiotisl, this is a good reference implementation, and it can serve as an example for adding new codecs. Thank you! This PR will be closed because we have two other things in the pipeline:
|
Three changes to the XOR encoding after benchmarking against `ALP`, `Gorilla`, `FPC` and the `Chimp` proposal from #66467: - A per-vector flag omits the trailing-zero field when sampled XOR residues have almost no trailing zeros (typical for full-precision doubles), where the field was pure overhead. - The encoder replaces the full ring scan with two O(1) probes (the predecessor and a high-bits hash table) and bails out to the RAW mode early on incompressible data; compression of incompressible data got 10x faster and now matches `NONE`. - The reference ring grows from 32 to 64 values with a 6-bit index, which covers longer periodicity in the data. Co-Authored-By: Claude Fable 5 <[email protected]>
`RowPolicyFilter::expression` is the parsed policy condition owned by `RowPolicyCache`. It is parsed once, in `RowPolicyCache::PolicyInfo::setPolicy`, and then handed out as is: every query of every user reading the table gets the same AST nodes, and a policy defined on a whole database is shared by all of its tables. `FiltersMixer` combines the parsed conditions without copying them, so the pointer a query receives points straight into the cache. `ReadFromMerge::RowPolicyData` passed that AST to `TreeRewriter` and `ExpressionAnalyzer`, both of which rewrite the AST they are given in place: they normalize identifiers, substitute the results of scalar subqueries for the subqueries themselves, and record `ASTLiteral::unique_column_name`. So reading a `Merge` table mutated the cache. Two consequences: - A scalar subquery in a policy was evaluated once and then frozen. With `CREATE ROW POLICY p ON src USING x <= (SELECT max(v) FROM limits)`, one `SELECT` through a `Merge` table over `src` replaced the subquery with its value in the cached AST, and every later query - including direct reads of `src` by other users - kept using that value for the rest of the server's lifetime. - Concurrent queries raced on the shared AST. ThreadSanitizer reported the write to `ASTLiteral::unique_column_name` from `ActionsMatcher::visit` against a concurrent `ASTLiteral::clone` performed by `buildQueryTree` for another table protected by the same policy: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=66467&sha=b48cf3b340cdcc0e2275b3c1a5a4ba34034deb4d&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 ClickHouse#66467 Analyze a clone instead. `generateFilterActions` in `InterpreterSelectQuery` already clones the policy expression for the same reason, as does `MergeTreeDataSelectExecutor::getSampling` for the sampling key, and `ASTLiteral::clone` resets `unique_column_name` precisely because it is per-analysis scratch state. This was the last consumer of a row policy filter that rewrote the cached AST: the other ones either clone (the analyzer, through `buildQueryTree`), only visit it with a const visitor (`StorageMergeTreeTextIndex`), or only test `isAlwaysTrue`. Co-Authored-By: Claude Fable 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Added the experimental
Chimpfloating-point compression codec forFloat32andFloat64columns (especially effective on time series). It is gated behind theallow_experimental_codecssetting. Based on Panagiotis Liakos, Katia Papakonstantinopoulou, Yannis Kotidis: Chimp: Efficient Lossless Floating Point Compression for Time Series Databases. Proc. VLDB Endow. 15(11): 3058-3070 (2022), https://dl.acm.org/doi/abs/10.14778/3551793.3551852Documentation entry for user-facing changes
Documentation is written (mandatory for new features)
Motivation:
Chimpis a lossless XOR-based floating-point codec that refinesGorilla: it keeps a small ring buffer of recent values to pick a better XOR reference and encodes the trailing zeros of the XOR result, which makes it much more effective thanGorillaon values with local correlation, such as time series. The reference is Panagiotis Liakos, Katia Papakonstantinopoulou, Yannis Kotidis: Chimp: Efficient Lossless Floating Point Compression for Time Series Databases, PVLDB 15(11).Measured numbers (single machine,
clickhouse local, 10MFloat64values of a smooth sine plus 2-decimal noise, so ratios are dataset-specific and not a general claim):INSERT(1 thread)SELECT sum(x)(1 thread, best of 3)NONEGorillaFPCChimpALPSo on this data
Chimpcompresses about 2.8x better thanGorillaat no cost in compression or decompression speed, which is the claim of the paper. It does not beatALP, which was added to ClickHouse later and is both smaller and faster here — that is the open product question on this pull request (whether an experimentalChimpis worth carrying next toALP), and it is a maintainer decision, not something this description asserts.Chimpis registered in the existingtests/performance/codecs_float_insert.xmlandcodecs_float_select.xmlperformance tests, so the CI performance job covers it as well.Validation side effect: a floating-point time series codec is resolved and applied per substream, so the float-only sanity check now requires every element of a composite type to be floating-point, instead of accepting the column as soon as one of them was. This tightens
Gorilla,FPC,ALPandSZ3along withChimp:Tuple(Float64, UInt64) CODEC(Gorilla)used to be created with default settings and appliedGorillato theUInt64substream, bypassingallow_suspicious_codecsfor that part of the column. Such a definition now needsallow_suspicious_codecs, like any other non-floating-point type. Homogeneous composites are unaffected, andATTACHruns with the sanity check disabled, so tables created earlier keep loading.Parameters: The implementation has been based on the implementation of
Gorillaso it requires the same parameters.Example use: The implementation has been based on the implementation of
Gorillaso it can be used exactly likeGorilla.CI Settings (Only check the boxes if you know what you are doing):