Skip to content

[WIP]Reorder short circuit functions' arguments adaptively - #55656

Open
lgbo-ustc wants to merge 19 commits into
ClickHouse:masterfrom
bigo-sg:reorder_shortcircuit
Open

lgbo-ustc wants to merge 19 commits into
ClickHouse:masterfrom
bigo-sg:reorder_shortcircuit

Conversation

@lgbo-ustc

@lgbo-ustc lgbo-ustc commented Oct 16, 2023 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Performance Improvement

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

...
For function and/or, the short-circuit arguments execution order has an important impact on performance. For example

-- q1
select * from mt_left where JSON_VALUE(s, '$.a') = '1' and key < 100 Format Null

0 rows in set. Elapsed: 0.067 sec. Processed 10.02 million rows, 475.95 MB (149.84 million rows/s., 7.12 GB/s.)
-- q2
select * from mt_left where key < 100 and JSON_VALUE(s, '$.a') = '1'  Format Null

0 rows in set. Elapsed: 0.018 sec. Processed 10.02 million rows, 475.95 MB (566.96 million rows/s., 26.93 GB/s.)

To determine the execution order of arguments, this PR first sample some rows, get the selectivity and execution cost, and then reorder the arguments position. For the q1 as above, the resutl is

-- q1
select * from mt_left where JSON_VALUE(s, '$.a') = '1' and key < 100  Format Null
0 rows in set. Elapsed: 0.018 sec. Processed 10.02 million rows, 475.95 MB (550.27 million rows/s., 26.14 GB/s.)

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/

@lgbo-ustc lgbo-ustc changed the title [WIP] Reordeer short circuit functions' arguments adaptively. [WIP] Reorder short circuit functions' arguments adaptively. Oct 16, 2023
@lgbo-ustc
lgbo-ustc force-pushed the reorder_shortcircuit branch 3 times, most recently from 344996c to 955f0fd Compare October 16, 2023 07:26
@lgbo-ustc
lgbo-ustc marked this pull request as ready for review October 16, 2023 07:35
@lgbo-ustc lgbo-ustc changed the title [WIP] Reorder short circuit functions' arguments adaptively. Reorder short circuit functions' arguments adaptively. Oct 16, 2023
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-performance Pull request with some performance improvements label Oct 16, 2023
@robot-clickhouse-ci-1

robot-clickhouse-ci-1 commented Oct 16, 2023 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit a3c674f 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
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS❌ failure
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ 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
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
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
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ 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

@nickitat nickitat added the can be tested Allows running workflows for external contributors label Oct 16, 2023
@Avogar Avogar self-assigned this Oct 16, 2023
@lgbo-ustc
lgbo-ustc force-pushed the reorder_shortcircuit branch 7 times, most recently from d0cbeef to 0d29435 Compare October 19, 2023 09:39
@lgbo-ustc lgbo-ustc changed the title Reorder short circuit functions' arguments adaptively. Reorder the arguments of functions which support short circuit execution adaptively. Oct 19, 2023
@lgbo-ustc
lgbo-ustc force-pushed the reorder_shortcircuit branch from 0d29435 to d7e0a53 Compare October 19, 2023 10:13
@lgbo-ustc lgbo-ustc changed the title Reorder the arguments of functions which support short circuit execution adaptively. Reorder the arguments of short circuit functions adaptively. Oct 19, 2023
@lgbo-ustc lgbo-ustc changed the title Reorder the arguments of short circuit functions adaptively. Reorder short circuit functions' arguments adaptively Oct 19, 2023
@lgbo-ustc
lgbo-ustc force-pushed the reorder_shortcircuit branch 9 times, most recently from 26f9b29 to bccd481 Compare October 23, 2023 02:44
@lgbo-ustc
lgbo-ustc force-pushed the reorder_shortcircuit branch 5 times, most recently from 5a6e2c2 to f3bd506 Compare December 20, 2024 03:26
@lgbo-ustc
lgbo-ustc force-pushed the reorder_shortcircuit branch from f3bd506 to a3c674f Compare December 20, 2024 03:34
@lgbo-ustc lgbo-ustc changed the title Reorder short circuit functions' arguments adaptively [WIP]Reorder short circuit functions' arguments adaptively Dec 24, 2024
@lgbo-ustc

lgbo-ustc commented Dec 24, 2024 •

Copy link
Copy Markdown
Contributor Author

There will be server update to improve short circuit execution.

  1. Don't lazy execute nodes which can be calculated quickly. Enable dynamic evaluation of whether a short-circuit function's argument should be lazily executed #73776
  2. Don't lazy excute common subexpression when most of the rows are needed
  3. Reorder arguments

@clickhouse-gh

clickhouse-gh Bot commented Jan 28, 2025

Copy link
Copy Markdown
Contributor

Dear @KochetovNicolai, @Avogar, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@Avogar Avogar assigned Avogar and unassigned Avogar Jun 1, 2026
@abashkeev abashkeev added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 3, 2026

This branch has not been deployed

No deployments
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 comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. external Author is not a member of the ClickHouse organization pr-performance Pull request with some performance improvements st-discussion When the implementation aspects are not clear or when the PR is on hold due to questions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants