* Fixing bug in StorageLiveView.cpp getHeader() method

that sometimes addressed invalid pointer when getHeader()
  method was called without holding the mutex
This commit is contained in:
Vitaliy Zakaznikov 2019-06-14 16:27:43 -04:00
parent 13978c03f3
commit d6d0404c48

View File

@ -159,24 +159,18 @@ Block StorageLiveView::getHeader() const
{ {
if (!sample_block) if (!sample_block)
{ {
if (!(*blocks_ptr) || (*blocks_ptr)->empty()) auto storage = global_context.getTable(select_database_name, select_table_name);
sample_block = InterpreterSelectQuery(inner_query, global_context, storage,
SelectQueryOptions(QueryProcessingStage::Complete)).getSampleBlock();
sample_block.insert({DataTypeUInt64().createColumnConst(
sample_block.rows(), 0)->convertToFullColumnIfConst(),
std::make_shared<DataTypeUInt64>(),
"_version"});
/// convert all columns to full columns
/// in case some of them are constant
for (size_t i = 0; i < sample_block.columns(); ++i)
{ {
auto storage = global_context.getTable(select_database_name, select_table_name); sample_block.safeGetByPosition(i).column = sample_block.safeGetByPosition(i).column->convertToFullColumnIfConst();
sample_block = InterpreterSelectQuery(inner_query, global_context, storage, SelectQueryOptions(QueryProcessingStage::Complete)).getSampleBlock();
sample_block.insert({DataTypeUInt64().createColumnConst(
sample_block.rows(), 0)->convertToFullColumnIfConst(),
std::make_shared<DataTypeUInt64>(),
"_version"});
/// convert all columns to full columns
/// in case some of them are constant
for (size_t i = 0; i < sample_block.columns(); ++i)
{
sample_block.safeGetByPosition(i).column = sample_block.safeGetByPosition(i).column->convertToFullColumnIfConst();
}
}
else
{
sample_block = (*blocks_ptr)->front().cloneEmpty();
} }
} }