Merge pull request #44959 from liangliangpan/liangliangpan-patch-fix-alter-ttl-error

fix alter table ttl error  when wide part has light weight delete mask
This commit is contained in:
Alexander Gololobov 2023-01-10 01:17:08 +01:00 committed by GitHub
commit 4a6ceb8a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 0 deletions

View File

@ -440,6 +440,13 @@ ASTPtr MutationsInterpreter::prepare(bool dry_run)
const ProjectionsDescription & projections_desc = metadata_snapshot->getProjections();
NamesAndTypesList all_columns = columns_desc.getAllPhysical();
/// Add _row_exists column if it is physically present in the part
if (auto part_storage = dynamic_pointer_cast<DB::StorageFromMergeTreeDataPart>(storage))
{
if (part_storage->hasLightweightDeletedMask())
all_columns.push_back({LightweightDeleteDescription::FILTER_COLUMN});
}
NameSet updated_columns;
bool materialize_ttl_recalculate_only = materializeTTLRecalculateOnly(storage);

View File

@ -0,0 +1,25 @@
-- { echoOn }
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
Rows in parts 100000
SELECT 'Count', count() FROM lwd_test_02521;
Count 100000
DELETE FROM lwd_test_02521 WHERE id < 25000;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
Rows in parts 100000
SELECT 'Count', count() FROM lwd_test_02521;
Count 50000
ALTER TABLE lwd_test_02521 MODIFY TTL event_time + INTERVAL 1 MONTH SETTINGS mutations_sync = 1;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
Rows in parts 50000
SELECT 'Count', count() FROM lwd_test_02521;
Count 25000
ALTER TABLE lwd_test_02521 DELETE WHERE id >= 40000 SETTINGS mutations_sync = 1;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
Rows in parts 40000
SELECT 'Count', count() FROM lwd_test_02521;
Count 15000
OPTIMIZE TABLE lwd_test_02521 FINAL SETTINGS mutations_sync = 1;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
Rows in parts 15000
SELECT 'Count', count() FROM lwd_test_02521;
Count 15000

View File

@ -0,0 +1,46 @@
DROP TABLE IF EXISTS lwd_test_02521;
CREATE TABLE lwd_test_02521 (id UInt64, value String, event_time DateTime)
ENGINE MergeTree()
ORDER BY id
SETTINGS min_bytes_for_wide_part = 0;
INSERT INTO lwd_test_02521 SELECT number, randomString(10), now() - INTERVAL 2 MONTH FROM numbers(50000);
INSERT INTO lwd_test_02521 SELECT number, randomString(10), now() FROM numbers(50000);
OPTIMIZE TABLE lwd_test_02521 FINAL SETTINGS mutations_sync = 1;
SET mutations_sync=1;
SET allow_experimental_lightweight_delete = 1;
-- { echoOn }
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
SELECT 'Count', count() FROM lwd_test_02521;
DELETE FROM lwd_test_02521 WHERE id < 25000;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
SELECT 'Count', count() FROM lwd_test_02521;
ALTER TABLE lwd_test_02521 MODIFY TTL event_time + INTERVAL 1 MONTH SETTINGS mutations_sync = 1;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
SELECT 'Count', count() FROM lwd_test_02521;
ALTER TABLE lwd_test_02521 DELETE WHERE id >= 40000 SETTINGS mutations_sync = 1;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
SELECT 'Count', count() FROM lwd_test_02521;
OPTIMIZE TABLE lwd_test_02521 FINAL SETTINGS mutations_sync = 1;
SELECT 'Rows in parts', SUM(rows) FROM system.parts WHERE database = currentDatabase() AND table = 'lwd_test_02521' AND active;
SELECT 'Count', count() FROM lwd_test_02521;
-- { echoOff }
DROP TABLE lwd_test_02521;