Skip to content

Commit c2b4ef1

Browse files
committed
get rid of unneeded getSampleBlock calls
1 parent 7deb461 commit c2b4ef1

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/Storages/StorageDistributed.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,6 @@ void StorageDistributed::read(
10481048

10491049
SelectQueryInfo modified_query_info = query_info;
10501050

1051-
std::vector<Block> all_headers;
10521051
std::vector<SelectQueryInfo> all_query_infos;
10531052

10541053
const auto & settings = local_context->getSettingsRef();
@@ -1081,8 +1080,9 @@ void StorageDistributed::read(
10811080

10821081
if (!additional_storages.empty())
10831082
{
1084-
for (const auto & extra_storage : additional_storages)
1083+
for (size_t i = 0; i < additional_storages.size(); ++i)
10851084
{
1085+
const auto & extra_storage = additional_storages[i];
10861086
// Create a modified query info with the additional predicate
10871087
SelectQueryInfo additional_query_info = query_info;
10881088

@@ -1092,17 +1092,12 @@ void StorageDistributed::read(
10921092
extra_storage.storage_ast,
10931093
extra_storage.storage_filter_ast);
10941094

1095-
// TODO: do we need it? somewhere here the DESCRIBE TABLE is triggered, try to avoid it.
1096-
auto additional_header = InterpreterSelectQueryAnalyzer::getSampleBlock(additional_query_tree, local_context, SelectQueryOptions(processed_stage).analyze());
1097-
1098-
for (auto & column : additional_header)
1099-
column.column = column.column->convertToFullColumnIfConst();
1095+
// We don't need to get sample block for additional storages as it triggers unnecessary analysis
1096+
// and causes issues with virtual columns that don't exist in remote tables
11001097

11011098
additional_query_info.query = queryNodeToDistributedSelectQuery(additional_query_tree);
11021099
additional_query_info.query_tree = std::move(additional_query_tree);
11031100

1104-
// TODO: do we need it?
1105-
all_headers.push_back(additional_header);
11061101
all_query_infos.push_back(additional_query_info);
11071102
}
11081103
}
@@ -1122,20 +1117,19 @@ void StorageDistributed::read(
11221117

11231118
if (!additional_storages.empty())
11241119
{
1125-
for (const auto & extra_storage : additional_storages)
1120+
for (size_t i = 0; i < additional_storages.size(); ++i)
11261121
{
1122+
const auto & extra_storage = additional_storages[i];
11271123
SelectQueryInfo additional_query_info = query_info;
11281124

1129-
// TODO: do we need it? somewhere here the DESCRIBE TABLE is triggered, try to avoid it.
1130-
auto additional_header = InterpreterSelectQuery(additional_query_info.query, local_context, SelectQueryOptions(processed_stage).analyze()).getSampleBlock();
1125+
// We don't need to get sample block for additional storages as it triggers unnecessary analysis
1126+
// and causes issues with virtual columns that don't exist in remote tables
11311127

11321128
additional_query_info.query = ClusterProxy::rewriteSelectQuery(
11331129
local_context, additional_query_info.query,
11341130
"", "", extra_storage.storage_ast,
11351131
extra_storage.storage_filter_ast);
11361132

1137-
// TODO: do we need it?
1138-
all_headers.push_back(additional_header);
11391133
all_query_infos.push_back(additional_query_info);
11401134
}
11411135
}
@@ -1192,7 +1186,6 @@ void StorageDistributed::read(
11921186
{
11931187
auto additional_query_info = all_query_infos[i];
11941188
const auto & storage = additional_storages[i].storage;
1195-
auto additional_header = all_headers[i];
11961189

11971190
// Create a new query plan for this additional storage
11981191
QueryPlan additional_plan;

0 commit comments

Comments
 (0)