mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Slightly optimize ColumnArray::get()/operator[] (by using reserve over resize)
Note, that simple "SELECT range(100)" will execute ColumnArray::operator[] 14 times (most of them from DB::checkColumnStructure()) Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
parent
63d8d75001
commit
4e07122079
@ -134,10 +134,11 @@ Field ColumnArray::operator[](size_t n) const
|
|||||||
throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array of size {} is too large to be manipulated as single field, maximum size {}",
|
throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array of size {} is too large to be manipulated as single field, maximum size {}",
|
||||||
size, max_array_size_as_field);
|
size, max_array_size_as_field);
|
||||||
|
|
||||||
Array res(size);
|
Array res;
|
||||||
|
res.reserve(size);
|
||||||
|
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
res[i] = getData()[offset + i];
|
res.push_back(getData()[offset + i]);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -152,11 +153,12 @@ void ColumnArray::get(size_t n, Field & res) const
|
|||||||
throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array of size {} is too large to be manipulated as single field, maximum size {}",
|
throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Array of size {} is too large to be manipulated as single field, maximum size {}",
|
||||||
size, max_array_size_as_field);
|
size, max_array_size_as_field);
|
||||||
|
|
||||||
res = Array(size);
|
res = Array();
|
||||||
Array & res_arr = DB::get<Array &>(res);
|
Array & res_arr = DB::get<Array &>(res);
|
||||||
|
res_arr.reserve(size);
|
||||||
|
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
getData().get(offset + i, res_arr[i]);
|
res_arr.push_back(getData()[offset + i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user