Repository navigation
Conversation
|
The library uses GPL 2, which is not compatible with ClickHouse's Apache |
|
Hi @fastio Apart from the License, which is a serious issue. We already tried |
Ergus
left a comment
There was a problem hiding this comment.
Hi @fastio
Very thanks for this contribution and the code is actually very nice.
Sadly I cannot approve this due to a License issue, however I reviewed it with some comments in case you want to consider. Feel free to share your thought and any comment related with them
Also I don't see any test for this code. In a change like this I would request very extensive tests including some performance checks and rate compression information.
Best,
Ergus
| temp_buffer.resize(bytes); | ||
| in.readStrict(temp_buffer.data(), bytes); | ||
| /// Decode postings | ||
| unsigned char *p = reinterpret_cast<unsigned char *>(temp_buffer.data()); |
| in.readStrict(raw.data(), bytes); | ||
| auto p = reinterpret_cast<unsigned char*>(raw.data()); | ||
| Codec::decodeBlock<T>(p, n, decoded, bytes); | ||
| ++ current_block; |
|
|
||
| String getName() const override { return PostingListData::name(); } | ||
|
|
||
| void add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena * arena) const override |
There was a problem hiding this comment.
Is it possible to use another input argument than a **.
There was a problem hiding this comment.
The add method is part of the aggregate function interface named IAggregateFunction defined by the framework.
AggregateFunctionPostingsList inherits from this interface and must implement the same function signature.
My understanding is that this design comes from the requirement that the aggregation hot path must have zero abstraction overhead.
Using const IColumn ** allows the compiler to optimize aggressively, which wouldn’t be possible with a std::vector<const IColumn *> wrapper.
|
|
||
| } | ||
|
|
||
| void registerAggregateFunctionsTextSearch(AggregateFunctionFactory & factory) |
There was a problem hiding this comment.
This function will be used together with projection indexes to support text indexing in future work.
| } | ||
| } | ||
|
|
||
| void serialize(WriteBuffer & buf, std::optional<size_t> /* version */) const |
There was a problem hiding this comment.
The code should at least chassert that the version argument is correct right?
| if (postings.isSmall()) | ||
| { | ||
| const auto &small = postings.getSmall(); | ||
| assert(postings.size() <= small.size()); |
| { | ||
| PostingsContainer32 container; | ||
| PostingList postings; | ||
| container.decodeTo(istr, postings); |
There was a problem hiding this comment.
In my experience this could be the key for any performance impact. You could consider to use the profiler events api to measure this and compare with uncompressed alternatives
There was a problem hiding this comment.
Thank you very much for pointing this out.
Apologies — I took a shortcut here.
I reused the existing PostingListBuilder logic, which still relies on a bitmap-based representation for the token → row-id mapping.
In this PR I only implemented the write-side using PostingsContainer, while the read/query side is still using the original bitmap path. This means there is an unnecessary data-structure conversion happening here.
As a next step, I will switch the query-side to use PostingsContainer directly, and then compare the performance between the original bitmap-based path, and the pure PostingsContainer path.
| { | ||
| PostingsContainer64 out_container; | ||
| mergePostingsContainers(out_container, container, rhs.container); | ||
| container.swap(out_container); |
There was a problem hiding this comment.
Very minor:
IIUC the "old container" is not needed anymore, so maybe it is better to use a move (to release it) instead of a swap. I know it will go out of scope immediately, but in case of issues it will be easier to debug
There was a problem hiding this comment.
I completely agree — thanks for pointing it out. I’ll update it.
| } | ||
|
|
||
| /// Returns an iterator over decompressed postings (lazy block decoding). | ||
| auto begin() const |
There was a problem hiding this comment.
I strongly discourage to use the croaring iterator api. In their own comment they explain that it is much slower than the array conversion alternative. And in our tests it affected performance by ~40%.
There was a problem hiding this comment.
Thanks for the warning — I fully agree that the croaring iterator API is not something we want to use in hot paths. Just to clarify: in this particular code we are not using the croaring iterator API. The Iterator here is the iterator of our own PostingsContainer abstraction.
| result_array_data.resize(result_array_data_insert_begin + container.size()); | ||
|
|
||
| size_t idx = 0; | ||
| for (auto it = container.begin(); it != container.end(); ++it, idx++) |
There was a problem hiding this comment.
The croaring iterator API is very slow. That's why we recommend to use api variants based in the toArray call
There was a problem hiding this comment.
The Iterator here is the iterator of our own PostingsContainer abstraction.
@Ergus , Thanks a lot for your detailed review and kind words! Thanks again for the thoughtful review and valuable suggestions! Best, |
|
It was said above but TurboPFOR is a no-no for ClickHouse due to GPL. Perhaps we can splitt of the aggregation function into a separate PR? |
@rschu1ze Ok, I’ve removed the aggregation-related code. This PR is now focused solely on posting list storage compression. |
@Ergus Thank you very much for all your helpful review comments. I’ve removed the posting list aggregate function–related code, so this PR now focuses solely on posting list compression. Based on current tests, when postings are relatively long (i.e. tokens are highly repetitive in the log data), the compression ratio is quite substantial. At the same time, CPU and memory usage during writes have not increased noticeably. |
|
Hi @Ergus, Thanks for reviewing this! No rush, but could you continue the review on this PR when you have bandwidth? |
|
Hi @fastio Very very sorry for the delay. This is a bad week because we have critical tasks with 100% priority (even over my own tasks, plans and development) and your new version deserves a full new review ;) I promise that your PR will be my first task after this ;) |
No worries — I completely understand. Thanks a lot for taking this on, and good luck with the urgent tasks! |
|
Hi @fastio I was checking the code and in general it looks good to me (I have some comments, but nothing critical to worry). However, at the moment we are working in an update for the index format: Inverted Text Index v3 (that is expected to be merged soon) and these changes has conflicts. Let's stop this PR for now and after merging the new version we restore this PR. Is it fine? |
@Ergus Thanks for your review. |
|
Hi @fastio I just want to let you know that the V3 was merged today :) I am looking again at this changes and it looks that they will need full re-implementation for the new format. I let to your consideration if it worth trying that for the new index. However I highlight two + 1 details to consider:
2 + 1. It will be very relevant to measure not only space, but also performance impact of the compression with some numbers (the good and the bad ones). Either in hot or cold runs. Best, |
@Ergus Congratulations on the V3. Thanks a lot for the update and the detailed notes — much appreciated. I’ll work on re-implementing the index compression for the v3 format in the next few days and rerun the benchmarks, covering storage size and the performance impact on reads and writes. |
That's for @CurtizJ ;)
Thank you very much, I will be on hold for whatever you need |
|
I’ve submitted a new PR and closed the old one. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Optimize postings list compression with simdcomp.
Documentation entry for user-facing changes
This PR introduces SIMD-accelerated compression for postings lists using
[simdcomp] on x86_64 and StreamVByte as a generic fallback.
Depending on the available SIMD ISA, postings are compressed in fixed-size
blocks with simdcomp, and the remaining tail is encoded with StreamVByte.
By using SIMD-friendly integer compression, we can reduce the storage
footprint and improve scan performance for inverted indexes, especially
for large postings lists.
https://github.com/fast-pack/simdcomp
How to use ?
Added a parameter enable_postings_compression when creating the index.
A Simple Test
In the same ClickHouse process, I inserted 12,400,000 rows into two tables (logs_compressed and logs_uncompressed). Then I used the system.parts table to measure the size of the inverted index for each table, as well as its proportion relative to the total data size.
In this simple test scenario, enabling postings compression for the inverted index significantly reduced the index disk footprint — by more than two orders of magnitude (over a 100× reduction).
A More Complex Test
Now I’ve done a more complex one. I inserted 10B rows of random, log-like data into each of the two tables, and then measured how much disk space the inverted index occupies in each table.
With postings compression enabled for the inverted index, the index storage footprint is reduced by more than an order of magnitude (over 10× smaller).