Skip to content

Commit

Permalink
Manual cherry-pick of #6780
Browse files Browse the repository at this point in the history
  • Loading branch information
alesapin committed Oct 28, 2019
1 parent ddb7e31 commit ba8c698
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 25 deletions.
39 changes: 15 additions & 24 deletions dbms/src/Storages/MergeTree/MergedColumnOnlyOutputStream.cpp
Expand Up @@ -19,32 +19,24 @@ MergedColumnOnlyOutputStream::MergedColumnOnlyOutputStream(
header(header_), part_path(part_path_), sync(sync_), skip_offsets(skip_offsets_),
already_written_offset_columns(already_written_offset_columns_)
{
}
serialization_states.reserve(header.columns());
WrittenOffsetColumns tmp_offset_columns;
IDataType::SerializeBinaryBulkSettings settings;

void MergedColumnOnlyOutputStream::write(const Block & block)
{
if (!initialized)
for (const auto & column_name : header.getNames())
{
column_streams.clear();
serialization_states.clear();
serialization_states.reserve(block.columns());
WrittenOffsetColumns tmp_offset_columns;
IDataType::SerializeBinaryBulkSettings settings;

for (size_t i = 0; i < block.columns(); ++i)
{
const auto & col = block.safeGetByPosition(i);

const auto columns = storage.getColumns();
addStreams(part_path, col.name, *col.type, columns.getCodecOrDefault(col.name, codec), 0, skip_offsets);
serialization_states.emplace_back(nullptr);
settings.getter = createStreamGetter(col.name, tmp_offset_columns, false);
col.type->serializeBinaryBulkStatePrefix(settings, serialization_states.back());
}

initialized = true;
const auto & col = header.getByName(column_name);

const auto columns = storage.getColumns();
addStreams(part_path, col.name, *col.type, columns.getCodecOrDefault(col.name, codec), 0, skip_offsets);
serialization_states.emplace_back(nullptr);
settings.getter = createStreamGetter(col.name, tmp_offset_columns, false);
col.type->serializeBinaryBulkStatePrefix(settings, serialization_states.back());
}
}

void MergedColumnOnlyOutputStream::write(const Block & block)
{
size_t rows = block.rows();
if (!rows)
return;
Expand Down Expand Up @@ -83,7 +75,7 @@ MergeTreeData::DataPart::Checksums MergedColumnOnlyOutputStream::writeSuffixAndG
column.type->serializeBinaryBulkStateSuffix(serialize_settings, serialization_states[i]);


if (with_final_mark)
if (with_final_mark && (index_offset != 0 || current_mark != 0))
writeFinalMark(column.name, column.type, offset_columns, skip_offsets, serialize_settings.path);
}

Expand All @@ -100,7 +92,6 @@ MergeTreeData::DataPart::Checksums MergedColumnOnlyOutputStream::writeSuffixAndG

column_streams.clear();
serialization_states.clear();
initialized = false;

return checksums;
}
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Storages/MergeTree/MergedColumnOnlyOutputStream.h
Expand Up @@ -29,7 +29,6 @@ class MergedColumnOnlyOutputStream final : public IMergedBlockOutputStream
SerializationStates serialization_states;
String part_path;

bool initialized = false;
bool sync;
bool skip_offsets;

Expand Down
@@ -0,0 +1,2 @@
1
1
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh

. $CURDIR/mergetree_mutations.lib


${CLICKHOUSE_CLIENT} --query="DROP TABLE IF EXISTS table_with_empty_part"

${CLICKHOUSE_CLIENT} --query="CREATE TABLE table_with_empty_part
(
id UInt64,
value UInt64
)
ENGINE = MergeTree()
ORDER BY id
PARTITION BY id
SETTINGS vertical_merge_algorithm_min_rows_to_activate=0, vertical_merge_algorithm_min_columns_to_activate=0
"


${CLICKHOUSE_CLIENT} --query="INSERT INTO table_with_empty_part VALUES (1, 1)"

${CLICKHOUSE_CLIENT} --query="INSERT INTO table_with_empty_part VALUES (2, 2)"

${CLICKHOUSE_CLIENT} --query="ALTER TABLE table_with_empty_part DELETE WHERE id % 2 == 0"

sleep 0.5

mutation_id=`${CLICKHOUSE_CLIENT} --query="SELECT max(mutation_id) FROM system.mutations WHERE table='table_with_empty_part'"`

wait_for_mutation "table_with_empty_part" "$mutation_id"

${CLICKHOUSE_CLIENT} --query="SELECT COUNT(DISTINCT value) FROM table_with_empty_part"

${CLICKHOUSE_CLIENT} --query="ALTER TABLE table_with_empty_part MODIFY COLUMN value Nullable(UInt64)"

${CLICKHOUSE_CLIENT} --query="SELECT COUNT(distinct value) FROM table_with_empty_part"

${CLICKHOUSE_CLIENT} --query="OPTIMIZE TABLE table_with_empty_part FINAL"

${CLICKHOUSE_CLIENT} --query="DROP TABLE IF EXISTS table_with_empty_part"

0 comments on commit ba8c698

Please sign in to comment.