Repository navigation
Add settings for real-time updates during query execution - #48607
Conversation
|
This is an automated comment for commit 36b8932 with description of existing statuses. It's updated for the latest CI running
|
vdimir
left a comment
There was a problem hiding this comment.
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/.
| bool needWatchRestartForPartialResultProgress() { return partial_result_duration_ms != 0 && partial_result_duration_ms < watch.elapsedMilliseconds(); } | ||
| void restartWatch() { watch.restart(); } |
There was a problem hiding this comment.
Since these methods only used together I'd make it at once
| 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(); | |
| } |
There was a problem hiding this comment.
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
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| { | ||
| 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. |
There was a problem hiding this comment.
Do we send any partial results after this flag is set?
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
Do we assure the type? Maybe just some additional check may be intoduced to have a logical error in case of bug.
| 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 {}", ... ); |
There was a problem hiding this comment.
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.
| { | ||
| if (partial_result_port == nullptr) | ||
| { | ||
| auto source = std::make_shared<NullSource>(getHeader()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)

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
…orm and more comments
vdimir
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Great job addressing the feedback and on the PR in general!
@KochetovNicolai can we merge? Do you want to skim over?
|
Does it work only for a single thread? Btw, LOGICAL_ERROR acts like assert in debug build, it should be used only to check for logical errors, not for other errors. |
|
@KochetovNicolai @vdimir, there is no use for this feature if it requires |
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):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add options
partial_result_update_duration_msandmax_rows_in_partial_resultto 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