-- 000003_add_indexes.sql
-- 添加缺失的业务索引以优化查询性能

-- rental_orders 索引（号主/租客查订单、状态筛选、超时扫描）
CREATE INDEX idx_rental_orders_owner_id ON rental_orders(owner_id);
CREATE INDEX idx_rental_orders_renter_id ON rental_orders(renter_id);
CREATE INDEX idx_rental_orders_status ON rental_orders(status);
CREATE INDEX idx_rental_orders_status_updated ON rental_orders(status, updated_at);
CREATE INDEX idx_rental_orders_settlement_status ON rental_orders(settlement_status);

-- handoff_records 索引
CREATE INDEX idx_handoff_records_order_id ON handoff_records(order_id);

-- notifications 索引
CREATE INDEX idx_notifications_user_id ON notifications(user_id);

-- wallet_entries 索引
CREATE INDEX idx_wallet_entries_user_id ON wallet_entries(user_id);
CREATE INDEX idx_wallet_entries_order_id ON wallet_entries(order_id);

-- disputes 索引
CREATE INDEX idx_disputes_order_id ON disputes(order_id);
CREATE INDEX idx_disputes_status ON disputes(status);

-- audit_logs 索引
CREATE INDEX idx_audit_logs_biz_type_biz_id ON audit_logs(biz_type, biz_id);
CREATE INDEX idx_audit_logs_actor_id ON audit_logs(actor_id);

-- rental_listings 补充索引
CREATE INDEX idx_rental_listings_owner_id ON rental_listings(owner_id);
CREATE INDEX idx_rental_listings_status ON rental_listings(status);
CREATE INDEX idx_rental_listings_game_name ON rental_listings(game_name);

-- order_checkouts 索引补充
CREATE INDEX idx_order_checkouts_order_id_status ON order_checkouts(order_id, status);
