Improve aliased_column_distributed_bug, fix check

This commit is contained in:
vdimir 2021-08-16 17:44:41 +03:00
parent db187c6b2d
commit 910787c5b6
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
4 changed files with 28 additions and 4 deletions

View File

@ -138,8 +138,6 @@ struct SelectQueryOptions
shard_count = shard_count_;
return *this;
}
bool hasShardInfo() const { return shard_num.has_value() || shard_count.has_value(); }
};
}

View File

@ -976,7 +976,8 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
result.required_source_columns_before_expanding_alias_columns = result.required_source_columns.getNames();
/// rewrite filters for select query, must go after getArrayJoinedColumns
if (settings.optimize_respect_aliases && result.metadata_snapshot && !select_options.hasShardInfo())
bool is_initiator = getContext()->getClientInfo().distributed_depth == 0;
if (settings.optimize_respect_aliases && result.metadata_snapshot && is_initiator)
{
/// If query is changed, we need to redo some work to correct name resolution.
if (replaceAliasColumnsInQuery(query, result.metadata_snapshot->getColumns(), result.array_join_result_to_source, getContext()))

View File

@ -0,0 +1,20 @@
0
0
0
0
0
0
6
7
8
9
0
0
0
0
0
0
6
7
8
9

View File

@ -1,10 +1,15 @@
DROP TABLE IF EXISTS click_storage;
DROP TABLE IF EXISTS click_storage_dst;
CREATE TABLE click_storage ( `PhraseID` UInt64, `PhraseProcessedID` UInt64 ALIAS if(PhraseID > 0, PhraseID, 0) ) ENGINE = MergeTree() ORDER BY tuple();
CREATE TABLE click_storage ( `PhraseID` UInt64, `PhraseProcessedID` UInt64 ALIAS if(PhraseID > 5, PhraseID, 0) ) ENGINE = MergeTree() ORDER BY tuple();
INSERT INTO click_storage SELECT number AS PhraseID from numbers(10);
CREATE TABLE click_storage_dst ( `PhraseID` UInt64, `PhraseProcessedID` UInt64 ) ENGINE = Distributed(test_shard_localhost, currentDatabase(), 'click_storage');
SET prefer_localhost_replica = 1;
SELECT materialize(PhraseProcessedID) FROM click_storage_dst;
SET prefer_localhost_replica = 0;
SELECT materialize(PhraseProcessedID) FROM click_storage_dst;
DROP TABLE IF EXISTS click_storage;