Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize group by constant keys #53549

Merged
merged 13 commits into from Sep 18, 2023
Merged

Conversation

Avogar
Copy link
Member

@Avogar Avogar commented Aug 18, 2023

Changelog category (leave one):

  • Performance Improvement

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

Optimize group by constant keys. Will optimize queries with group by _file/_path after #53529

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/

@robot-clickhouse robot-clickhouse added the pr-performance Pull request with some performance improvements label Aug 18, 2023
@robot-clickhouse
Copy link
Member

robot-clickhouse commented Aug 18, 2023

This is an automated comment for commit a075d03 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
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub✅ 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. Integrational 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
Mergeable CheckChecks if all other necessary checks are successful✅ 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
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub✅ success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool✅ success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed✅ 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
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
Check nameDescriptionStatus
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors❌ failure

@nickitat nickitat self-assigned this Aug 18, 2023
@Avogar
Copy link
Member Author

Avogar commented Aug 21, 2023

Screenshot 2023-08-21 at 13 31 07

executeImplBatch<false, false, false>(
method, state, aggregates_pool, row_begin, row_end, aggregate_instructions, overflow_row);
}
BoolArgsToTemplateArgsDispatcher<decltype(call_execute_impl_batch)>::call(call_execute_impl_batch, no_more_keys, use_compiled_functions, prefetch, all_keys_are_const);
Copy link
Member

Choose a reason for hiding this comment

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

Why is it better? I didn't understand why we need this class.

Copy link
Member Author

@Avogar Avogar Aug 22, 2023

Choose a reason for hiding this comment

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

Otherwise we will need to write ~16 if/else branches to check all 4 bool arguments (maybe some of them won't actually appear, but still a lot).
Like https://pastila.nl/?01f3324d/a170ed3f747f063f81f5821188dd8aa3#B7nUAYOQzbzMvGUQ6wClTw==
And IMHO do it in a few lines with some dispatcher class is better. But you can disagree and I can bring back this batch of if/else

Copy link
Member

Choose a reason for hiding this comment

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

I do not like dispatchers as well. I think the issue is with executeImplBatch and we should refactor it somehow.

@KochetovNicolai KochetovNicolai self-assigned this Aug 22, 2023
Copy link
Member

@KochetovNicolai KochetovNicolai left a comment

Choose a reason for hiding this comment

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

The change is good and clear generally.
However, I do not like how our dispatching is done.
Looks like something is wrong with a function that takes 4 bool template args.
I would like to refactor it somehow, but do not have good ideas right now.

@Avogar
Copy link
Member Author

Avogar commented Aug 23, 2023

Actually, the new bool flag all_keys_are_const is not called on each row as other flags, so I can just pass it as not template argument and bring previous code back in dispatching with 3 bool template arguments

@nickitat
Copy link
Member

I don't really mind BoolArgsToTemplateArgsDispatcher, but I do mind all the if-s that we had to add. we essntially already have this method of calculation - it is called without_key. so I assume that we need almost no changes in Aggregator itself (except that now key columns wouldn't be added to the output header afaik).
so would be better to make it a plan optimisation and get rid of one more AST optimisation:

:) explain syntax select count(), pi() from numbers_mt(1e6) group by pi(), e()

EXPLAIN SYNTAX
SELECT
    count(),
    pi()
FROM numbers_mt(1000000.)
GROUP BY
    pi(),
    e()

┌─explain───────────────────┐
│ SELECT                    │
│     count(),              │
│     pi()                  │
│ FROM numbers_mt(1000000.) │
└───────────────────────────┘

@Avogar
Copy link
Member Author

Avogar commented Aug 23, 2023

we essntially already have this method of calculation - it is called without_key

But afaiu that's not the same and we cannot reuse it. We can still have different keys, but some blocks of data can contain constant columns with keys. For example:

select count() from file('data{1,2,3}.parquet') group by _file

Reading from file will return blocks with constant column _file, but different blocks can have different values

@nickitat
Copy link
Member

we essntially already have this method of calculation - it is called without_key

But afaiu that's not the same and we cannot reuse it. We can still have different keys, but some blocks of data can contain constant columns with keys. For example:

select count() from file('data{1,2,3}.parquet') group by _file

Reading from file will return blocks with constant column _file, but different blocks can have different values

ok, I indeed assumed that we're talking about globally constant keys.

@robot-ch-test-poll4 robot-ch-test-poll4 added pr-status-⏳ PR with some pending statuses pr-status-❌ PR with some error/faliure statuses and removed pr-status-⏳ PR with some pending statuses labels Sep 15, 2023
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-status-⏳ PR with some pending statuses and removed pr-status-❌ PR with some error/faliure statuses labels Sep 15, 2023
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-status-❌ PR with some error/faliure statuses and removed pr-status-⏳ PR with some pending statuses labels Sep 15, 2023
@Avogar Avogar merged commit 9c888ea into ClickHouse:master Sep 18, 2023
276 of 277 checks passed
baibaichen added a commit to Kyligence/gluten that referenced this pull request Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-performance Pull request with some performance improvements pr-status-❌ PR with some error/faliure statuses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants