Improved performance of function arrayElement with constant array when one of element is an empty array #1889

This commit is contained in:
Alexey Milovidov 2018-02-13 00:06:13 +03:00
parent ac0d1f8fba
commit 3656aa0606
3 changed files with 14 additions and 2 deletions

View File

@ -61,6 +61,13 @@ void FunctionArray::executeImpl(Block & block, const ColumnNumbers & arguments,
{ {
size_t num_elements = arguments.size(); size_t num_elements = arguments.size();
if (num_elements == 0)
{
/// We should return constant empty array.
block.getByPosition(result).column = block.getByPosition(result).type->createColumnConstWithDefaultValue(block.rows());
return;
}
const DataTypePtr & return_type = block.getByPosition(result).type; const DataTypePtr & return_type = block.getByPosition(result).type;
const DataTypePtr & elem_type = static_cast<const DataTypeArray &>(*return_type).getNestedType(); const DataTypePtr & elem_type = static_cast<const DataTypeArray &>(*return_type).getNestedType();
@ -91,8 +98,7 @@ void FunctionArray::executeImpl(Block & block, const ColumnNumbers & arguments,
columns[i] = columns_holder[i].get(); columns[i] = columns_holder[i].get();
} }
/** Create and fill the result array. /// Create and fill the result array.
*/
auto out = ColumnArray::create(elem_type->createColumn()); auto out = ColumnArray::create(elem_type->createColumn());
IColumn & out_data = out->getData(); IColumn & out_data = out->getData();

View File

@ -0,0 +1,3 @@
Array(Nothing), Const(size = 1, Array(size = 1, UInt64(size = 1), Nothing(size = 0)))
Array(Array(Array(Nothing))), Const(size = 1, Array(size = 1, UInt64(size = 1), Array(size = 1, UInt64(size = 1), Array(size = 1, UInt64(size = 1), Nothing(size = 0)))))
Array(Array(UInt8)), Const(size = 1, Array(size = 1, UInt64(size = 1), Array(size = 2, UInt64(size = 2), UInt8(size = 1))))

View File

@ -0,0 +1,3 @@
SELECT dumpColumnStructure([]);
SELECT dumpColumnStructure([[[]]]);
SELECT DISTINCT dumpColumnStructure([[], [1]]) FROM numbers(2);