perf(finance): 优化财务仪表盘聚合查询

This commit is contained in:
yml2213
2026-11-02 19:11:22 +08:00
parent 1b23b9b14b
commit 1c18dbcb64
4 changed files with 49 additions and 5 deletions
@@ -0,0 +1,35 @@
-- +goose Up
-- 财务仪表盘按时间窗口聚合支付、退款和结算数据。
-- 支付索引避免退款统计扫描全部历史状态;结算与结账索引避免日报聚合回表。
ALTER TABLE payment_orders
ADD KEY idx_payment_orders_dashboard_created (created_at, biz_type, status, order_id, amount_cent),
ADD KEY idx_payment_orders_dashboard_order (order_id, biz_type, status, amount_cent);
ALTER TABLE rental_orders
ADD KEY idx_rental_orders_dashboard_settled (
settled_at,
id,
settlement_mode,
offline_settlement_status,
offline_settlement_amount_cent,
refund_status
);
ALTER TABLE order_checkouts
ADD KEY idx_order_checkouts_dashboard_accepted (
status,
order_id,
platform_fee_cent,
owner_income_amount_cent
);
-- +goose Down
ALTER TABLE order_checkouts
DROP KEY idx_order_checkouts_dashboard_accepted;
ALTER TABLE rental_orders
DROP KEY idx_rental_orders_dashboard_settled;
ALTER TABLE payment_orders
DROP KEY idx_payment_orders_dashboard_order,
DROP KEY idx_payment_orders_dashboard_created;