Backport #70695 to 24.8: Fixed crash in filling of missed arrays

This commit is contained in:
robot-clickhouse 2024-10-16 16:06:51 +00:00
parent 0c5784c3a3
commit 0ef6b35b7f
4 changed files with 43 additions and 6 deletions

View File

@ -156,13 +156,21 @@ void IMergeTreeReader::evaluateMissingDefaults(Block additional_columns, Columns
auto it = original_requested_columns.begin();
for (size_t pos = 0; pos < num_columns; ++pos, ++it)
{
auto name_in_storage = it->getNameInStorage();
if (full_requested_columns_set.emplace(name_in_storage).second)
full_requested_columns.emplace_back(name_in_storage, it->getTypeInStorage());
if (res_columns[pos])
{
/// If column is already read, request it as is.
if (full_requested_columns_set.emplace(it->name).second)
full_requested_columns.emplace_back(it->name, it->type);
additional_columns.insert({res_columns[pos], it->type, it->name});
}
else
{
/// If column or subcolumn is missed, request full column for correct evaluation of defaults of subcolumns.
auto name_in_storage = it->getNameInStorage();
if (full_requested_columns_set.emplace(name_in_storage).second)
full_requested_columns.emplace_back(name_in_storage, it->getTypeInStorage());
}
}
auto dag = DB::evaluateMissingDefaults(
@ -183,6 +191,12 @@ void IMergeTreeReader::evaluateMissingDefaults(Block additional_columns, Columns
it = original_requested_columns.begin();
for (size_t pos = 0; pos < num_columns; ++pos, ++it)
{
if (additional_columns.has(it->name))
{
res_columns[pos] = additional_columns.getByName(it->name).column;
continue;
}
auto name_in_storage = it->getNameInStorage();
res_columns[pos] = additional_columns.getByName(name_in_storage).column;

View File

@ -27,5 +27,5 @@
2 ('aaa','bbb') [1,NULL,3]
3 ('ccc','ddd') [4,5,6]
1 foo bar 3 [0,1,0]
2 foo bar 3 [0,1,0]
2 aaa bbb 3 [0,1,0]
3 ccc ddd 3 [0,0,0]

View File

@ -0,0 +1 @@
20000

View File

@ -0,0 +1,22 @@
DROP TABLE IF EXISTS t_fill_arrays;
CREATE TABLE t_fill_arrays
(
`id` String,
`mapCol` Map(String, Array(String)),
)
ENGINE = MergeTree
ORDER BY id
SETTINGS vertical_merge_algorithm_min_rows_to_activate = 1, vertical_merge_algorithm_min_columns_to_activate = 1, min_bytes_for_full_part_storage = 0;
INSERT INTO t_fill_arrays (id) SELECT hex(number) FROM numbers(10000);
ALTER TABLE t_fill_arrays ADD COLUMN arrCol Array(String) DEFAULT [];
INSERT INTO t_fill_arrays (id) SELECT hex(number) FROM numbers(10000);
SELECT count() FROM t_fill_arrays WHERE NOT ignore(arrCol, mapCol.values);
OPTIMIZE TABLE t_fill_arrays FINAL;
DROP TABLE t_fill_arrays;