-- ===========================================================================
-- 99c-bulk-index.sql : 대량 데이터 운영 인덱스. 화면/조회 쿼리 응답성 확보.
--   (실운영 매입시스템의 상시 인덱스에 해당) 전부 IF NOT EXISTS (idempotent).
-- ===========================================================================
CREATE INDEX IF NOT EXISTS ix_purchase_bizdate  ON purchase(biz_date);
CREATE INDEX IF NOT EXISTS ix_purchase_merch     ON purchase(merchant_id);
CREATE INDEX IF NOT EXISTS ix_purchase_status    ON purchase(status);
CREATE INDEX IF NOT EXISTS ix_purchase_merch_day ON purchase(merchant_id, biz_date);
CREATE INDEX IF NOT EXISTS ix_settlement_bizdate ON settlement(biz_date);
CREATE INDEX IF NOT EXISTS ix_settlement_merch   ON settlement(merchant_id);
CREATE INDEX IF NOT EXISTS ix_ledger_bizdate     ON ledger(biz_date);
CREATE INDEX IF NOT EXISTS ix_ledger_pid         ON ledger(purchase_id);
CREATE INDEX IF NOT EXISTS ix_cmlog_bizdate      ON cm_log(biz_date);
CREATE INDEX IF NOT EXISTS ix_cmlog_level        ON cm_log(log_level);
CREATE INDEX IF NOT EXISTS ix_funding_merch      ON st_merchant_funding(merchant_id);
CREATE INDEX IF NOT EXISTS ix_netset_bizdate     ON st_net_settlement(biz_date);
CREATE INDEX IF NOT EXISTS ix_clearing_bizdate   ON mg_clearing(biz_date);
CREATE INDEX IF NOT EXISTS ix_mercsum_day        ON merchant_summary(biz_date);
ANALYZE purchase; ANALYZE settlement; ANALYZE ledger; ANALYZE st_fee_component;
ANALYZE st_merchant_funding; ANALYZE mg_clearing;
