diff --git a/src/Functions/array/arrayElement.cpp b/src/Functions/array/arrayElement.cpp index 51f2ef659cdd..79c09b4d0443 100644 --- a/src/Functions/array/arrayElement.cpp +++ b/src/Functions/array/arrayElement.cpp @@ -277,8 +277,7 @@ struct ArrayElementStringImpl ColumnArray::Offset current_offset = 0; /// get the total result bytes at first, and reduce the cost of result_data.resize. size_t total_result_bytes = 0; - ColumnString::Chars zero_buf(1); - zero_buf.push_back(0); + ColumnString::Chars zero_buf(16, '\0'); /// Needs 15 extra bytes for memcpySmallAllowReadWriteOverflow15 std::vector> selected_bufs; selected_bufs.reserve(size); for (size_t i = 0; i < size; ++i) @@ -344,8 +343,7 @@ struct ArrayElementStringImpl size_t size = offsets.size(); result_offsets.resize(size); - ColumnString::Chars zero_buf(1); - zero_buf.push_back(0); + ColumnString::Chars zero_buf(16, '\0'); /// Needs 15 extra bytes for memcpySmallAllowReadWriteOverflow15 ColumnArray::Offset current_offset = 0; /// get the total result bytes at first, and reduce the cost of result_data.resize. size_t total_result_bytes = 0; diff --git a/tests/queries/0_stateless/02983_empty_map.reference b/tests/queries/0_stateless/02983_empty_map.reference new file mode 100644 index 000000000000..fadedaf23aec --- /dev/null +++ b/tests/queries/0_stateless/02983_empty_map.reference @@ -0,0 +1,7 @@ +-- { echoOn } +SELECT f1, f2['2'], count() FROM t1 GROUP BY 1,2 order by 1,2; +1 1000111 +SELECT f1, f3['2'], count() FROM t1 GROUP BY 1,2 order by 1,2; +1 1000111 +SELECT f1, f4[2], count() FROM t1 GROUP BY 1,2 order by 1,2; +1 0 1000111 diff --git a/tests/queries/0_stateless/02983_empty_map.sql b/tests/queries/0_stateless/02983_empty_map.sql new file mode 100644 index 000000000000..78bc5d8736fa --- /dev/null +++ b/tests/queries/0_stateless/02983_empty_map.sql @@ -0,0 +1,21 @@ +--https://github.com/ClickHouse/ClickHouse/issues/59402 +CREATE TABLE t1 +( + f1 Int32, + f2 Map(LowCardinality(String),LowCardinality(String)), + f3 Map(String,String), + f4 Map(Int32,Int32) +) +ENGINE=Memory AS +SELECT 1 as f1, + map(number%2,number%10) as f2, + f2 as f3, + f2 as f4 +from numbers(1000111); + +SET max_block_size=10; + +-- { echoOn } +SELECT f1, f2['2'], count() FROM t1 GROUP BY 1,2 order by 1,2; +SELECT f1, f3['2'], count() FROM t1 GROUP BY 1,2 order by 1,2; +SELECT f1, f4[2], count() FROM t1 GROUP BY 1,2 order by 1,2;