CREATE TABLE test_on_fly_mutations (id UInt64, v String)
ENGINE = MergeTree ORDER BY id;
-- Disable background materialization of mutations to showcase
-- default behavior when on-the-fly mutations are not enabled
SYSTEM STOP MERGES test_on_fly_mutations;
SET mutations_sync = 0;
-- Insert some rows in our new table
INSERT INTO test_on_fly_mutations VALUES (1, 'a'), (2, 'b'), (3, 'c');
-- Update the values of the rows
ALTER TABLE test_on_fly_mutations UPDATE v = 'd' WHERE id = 1;
ALTER TABLE test_on_fly_mutations DELETE WHERE v = 'd';
ALTER TABLE test_on_fly_mutations UPDATE v = 'e' WHERE id = 2;
ALTER TABLE test_on_fly_mutations DELETE WHERE v = 'e';
让我们通过 SELECT 查询检查更新的结果
-- Explicitly disable on-the-fly-mutations
SET apply_mutations_on_fly = 0;
SELECT id, v FROM test_on_fly_mutations ORDER BY id;
请注意,当我们查询新表时,行的值尚未更新
┌─id─┬─v─┐
│ 1 │ a │
│ 2 │ b │
│ 3 │ c │
└────┴───┘
现在让我们看看启用实时突变时会发生什么
-- Enable on-the-fly mutations
SET apply_mutations_on_fly = 1;
SELECT id, v FROM test_on_fly_mutations ORDER BY id;