Skip to content

Add settings for real-time updates during query execution - #48607

Merged
KochetovNicolai merged 34 commits into
ClickHouse:masterfrom
alexX512:master
Sep 8, 2023
Merged

KochetovNicolai merged 34 commits into
ClickHouse:masterfrom
alexX512:master

Conversation

@alexX512

@alexX512 alexX512 commented Apr 10, 2023 •

Copy link
Copy Markdown
Contributor

Currently real-time updates supported only for queries running in a single thread. Also real-time updates currently useful only for queries with extensive part of execution in ORDER BY or in functions for aggregation without key.

Changelog category (leave one):

  • New Feature

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

Add options partial_result_update_duration_ms and max_rows_in_partial_result to show updates of a partial result of output table in real-time during query execution.

Example of updates for ORDER BY

real-time-updates.mp4

Example of updates for aggregation without key

real-time-updates-aggregation-without-key.mp4

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-feature Pull request with new product feature label Apr 10, 2023
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 10, 2023
@robot-ch-test-poll3

robot-ch-test-poll3 commented May 1, 2023 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 36b8932 with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🔴 failure

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
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. 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🔴 failure
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

@alexX512
alexX512 marked this pull request as ready for review August 8, 2023 07:33
@evillique evillique self-assigned this Aug 9, 2023
@vdimir vdimir self-assigned this Aug 21, 2023

@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.

Thank you for the fantastic work on this PR!

The most tricky part for me is the changes around Pipe, probably, I need to check it once more.

