mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-23 18:20:50 +00:00
Merge pull request #32641 from gulige/master
avoid inconsistent state in Block
This commit is contained in:
commit
2c73ee2758
@ -145,15 +145,17 @@ void Block::insert(size_t position, ColumnWithTypeAndName elem)
|
||||
if (elem.name.empty())
|
||||
throw Exception("Column name in Block cannot be empty", ErrorCodes::AMBIGUOUS_COLUMN_NAME);
|
||||
|
||||
for (auto & name_pos : index_by_name)
|
||||
if (name_pos.second >= position)
|
||||
++name_pos.second;
|
||||
|
||||
auto [it, inserted] = index_by_name.emplace(elem.name, position);
|
||||
auto [new_it, inserted] = index_by_name.emplace(elem.name, position);
|
||||
if (!inserted)
|
||||
checkColumnStructure<void>(data[it->second], elem,
|
||||
checkColumnStructure<void>(data[new_it->second], elem,
|
||||
"(columns with identical name must have identical structure)", true, ErrorCodes::AMBIGUOUS_COLUMN_NAME);
|
||||
|
||||
for (auto it = index_by_name.begin(); it != index_by_name.end(); ++it)
|
||||
{
|
||||
if (it->second >= position && (!inserted || it != new_it))
|
||||
++it->second;
|
||||
}
|
||||
|
||||
data.emplace(data.begin() + position, std::move(elem));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user