-- 为资产最终套餐到期的实时投影提供稳定的主套餐队列读取索引。
CREATE INDEX idx_package_usage_expiry_iot_card_queue
    ON tb_package_usage (iot_card_id, priority ASC, created_at ASC, id ASC)
    WHERE deleted_at IS NULL
      AND master_usage_id IS NULL
      AND refund_id IS NULL
      AND status IN (0, 1, 2);

CREATE INDEX idx_package_usage_expiry_device_queue
    ON tb_package_usage (device_id, priority ASC, created_at ASC, id ASC)
    WHERE deleted_at IS NULL
      AND master_usage_id IS NULL
      AND refund_id IS NULL
      AND status IN (0, 1, 2);
