Fix "DB::Exception: Block structure mismatch in UNION stream: different number of columns" #2393
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
I encounter the following failure, and think it's a bug. The version I am using is stable 1.1.54380, and could also reproduce this problem in main branch.
== How to reproduce:
CREATE TABLE default.t ( id Int64, p_date Date) ENGINE = MergeTree PARTITION BY p_date ORDER BY id SETTINGS index_granularity = 8192
CREATE TABLE default.t_all ( id Int64, p_date Date) ENGINE = Distributed(xxx, default, t, intHash64(id))
------- :) select id from t_all where p_date='2018-01-01' limit 1
SELECT id
FROM t_all
WHERE p_date = '2018-01-01'
LIMIT 1
Received exception from server (version 1.1.54382):
Code: 171. DB::Exception: Received from localhost:9000, ::1. DB::Exception: Block structure mismatch in UNION stream: different number of columns:
id Int64 Int64(size = 0)
id Int64 Int64(size = 0), p_date Date UInt16(size = 0).
== Problem analysis:
After predicate is moved to prewhere expression, the rule to deduce columns in the result stream should be adjusted, otherwise, we should keep the PROJECT action generated by the original prewhere expression which help deduce correct stream header(block's columns).