Skip to content

Hash join: automatically choose build side#68682

Merged
vdimir merged 47 commits intomasterfrom
vdimir/join_select_inner_table
Nov 4, 2024
Merged

Hash join: automatically choose build side#68682
vdimir merged 47 commits intomasterfrom
vdimir/join_select_inner_table

Conversation

@vdimir
Copy link
Copy Markdown
Member

@vdimir vdimir commented Aug 21, 2024

Changelog category (leave one):

  • New Feature

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

  • Added an option to select the side of the join that will act as the inner table in the query plan. This is controlled by query_plan_join_inner_table_selection, which can be set to auto. In this mode, ClickHouse will try to choose the table with the smallest number of rows. Resubmitted Resubmit #68682 #71577

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

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-feature Pull request with new product feature label Aug 21, 2024
@robot-clickhouse
Copy link
Copy Markdown
Member

robot-clickhouse commented Aug 21, 2024

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

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

Check nameDescriptionStatus
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
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
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/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
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
Stateful testsRuns stateful 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

@vdimir vdimir changed the title [wip] select inner table for hash join [wip, do not review] select inner table for hash join Aug 21, 2024
@vdimir vdimir force-pushed the vdimir/join_select_inner_table branch 2 times, most recently from 8276d1d to 78bfc55 Compare August 26, 2024 10:42
@vdimir vdimir changed the title [wip, do not review] select inner table for hash join select inner table for hash join Aug 29, 2024
@vdimir vdimir marked this pull request as ready for review August 29, 2024 09:47
@vdimir
Copy link
Copy Markdown
Member Author

vdimir commented Sep 6, 2024

Need also to enable setting in integration tests by #69328 However, the resr should be alright

@vdimir vdimir changed the title select inner table for hash join Automatic selection of hash join inner table Sep 6, 2024
@vdimir vdimir changed the title Automatic selection of hash join inner table Selection of hash join inner table Sep 6, 2024
@nickitat nickitat self-assigned this Sep 8, 2024
@vdimir vdimir requested a review from nickitat September 17, 2024 16:01
void optimizePrewhere(Stack & stack, QueryPlan::Nodes & nodes);
void optimizeReadInOrder(QueryPlan::Node & node, QueryPlan::Nodes & nodes);
void optimizeAggregationInOrder(QueryPlan::Node & node, QueryPlan::Nodes &);
void optimizeJoin(QueryPlan::Node & node, QueryPlan::Nodes &);
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.

🎉

return;

const auto & join = join_step->getJoin();
if (join->pipelineType() != JoinPipelineType::FillRightFirst || !join->isCloneSupported() || typeid_cast<const HashJoin *>(join.get()))
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.

could we allow ConcurrentHashJoin here too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I enabled isCloneSupported for ConcurrentHashJoin, should work for that implementation as well


const auto & table_join = join->getTableJoin();
auto kind = table_join.kind();
if (table_join.hasUsing()
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.

comment for this if pls

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually it's a todo, since using implemented so it depends on table orders, can be fixed but a bit of headache

/// fixme: USING clause handled specially in join algorithm, so swap breaks it
/// fixme: Swapping for SEMI and ANTI joins should be alright, need to try to enable it and test

join_step->swap_streams = true;

auto updated_table_join = std::make_shared<TableJoin>(table_join);
updated_table_join->swapSides();
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.

it seems it could happen that different nodes could make different optimisation decisions here in a distributed query. afaiu we change output header too. is it actually a problem and should we then maybe take some actions to preserve the header?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Implemented transformations inside JoinStep, so it keeps column order unchanged

@vdimir vdimir force-pushed the vdimir/join_select_inner_table branch 2 times, most recently from 4223def to 3cf2b90 Compare September 26, 2024 12:12
@vdimir vdimir force-pushed the vdimir/join_select_inner_table branch from 3cf2b90 to 35cf3e8 Compare September 26, 2024 13:39
@vdimir vdimir force-pushed the vdimir/join_select_inner_table branch from 697017b to fca592a Compare September 26, 2024 14:20
@vdimir vdimir marked this pull request as draft September 27, 2024 09:01
@vdimir vdimir force-pushed the vdimir/join_select_inner_table branch from ede7e1d to 32fe869 Compare October 24, 2024 12:19
@vdimir vdimir marked this pull request as ready for review October 25, 2024 09:52
@vdimir vdimir requested a review from nickitat October 25, 2024 09:52
@vdimir
Copy link
Copy Markdown
Member Author

vdimir commented Nov 1, 2024

Stateless tests (debug, s3 storage) — fail: 1, passed: 6984, skipped: 181 Details

#71366

@vdimir vdimir enabled auto-merge November 1, 2024 12:28
@vdimir vdimir disabled auto-merge November 1, 2024 12:31
@vdimir vdimir added this pull request to the merge queue Nov 4, 2024
Merged via the queue into master with commit 93b1484 Nov 4, 2024
@vdimir vdimir deleted the vdimir/join_select_inner_table branch November 4, 2024 14:47
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 4, 2024
{"restore_replace_external_dictionary_source_to_null", false, false, "New setting."},
{"show_create_query_identifier_quoting_rule", "when_necessary", "when_necessary", "New setting."},
{"show_create_query_identifier_quoting_style", "Backticks", "Backticks", "New setting."},
{"query_plan_join_inner_table_selection", "auto", "auto", "New setting."},
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.

This should go to 24.11

@Algunenano Algunenano mentioned this pull request Nov 4, 2024
21 tasks
baibaichen added a commit to Kyligence/gluten that referenced this pull request Nov 5, 2024
baibaichen added a commit to apache/gluten that referenced this pull request Nov 5, 2024
* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20241105)

* Fix Build due to ClickHouse/ClickHouse#71261

* Fix Build due to ClickHouse/ClickHouse#68682

---------

Co-authored-by: kyligence-git <gluten@kyligence.io>
Co-authored-by: Chang Chen <baibaichen@gmail.com>
baibaichen added a commit to apache/gluten that referenced this pull request Nov 7, 2024
* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20241107)

* Revert "Fix Build due to ClickHouse/ClickHouse#68682", see ClickHouse/ClickHouse#71527

---------

Co-authored-by: kyligence-git <gluten@kyligence.io>
Co-authored-by: Chang Chen <baibaichen@gmail.com>
Algunenano added a commit that referenced this pull request Nov 25, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 25, 2024
vdimir added a commit that referenced this pull request Nov 26, 2024
@rschu1ze rschu1ze changed the title Selection of hash join inner table Hash join: automatically choose build side Nov 26, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature 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.

6 participants