All in all, I get the idea as follows (correct me where I'm wrong): we are building an auxiliary pipeline with processors corresponding to processors in the main pipeline. And auxiliary processors can get partial results from the main ones.
A comment with such high-level details would be good to add somewhere to the code related to partial results in Pipe or in Processors/.

Comment on lines +71 to +72
bool needWatchRestartForPartialResultProgress() { return partial_result_duration_ms != 0 && partial_result_duration_ms < watch.elapsedMilliseconds(); }
void restartWatch() { watch.restart(); }

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.

Since these methods only used together I'd make it at once

Suggested change
bool needWatchRestartForPartialResultProgress() { return partial_result_duration_ms != 0 && partial_result_duration_ms < watch.elapsedMilliseconds(); }
void restartWatch() { watch.restart(); }
bool restartPartialResultWatchIfNedeed()
{
if (partial_result_duration_ms != 0 && partial_result_duration_ms < watch.elapsedMilliseconds())
watch.restart();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are separate methods here because of this part https://github.com/ClickHouse/ClickHouse/pull/48607/files#diff-e095e580e92b75f98a4be9dd98f799946573094bff8fb968054f21519e0ae48dR114

We should always stop optimization of running local task for partial result processors because they wait until next time when they can make a snapshot and because of that should be added to the end of the tasks queue. So we should restart watch also in case when needWatchRestartForPartialResultProgress is false but the current task is for partial result

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 thread src/Client/ClientBase.h Resolved
Comment thread src/Client/ClientBase.h Outdated
enum class PartialResultMode: UInt8
{
NotInit, /// Query doesn't show partial result before the first block with 0 rows.
Active, /// Query shows partial result after the first and before the second block with 0 rows.

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.

Not really clear why block with 0 rows is mentioned. Is it used to indicate the readiness of result? Consider adding more details about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, the second block with 0 elements indicates that we finished receiving blocks with partial result. The first block with 0 elements is needed to initialize the output table format using the header from the block as mentioned here https://github.com/ClickHouse/ClickHouse/pull/48607/files#diff-6093a5c41d802a9ed5c132cbeba31ed89c97402ec68b371e01bc17e39da3fd69R460

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 thread src/Core/Settings.h Resolved
{
NotReady, // Waiting for data from the previous partial result processor or awaiting a timer before creating the snapshot.
Ready, // Current partial result processor has received a snapshot from the processor in the main pipeline.
Stopped, // The processor from the main pipeline has started sending data, and the pipeline for partial results should use data from the next processors of the main pipeline.

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.

Do we send any partial results after this flag is set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't send partial results (only for single processor) if partial result processor receive Stopped flag during snapshoting.

But we don't stop a full partial pipeline. For example if a pipeline looks like this: Source -> AggragatingTransform -> MergeSortingTransform -> Output. It's possible that aggregating stage finished and we are waiting for sorting. In this case AggragatingTransformPartialResult has received Stopped flag, but MergeSortingPartialResult is receiving Ready flag because it can do snapshots.

Currently this example doesn't work because AggragatingTransformPartialResult supports only aggregation without key. The example will have more sense when aggregation with key will be also supported. The query for this example would looks like SELECT key, sum(value) FROM source GROUP BY key ORDER BY -key where all keys in the source table are different

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.

ProcessorPtr MergeSortingTransform::getPartialResultProcessor(const ProcessorPtr & current_processor, UInt64 partial_result_limit, UInt64 partial_result_duration_ms)
{
const auto & header = inputs.front().getHeader();
auto merge_sorting_processor = std::dynamic_pointer_cast<MergeSortingTransform>(current_processor);

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.

Do we assure the type? Maybe just some additional check may be intoduced to have a logical error in case of bug.

Suggested change
auto merge_sorting_processor = std::dynamic_pointer_cast<MergeSortingTransform>(current_processor);
auto merge_sorting_processor = std::dynamic_pointer_cast<MergeSortingTransform>(current_processor);
if (!merge_sorting_processor)
throw Exception(ErrorCodes:LOGICAL_ERROR, "Unexpected transform type {}", ... );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's garanted that current processor type will be same as class of this overrided method because getPartialResultProcessor is protected method of IProcessor and can be used only from static method getPartialResultProcessorPtr where the processor calls this function with itself as a current_processor.

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.

{
if (partial_result_port == nullptr)
{
auto source = std::make_shared<NullSource>(getHeader());

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.

In what cases do we insert NullSource? As far as we are bulding kind of "parallel" to the main pipeline, do we insert NullSources corresponding to reading steps in the main pipeline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We insert NullSource in case of not implemented realization of partial result processor for previous processor in the pipeline. For example PartialSortingTransform currently has no realization of corresponding partial result processor, but it works fast and it's not reasonable to make a snapshot of this processor (picture below illustrate this case)
Incomplit_partial_result

It might be useful to add a partial result processor for PartialSortingTransform as well, when we make snapshots for one of the previous processors of the main pipeline. But this will be a future work because it's impossible to implement corresponding partial result processors for all existing processors in a single PR

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 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.

I added info from Settings.h to settings.md to pass Docs Check. Also I tagged you in unresolved comments. I couldn't find answers, could you please review and respond to the threads?

@alexX512

alexX512 commented Aug 31, 2023 •

Copy link
Copy Markdown
Contributor Author

I added info from Settings.h to settings.md to pass Docs Check. Also I tagged you in unresolved comments. I couldn't find answers, could you please review and respond to the threads?

I found that replies were in the pending state and it was not obvious that others can't see them. Now they should be published could you check them? @vdimir

@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.

Great job addressing the feedback and on the PR in general!

@KochetovNicolai can we merge? Do you want to skim over?

@KochetovNicolai
KochetovNicolai merged commit 0095124 into ClickHouse:master Sep 8, 2023
@alexey-milovidov

Copy link
Copy Markdown
Member

Does it work only for a single thread?

milovidov-desktop :) select sum(size) from pypi limit 10

SELECT sum(size)
FROM pypi
LIMIT 10

Query id: 8478532b-e308-4773-9fc0-79b216795ac4

Partial result:

0 rows in set. Elapsed: 0.020 sec. 

Received exception from server (version 23.9.1):
Code: 49. DB::Exception: Received from localhost:9000. DB::Exception: Cannot add partial result transform LimitPartialResultTransform to Pipe because it has 1 input ports, but 64 expected. (LOGICAL_ERROR)

Btw, LOGICAL_ERROR acts like assert in debug build, it should be used only to check for logical errors, not for other errors.

@alexey-milovidov

Copy link
Copy Markdown
Member

@alexey-milovidov

alexey-milovidov commented Oct 8, 2023 •

Copy link
Copy Markdown
Member

@KochetovNicolai @vdimir, there is no use for this feature if it requires max_threads = 1.
If it will not be finished in a month, let's revert it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants