Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix constants in the result of MergingSortedAlgorithm. #46493

Merged
merged 5 commits into from Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Processors/Merges/Algorithms/MergedData.h
Expand Up @@ -60,7 +60,19 @@ class MergedData
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot insert to MergedData from Chunk because MergedData is not empty.");

UInt64 num_rows = chunk.getNumRows();
columns = chunk.mutateColumns();
UInt64 num_columns = chunk.getNumColumns();
auto chunk_columns = chunk.mutateColumns();

/// Here is a special code for constant columns.
/// Currently, 'columns' will contain constants, but 'chunk_columns' will not.
/// We want to keep constants in the result, so just re-create them carefully.
for (size_t i = 0; i < num_columns; ++i)
{
if (isColumnConst(*columns[i]))
columns[i] = columns[i]->cloneResized(num_rows);
else
columns[i] = std::move(chunk_columns[i]);
}

if (rows_size < num_rows)
{
Expand Down
@@ -0,0 +1,4 @@
constant_1 250000
constant_1 2000000
constant_1 test_value_1
constant_1 test_value_2
@@ -0,0 +1,27 @@
drop table if exists test_table;
CREATE TABLE test_table (string_value String) ENGINE = MergeTree ORDER BY string_value;
system stop merges test_table;
insert into test_table select * from (
devcrafter marked this conversation as resolved.
Show resolved Hide resolved
select 'test_value_1'
from numbers_mt(250000)
union all
select 'test_value_2'
from numbers_mt(2000000)
)
order by rand();

select distinct
'constant_1' as constant_value,
count(*) over(partition by constant_value, string_value) as value_cnt
from (
select string_value
from test_table
);

select distinct
'constant_1' as constant_value, *
from (select string_value from test_table)
ORDER BY constant_value, string_value settings max_threads=1;

system start merges test_table;
drop table test_table;