Skip to content

Conversation

arthurpassos
Copy link
Contributor

@arthurpassos arthurpassos commented Nov 1, 2024

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Evaluate parquet bloom filters and min/max indexes together. Necessary to properly support: x = 3 or x > 5 where data = [1, 2, 4, 5]

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Run only fuzzers related jobs (libFuzzer fuzzers, AST fuzzers, etc.)
  • Exclude: AST fuzzers

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@arthurpassos
Copy link
Contributor Author

For now, this is just an ugly POC. Done with minimal effort. Ideas for its design are welcome.

The design challenge here is if we should re-use logic in KeyCondition or not. If so, how, and how much.

@al13n321

@arthurpassos
Copy link
Contributor Author

arthurpassos commented Nov 1, 2024

Ok, looks like I messed up when switching branches and managed to lose some code :D


rpn_stack.emplace_back(intersects, !contains);

if (rpn_stack.back().can_be_true && element.bloom_filter_data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just highlighting bf check since diff can't do it

{
rpn_stack.emplace_back(true, true);

if (element.bloom_filter_data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just highlighting bf check since diff can't do it

* represented by a set of hyperrectangles.
*/
}
else if (element.function == ConditionElement::FUNCTION_POINT_IN_POLYGON)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.


rpn_stack.emplace_back(element.set_index->checkInRange(hyperrectangle, data_types, single_point));

if (rpn_stack.back().can_be_true && element.bloom_filter_data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just highlighting bf check since diff can't do it

@arthurpassos
Copy link
Contributor Author

arthurpassos commented Nov 1, 2024

The first option that comes to my mind

Make KeyCondition::checkInHyperrectangle static and try to re-use its logic. To do that, RPN and other things would be passed in the function arguments. The RPN would contain an optional bloom_filter data field that contains hashes just like we need. Since the field is optional, it wouldn't affect existing usage. Parquet usage would need to do an external conversion like https://github.com/ClickHouse/ClickHouse/pull/71383/files#diff-13d6203d07156cfe09dfc59f2f772758a248d11dc8e96f221040579b9b5e5e34R366

The thing I dislike the most about this approach is the method name... Because it is now doing other things, not only checking the hyperrectangle.

@arthurpassos
Copy link
Contributor Author

arthurpassos commented Nov 4, 2024

The first option that comes to my mind

Make KeyCondition::checkInHyperrectangle static and try to re-use its logic. To do that, RPN and other things would be passed in the function arguments. The RPN would contain an optional bloom_filter data field that contains hashes just like we need. Since the field is optional, it wouldn't affect existing usage. Parquet usage would need to do an external conversion like https://github.com/ClickHouse/ClickHouse/pull/71383/files#diff-13d6203d07156cfe09dfc59f2f772758a248d11dc8e96f221040579b9b5e5e34R366

The thing I dislike the most about this approach is the method name... Because it is now doing other things, not only checking the hyperrectangle.

Another problem with this approach is that we would need some sort of hash find hash callback in order to avoid flooding KeyCondition with parquet stuff.

EDIT

Addressed above with an interface

@arthurpassos arthurpassos changed the title [Draft/ POC] Merge parquet bloom filter and min/max evaluation Merge parquet bloom filter and min/max evaluation Nov 5, 2024
@arthurpassos arthurpassos marked this pull request as ready for review November 5, 2024 14:50
@arthurpassos
Copy link
Contributor Author

@al13n321

I have implemented the approach I mentioned above. Let me know if you are ok with this approach. Plus, can you enable CI?

@arthurpassos
Copy link
Contributor Author

Basically, a new static method checkRPNAgainstHyperrectangle has been added and it is a copy of checkInHyperrectangle but with bloom filter optional checks. Existing checkInHyperrectangle is still a member function that calls the static checkRPNAgainstHyperrectangle.

Some KeyCondition members had to be made public in order to pass to checkRPNAgainstHyperrectangle.

One thing to note is that in case bf_filter=on and minmax_filter=false the minmax evaluation will happen on an infinite range. Previously, it would not happen at all.

@vdimir vdimir added the can be tested Allows running workflows for external contributors label Nov 6, 2024
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-improvement Pull request with some product improvements label Nov 6, 2024
@robot-ch-test-poll3
Copy link
Contributor

robot-ch-test-poll3 commented Nov 6, 2024

This is an automated comment for commit 07cb54f with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (asan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (debug)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (msan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (tsan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
BuzzHouse (ubsan)There's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns ClickBench with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@UnamedRus
Copy link
Contributor

Necessary to properly support: x = 3 or x > 5 where data = [1, 2, 4, 5]

Correct me, if i'm wrong, but this doesn't work even for MergeTree tables right now?

@arthurpassos
Copy link
Contributor Author

Necessary to properly support: x = 3 or x > 5 where data = [1, 2, 4, 5]

Correct me, if i'm wrong, but this doesn't work even for MergeTree tables right now?

I haven't looked through the code, but I assume it doesn't work even for MT. KeyCondition does not handle bloom filters, it is handled separately, so most likely that's the case

Copy link
Member

@al13n321 al13n321 left a comment

Choose a reason for hiding this comment

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

Neat, more functionality for less code. Thanks for taking the time to simplify this!

Correct me, if i'm wrong, but this doesn't work even for MergeTree tables right now?

Yes. I think it would make sense to do a similar refactoring to MergeTreeIndexConditionBloomFilter too (move most of the logic into KeyCondition instead of having a custom RPNElement and tree traversal; then, separately, actually merging bf index checking with primary key analysis would be more tricky, may or may not be worth it).

Comment on lines 343 to 347
if (found_empty_column)
{
condition_elements.emplace_back(Function::ALWAYS_FALSE);
// todo arthur
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

This should just be handled by KeyCondition independent of bf. I think the line element.set_index->checkInRange already takes care of empty sets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you say that because if the set is empty, it'll be false and thus rpn_stack.back().can_be_true will prevent the bloom filter check??

Copy link
Member

@al13n321 al13n321 Dec 4, 2024

Choose a reason for hiding this comment

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

Yes. Maybe it would make sense to also do a redundant explicit check, to not rely on checkInRange carefully handling the kinda-special "infinite range x empty set" case. Either way, this logic belongs in KeyCondition, I feel.

In my mind, empty set is not a special case at all, nothing would break if the normal code path runs on it (unless the code uses empty list as a special value with special meaning (e.g. "skip bloom filter check"), which I think is not a good idea in this case). Except that we may unnecessarily read the bloom filter from file, worth avoiding.

(Or KeyCondition's construction code could do the ALWAYS_FALSE thing, but I like that slightly less because (a) it means a more substantially different code path is taken depending on the data (whether the set happens to be empty, e.g. if it's a subquery), (b) it requires the set to be built (e.g. by running subquery) at KeyCondition construction time; which currently always happens anyway, but in future I can imagine deferring it to a different stage of query execution, with better progress reporting and cancellability than the early query analysis stage.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mind might be tricking me, but I guess it is ok not to check for empty columns at this stage.

bool mayExistOnBloomFilter(const KeyCondition::BloomFilterData & condition_bloom_filter_data,
                           const KeyCondition::ColumnIndexToBloomFilter & column_index_to_column_bf)

will loop over the columns in the set index, and then call the overload

bool mayExistOnBloomFilter(const std::vector<uint64_t> & hashes, const std::unique_ptr<KeyCondition::BloomFilter> & bloom_filter)

which loops over the hashes, but none shall be found because empty set won't produce any hashes. If that is the case, it'll return false. If it returns false, the row group will be skipped.

That's the goal, right? Unless there is a scenario where min/max range check would return true for empty set, and then bloom filter would affect the end result.

Copy link
Member

@al13n321 al13n321 Dec 5, 2024

Choose a reason for hiding this comment

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

Two goals: (1) skip the row group (which probably already redundantly accomplished by both set_index->checkInRange and mayExistOnBloomFilter), (2) don't read the bf. For (2) I just realized checkRPNAgainstHyperrectangle's behavior is irrelevant, the empty set check would need to be in getBloomFilterFilteringColumnKeys (and it doesn't seem important; if any special effort is needed to "prepare" the set correctly in there, it's probably not worth it).

(EDIT: So my first comment in this chain was incorrect: the empty set check belongs in getBloomFilterFilteringColumnKeys, not in KeyCondition. Unless KeyCondition does the ALWAYS_FALSE thing for empty set, which is also fine. None of this is important, why am I writing so many words lol.)

hashes_for_column.emplace_back(*hashed_value);

hashes.emplace_back(std::move(hashes_for_column));
hashes.emplace_back(static_cast<std::vector<uint64_t>>(std::move(hashes_for_column)));
Copy link
Member

Choose a reason for hiding this comment

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

Would just hashes.emplace_back({*hashed_value}); work?

I'd use uint64_t for the hash everywhere in this PR (changing hash_one and hash_many return types), since that's what the arrow's functions return, and all hashes in this PR come from those functions.

@arthurpassos
Copy link
Contributor Author

01086_window_view_cleanup - #72232

@arthurpassos
Copy link
Contributor Author

@al13n321 can we merge it?

@arthurpassos
Copy link
Contributor Author

@al13n321 ping

@arthurpassos
Copy link
Contributor Author

@al13n321 can we merge it?

s3_cluster - #74202

@al13n321
Copy link
Member

IIUC, the workflow is that I should fix these flaky tests before merging, and I don't have the time/energy right now, sorry.

@arthurpassos
Copy link
Contributor Author

@al13n321 CI/CD is green, can you fix the CH sync issue and merge it?

@al13n321 al13n321 added this pull request to the merge queue Jan 29, 2025
Merged via the queue into ClickHouse:master with commit 288ad3e Jan 29, 2025
206 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 29, 2025
Enmk added a commit to Altinity/ClickHouse that referenced this pull request Mar 13, 2025
…_minmax_eval

24.8 Backport of ClickHouse#71383 - Merge parquet bloom filter and min/max evaluation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants