Merge pull request #32641 from gulige/master

avoid inconsistent state in Block
This commit is contained in:
alexey-milovidov 2021-12-24 03:54:38 +03:00 committed by GitHub
commit 2c73ee2758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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));
}