-- 为每日临期节点扫描增加按到期时间预筛的主套餐索引。
CREATE INDEX IF NOT EXISTS idx_package_usage_card_expiry_scan
    ON tb_package_usage (expires_at, iot_card_id)
    WHERE deleted_at IS NULL
      AND master_usage_id IS NULL
      AND refund_id IS NULL
      AND status IN (1, 2)
      AND expires_at IS NOT NULL;

CREATE INDEX IF NOT EXISTS idx_package_usage_device_expiry_scan
    ON tb_package_usage (expires_at, device_id)
    WHERE deleted_at IS NULL
      AND master_usage_id IS NULL
      AND refund_id IS NULL
      AND status IN (1, 2)
      AND expires_at IS NOT NULL;
