-- 为已完成且未软删除的换货链双向最新记录查询增加非唯一部分索引。
CREATE INDEX idx_exchange_trace_new_asset
    ON tb_exchange_order USING btree (new_asset_type, new_asset_id, completed_at DESC NULLS LAST, id DESC)
    WHERE status = 4 AND deleted_at IS NULL;

CREATE INDEX idx_exchange_trace_old_asset
    ON tb_exchange_order USING btree (old_asset_type, old_asset_id, completed_at DESC NULLS LAST, id DESC)
    WHERE status = 4 AND deleted_at IS NULL;
