Repository navigation
Conversation
|
Workflow [PR], commit [ed8dfed] Summary: ❌
|
|
The new test produces the same logical error. |
|
@alexey-milovidov seems to pass now |
…r optimization When using parallel replicas with parallel_replicas_local_plan, different replicas were computing different "fixed columns" due to non-deterministic DAG-based detection. This caused coordination failures where one replica decided to read in ReverseOrder while another chose WithOrder. Solution: - Add needsDeterministicFixedColumns() method to ReadFromMergeTree that returns true when both parallel replicas and parallel_replicas_local_plan are enabled - Use AST-based fixed column detection (via getFixedSortingColumns) instead of DAG-based when deterministic detection is needed - This ensures all replicas compute the same fixed columns and agree on read order
d3c84c0 to
6478122
Compare
…r optimization When using parallel replicas with parallel_replicas_local_plan, different replicas were computing different "fixed columns" due to non-deterministic DAG-based detection. This caused coordination failures where one replica decided to read in ReverseOrder while another chose WithOrder. Solution: - Add needsDeterministicFixedColumns() method to ReadFromMergeTree that returns true when both parallel replicas and parallel_replicas_local_plan are enabled - Use AST-based fixed column detection (via getFixedSortingColumns) instead of DAG-based when deterministic detection is needed - This ensures all replicas compute the same fixed columns and agree on read order
e6106dd to
864b3c2
Compare
…r optimization Use AST-based fixed column detection for parallel replicas with local plan to ensure deterministic read order decisions across all replicas. DAG-based detection can differ between replicas due to non-deterministic DAG structures, causing coordination mode mismatch errors (WithOrder vs ReverseOrder). The fix uses getFixedSortingColumns() for AST-based detection when is_parallel_reading_from_replicas && parallel_replicas_local_plan are both enabled, while keeping DAG-based detection for normal queries to preserve full optimization.
Reverts the unintended submodule updates that were included in commit 864b3c2. The following submodules have been restored to their previous commits: - contrib/AMQP-CPP - contrib/boost - contrib/c-ares - contrib/cctz - contrib/chdig - contrib/croaring - contrib/libcpuid - contrib/librdkafka - contrib/llvm-project - contrib/openssl
- Inline needsDeterministicFixedColumns() logic for better clarity - Revert unnecessary code style changes (use idiomatic if declarations) - Remove trailing whitespaces - Remove duplicate include of Core/Settings.h The functional behavior for parallel replicas coordination remains unchanged.
752d46a to
e5a5ee3
Compare
|
Add a changelog entry please, as in the template: https://github.com/ClickHouse/ClickHouse/blob/master/.github/PULL_REQUEST_TEMPLATE.md |
|
The test fails: 03789_read_in_order_constant_column_direction. |
fbea28e to
6b48144
Compare
| ORDER BY (tenant, event_time); | ||
|
|
||
| -- Insert deterministic test data | ||
| INSERT INTO t_read_in_order_coordination SELECT 1, number FROM numbers(10); |
There was a problem hiding this comment.
The test contains way too less data. In most of the runs local replicas will handle all the data and remote replicas will have almost no chance to respond to the query execution (the query execution on remote replicas will be cancelled).
To make the probability of getting first response from a remote replica higher, I would suggest to set index_granularity = 1, and populate the table with more data.
There was a problem hiding this comment.
Have a look if I added enough data
0d89513 to
897ab88
Compare
This ensures plan stability with parallel replicas by enabling AST-based fixed column detection, which works reliably regardless of DAG transformations.
897ab88 to
52c1b65
Compare
The previous fix was checking if parallel replicas are actually active, but the parallel_replicas_local_plan setting can affect query plan building even when parallel replicas are not active. This caused DAG-based fixed column detection to fail in normal queries when the setting was enabled via randomized settings. Now use AST-based detection when: - parallel replicas are active AND parallel_replicas_local_plan is enabled, OR - running on initiator with parallel replicas capability This fixes test_03789_read_in_order_constant_column_direction which expects read-in-order optimization to work even with parallel_replicas_local_plan=1 in randomized settings.
Remove the parallel_replicas_local_plan setting check and always use AST-based fixed column detection for any parallel replicas scenario. This provides: - Simpler, more maintainable code - Consistent behavior for both local_plan=0 and local_plan=1 - Fixed optimization for local_plan=0 (previously missed due to DAG issues) The AST-based detection is more conservative but deterministic, which is what we need for parallel replicas coordination.
The previous implementation only worked with the old analyzer (ASTSelectQuery). When the new analyzer is used, query_info.query_tree contains a QueryNode instead. Changes: - Add overload of getFixedSortingColumns that takes condition AST directly - Update isFixedColumnForReadInOrder to handle both analyzers: - New analyzer: extract WHERE/PREWHERE from QueryNode via toAST() - Old analyzer: extract from ASTSelectQuery - Combine WHERE + PREWHERE using makeASTForLogicalAnd This fixes the test failure when running with ParallelReplicas configuration which uses the new analyzer.
The test requires optimize_read_in_order=1 to work. When the test runner randomizes settings, it can set optimize_read_in_order=0, causing the test to fail even though the SET statement should override it. Adding the no-random-settings tag prevents any setting randomization for this test.
Without local plan, read-in-order optimization is skipped for parallel replicas (due to readingFromParallelReplicas check). Setting local_plan=1 ensures the optimization applies and the test works in ParallelReplicas CI configuration.
Refactor read-in-order optimization to use QueryTree-based detection for fixed columns when parallel replicas are enabled. This ensures deterministic results across replicas and correctly handles JOINs by checking table aliases. - Add getFixedColumnsFromQueryTree() helper that traverses QueryTree conditions and filters columns by table alias - Update isFixedColumnForReadInOrder() to use QueryTree-based detection for parallel replicas, falling back to DAG-based for other cases - Revert changes to ReadInOrderOptimizer (not needed with new approach) - Remove no-random-settings tag and parallel_replicas_local_plan from test
|
@devcrafter |
|
I wasn't able to reproduce the error with the test provided here against master version. But I have reproduced it with query from this report #94103 (comment). It's not related to in order optimization, but to aggregation in order. Trying to fix it in #95306 (at least the repo is already there). So, I'm not exactly sure what are you trying to fix within this change, - have you been able to reproduce the issue with the test? |
|
@devcrafter I didn't reproduce it personally, but @alexey-milovidov wrote the test in another PR so I trust it |
|
After some investigation, the conclusion is that the reason for #94103 (comment) is not #94103. I've created a separate issue, - #95524. So, I'll close this PR. You can reopen it if you think that still something need to be done. |
When using parallel_replicas_local_plan, different replicas could identify different columns as "fixed" (constant due to WHERE filtering) because each replica builds its own query plan independently. This caused replicas to compute different read directions, leading to coordination mode mismatch errors like "Replica N decided to read in WithOrder mode, not in ReverseOrder".
The fix uses AST-based fixed column detection (via getFixedSortingColumns) instead of DAG-based detection when in parallel replicas local plan mode. AST-based detection analyzes the original WHERE/PREWHERE clauses and produces deterministic results across all replicas.
The bug introduced in #94103
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed regression causing parallel replicas coordination failures with parallel_replicas_local_plan in read-in-order optimization.