-- 已安装历史表的环境先执行本增量脚本,再部署清理器。MySQL 5.7+/8.0,可重复执行。 -- 只增加历史清理租约字段及基线清理索引,不删数据、不修改订单及资金表。 SET @rent_history_cleanup_sql = IF( EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='rent_history_cursor' AND COLUMN_NAME='cleanup_owner'), 'SELECT 1', 'ALTER TABLE rent_history_cursor ADD COLUMN cleanup_owner VARCHAR(64) NULL COMMENT ''清理器独立网络租约'''); PREPARE rent_history_cleanup_stmt FROM @rent_history_cleanup_sql; EXECUTE rent_history_cleanup_stmt; DEALLOCATE PREPARE rent_history_cleanup_stmt; -- 按网络/高度分批选择旧检查点,避免清理每批都排序整个地址对基线表。 SET @rent_history_cleanup_sql = IF( EXISTS(SELECT 1 FROM information_schema.STATISTICS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='rent_history_anchor' AND INDEX_NAME='idx_history_anchor_retention'), 'SELECT 1', 'ALTER TABLE rent_history_anchor ADD INDEX idx_history_anchor_retention (network,block_height)'); PREPARE rent_history_cleanup_stmt FROM @rent_history_cleanup_sql; EXECUTE rent_history_cleanup_stmt; DEALLOCATE PREPARE rent_history_cleanup_stmt; SET @rent_history_cleanup_sql = IF( EXISTS(SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='rent_history_cursor' AND COLUMN_NAME='cleanup_until'), 'SELECT 1', 'ALTER TABLE rent_history_cursor ADD COLUMN cleanup_until DATETIME(3) NULL COMMENT ''清理租约UTC截止'''); PREPARE rent_history_cleanup_stmt FROM @rent_history_cleanup_sql; EXECUTE rent_history_cleanup_stmt; DEALLOCATE PREPARE rent_history_cleanup_stmt;