consider the case of alter table add projection

This commit is contained in:
jsc0218 2024-07-29 20:57:21 +00:00
parent 36c57ca50b
commit 09619e6006
3 changed files with 35 additions and 2 deletions

View File

@ -3211,6 +3211,16 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context
queryToString(mutation_commands.ast()));
}
/// Block the case of alter table add projection for special merge trees.
if (std::any_of(commands.begin(), commands.end(), [](const AlterCommand & c) { return c.type == AlterCommand::ADD_PROJECTION; }))
{
if (auto storage_name = getName(); storage_name != "MergeTree" && storage_name != "ReplicatedMergeTree"
&& settings_from_storage->deduplicate_merge_projection_mode == DeduplicateMergeProjectionMode::THROW)
throw Exception(ErrorCodes::NOT_IMPLEMENTED,
"Projection is fully supported in (Replictaed)MergeTree, but also allowed in non-throw mode with other"
" mergetree family members. Consider drop or rebuild option of deduplicate_merge_projection_mode.");
}
commands.apply(new_metadata, local_context);
if (AlterCommands::hasFullTextIndex(new_metadata) && !settings.allow_experimental_full_text_index)

View File

@ -59,8 +59,7 @@ OPTIMIZE TABLE tp FINAL;
-- expecting no projection
SYSTEM FLUSH LOGS;
SELECT
name,
part_name
name
FROM system.projection_parts
WHERE (database = currentDatabase()) AND (`table` = 'tp') AND (active = 1);
@ -81,4 +80,27 @@ ALTER TABLE tp MODIFY SETTING deduplicate_merge_projection_mode = 'throw';
OPTIMIZE TABLE tp DEDUPLICATE; -- { serverError NOT_IMPLEMENTED }
DROP TABLE tp;
-- test alter add projection case
CREATE TABLE tp (
type Int32,
eventcnt UInt64
) engine = ReplacingMergeTree order by type;
ALTER TABLE tp ADD PROJECTION p (SELECT sum(eventcnt), type GROUP BY type); -- { serverError NOT_IMPLEMENTED }
ALTER TABLE tp MODIFY SETTING deduplicate_merge_projection_mode = 'drop';
ALTER TABLE tp ADD PROJECTION p (SELECT sum(eventcnt), type GROUP BY type);
INSERT INTO tp SELECT number%3, 1 FROM numbers(3);
SYSTEM FLUSH LOGS;
-- expecting projection p
SELECT
name
FROM system.projection_parts
WHERE (database = currentDatabase()) AND (`table` = 'tp') AND (active = 1);
DROP TABLE tp;