Skip to content

Refactor query engine settings - #73693

Merged
vdimir merged 3 commits into
ClickHouse:masterfrom
rschu1ze:refactor-settings
Dec 30, 2024
Merged

vdimir merged 3 commits into
ClickHouse:masterfrom
rschu1ze:refactor-settings

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Dec 20, 2024 •

Copy link
Copy Markdown
Member

Various settings classes in the query engine code look like this:

struct QuerySettings
{
    bool setting_1 = true;
    bool setting_2 = false;
    [...]

    static QuerySettings fromContext(ContextPtr from);
    static QuerySettings fromSettings(const Settings & from);
};

The member variables ^^ are default-initialized. This is a problem: First, it repeats the default setting values in src/Core/Settings.cpp (redundancy). Second, is dangerous as there are already subtle differences between default-initialized values and settings.

This PR gets rid of the default initialization by replacing the static factory methods with normal constructors:

struct QuerySettings
{
    QuerySettings(ContextPtr context);

    bool setting_1;
    bool setting_2;
};

Motivated by #73393 (comment)

Review note: this PR is best reviewed commit by commit.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Dec 20, 2024
@robot-ch-test-poll

robot-ch-test-poll commented Dec 20, 2024 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit af56c74 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
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
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
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

@rschu1ze rschu1ze changed the title *wip* Refactor query engine settings Refactor query engine settings Dec 29, 2024
@rschu1ze
rschu1ze marked this pull request as ready for review December 29, 2024 17:49
(ignore:
- max_optimizations_to_apply: 0 vs. 10k
- optimize_use_implicit_projections: false vs. true
- distinct_in_order: false vs. true
- Usages potentially impacted by refactoring: Interpreters/MutationsInterpreter.cpp
)
(ignore:
- min_count_to_compile_expressions: 0 vs. 3
- short_circuit_function_evaluation: disable vs enable
)
@vdimir vdimir self-assigned this Dec 30, 2024

@vdimir vdimir left a comment

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.

👍

@vdimir
vdimir enabled auto-merge December 30, 2024 09:29
@vdimir
vdimir added this pull request to the merge queue Dec 30, 2024
Merged via the queue into ClickHouse:master with commit 1188dad Dec 30, 2024
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Dec 30, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Dec 31, 2024
@baibaichen

Copy link
Copy Markdown
Contributor

@rschu1ze

I have quesiton, IIUC, optimize_plan currently only affects first pass optimization, so even optimize_plan is set to false, other optimizations except first-pass optimation still be effective before this PR.

void optimizeTreeFirstPass(const QueryPlanOptimizationSettings & optimization_settings, QueryPlan::Node & root, QueryPlan::Nodes & nodes)
{
    if (!optimization_settings.optimize_plan)
        return;
//     ......
}

I am not clear the comment of the following codes, does it mean only first pass optimization change the transformers?

   QueryPlanOptimizationSettings optimization_settings(context);
    /// All optimisations will be done at plans creation  
    optimization_settings.optimize_plan = false;

@rschu1ze

rschu1ze commented Dec 31, 2024 •

Copy link
Copy Markdown
Member Author

@baibaichen

I have quesiton, IIUC, optimize_plan currently only affects first pass optimization, so even optimize_plan is set to false, other optimizations except first-pass optimation still be effective before this PR.

That was probably an oversight, I'll push a separate PR to address that (i.e. enable/disable also the 2nd pass).

EDIT: Disabling the 2nd / 3rd passes doesn't look safe. We better keep it as is.

I am not clear the comment of the following codes, does it mean only first pass optimization change the transformers?

QueryPlanOptimizationSettings optimization_settings(context);
/// All optimisations will be done at plans creation  
optimization_settings.optimize_plan = false;

I don't understand what "only first pass optimization change the transformers" means.
Besides that, the comment and the code existed already before this PR and I was not the author of it.

baibaichen added a commit to Kyligence/gluten that referenced this pull request Jan 3, 2025
baibaichen added a commit to apache/gluten that referenced this pull request Jan 3, 2025
* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20250103)

* Fix gtest due to ClickHouse/ClickHouse#73811

* Another way to set query_plan_enable_optimizations to false

* Try to set max_threads to 1, but GlutenClickHouseTPCHColumnarShuffleParquetAQESuite::q1 and q2 will fail

* Fix Build Due to ClickHouse/ClickHouse#73693

* Restore QueryPlanOptimizationSettings

* COLLECT_METRICS

* Fix build due to ClickHouse/ClickHouse#73994

---------

Co-authored-by: kyligence-git <[email protected]>
Co-authored-by: Chang Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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