mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 02:12:21 +00:00
Merge pull request #72854 from CurtizJ/fix-block-number-update-all
Fix update of all columns in presence of `_block_number` column
This commit is contained in:
commit
94709d7a5a
@ -73,7 +73,6 @@ namespace ErrorCodes
|
||||
extern const int NO_SUCH_COLUMN_IN_TABLE;
|
||||
extern const int CANNOT_UPDATE_COLUMN;
|
||||
extern const int UNEXPECTED_EXPRESSION;
|
||||
extern const int THERE_IS_NO_COLUMN;
|
||||
extern const int ILLEGAL_STATISTICS;
|
||||
}
|
||||
|
||||
@ -603,10 +602,6 @@ void MutationsInterpreter::prepare(bool dry_run)
|
||||
if (available_columns_set.emplace(name).second)
|
||||
available_columns.push_back(name);
|
||||
}
|
||||
else if (!available_columns_set.contains(name))
|
||||
{
|
||||
throw Exception(ErrorCodes::THERE_IS_NO_COLUMN, "Column {} is updated but not requested to read", name);
|
||||
}
|
||||
|
||||
updated_columns.insert(name);
|
||||
}
|
||||
@ -1107,6 +1102,21 @@ void MutationsInterpreter::prepareMutationStages(std::vector<Stage> & prepared_s
|
||||
}
|
||||
}
|
||||
|
||||
auto storage_columns = metadata_snapshot->getColumns().getNamesOfPhysical();
|
||||
|
||||
/// Add persistent virtual columns if the whole part is rewritten,
|
||||
/// because we should preserve them in parts after mutation.
|
||||
if (prepared_stages.back().isAffectingAllColumns(storage_columns))
|
||||
{
|
||||
for (const auto & column_name : available_columns)
|
||||
{
|
||||
if (column_name == RowExistsColumn::name && has_filters && !deleted_mask_updated)
|
||||
continue;
|
||||
|
||||
prepared_stages.back().output_columns.insert(column_name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Now, calculate `expressions_chain` for each stage except the first.
|
||||
/// Do it backwards to propagate information about columns required as input for a stage to the previous stage.
|
||||
for (int64_t i = prepared_stages.size() - 1; i >= 0; --i)
|
||||
|
@ -170,7 +170,12 @@ private:
|
||||
Source source;
|
||||
StorageMetadataPtr metadata_snapshot;
|
||||
MutationCommands commands;
|
||||
|
||||
/// List of columns in table or in data part that can be updated by mutation.
|
||||
/// If mutation affects all columns (e.g. DELETE), all of this columns
|
||||
/// must be returned by pipeline created in MutationsInterpreter.
|
||||
Names available_columns;
|
||||
|
||||
ContextPtr context;
|
||||
Settings settings;
|
||||
SelectQueryOptions select_limits;
|
||||
|
@ -0,0 +1,4 @@
|
||||
2
|
||||
3
|
||||
2
|
||||
3
|
27
tests/queries/0_stateless/03275_block_number_update.sql
Normal file
27
tests/queries/0_stateless/03275_block_number_update.sql
Normal file
@ -0,0 +1,27 @@
|
||||
DROP TABLE IF EXISTS t_block_number_mut;
|
||||
|
||||
SET mutations_sync = 2;
|
||||
|
||||
CREATE TABLE t_block_number_mut (n int) ENGINE = MergeTree ORDER BY tuple() SETTINGS enable_block_number_column = 1, min_bytes_for_wide_part = 0;
|
||||
|
||||
INSERT INTO t_block_number_mut VALUES (1) (2);
|
||||
|
||||
OPTIMIZE TABLE t_block_number_mut FINAL;
|
||||
|
||||
ALTER TABLE t_block_number_mut UPDATE n = n + 1 WHERE 1;
|
||||
|
||||
SELECT * FROM t_block_number_mut;
|
||||
|
||||
DROP TABLE IF EXISTS t_block_number_mut;
|
||||
|
||||
CREATE TABLE t_block_number_mut (n int) ENGINE = MergeTree ORDER BY tuple() SETTINGS enable_block_number_column = 1, min_bytes_for_wide_part = '1G';
|
||||
|
||||
INSERT INTO t_block_number_mut VALUES (1) (2);
|
||||
|
||||
OPTIMIZE TABLE t_block_number_mut FINAL;
|
||||
|
||||
ALTER TABLE t_block_number_mut UPDATE n = n + 1 WHERE 1;
|
||||
|
||||
SELECT * FROM t_block_number_mut;
|
||||
|
||||
DROP TABLE IF EXISTS t_block_number_mut;
|
Loading…
Reference in New Issue
Block a user