Verification of the rewrite
How do you prove a maintenance rewrite preserved the data, almost for free?
Compaction already reads every byte, so computing a row count and a per-column hash aggregate before and after costs almost nothing. Yet almost nobody does it. A silent corruption caused by a maintenance rewrite has no user-visible trigger and no failing job.
-- Run on the input files, then on the output files of the rewrite:
SELECT count(*) AS row_count,
sum(hash(event_id, status, ts)) AS content_fingerprint
FROM events_partition_input; -- same query on the output; results must matchThe two results must be equal. (A sum of per-row hashes does not depend on row order, so it survives re-sorting. Overflow behavior depends on the engine.) This is write-audit-publish applied to maintenance: write the new files, audit them, and only then publish them with a commit.