-- Drop redundant indexes to reduce write amplification on hot tables.
-- groups PK already covers (chain_id, maker, group); consumed column adds marginal value.
DROP INDEX "router_v1.14"."groups_chain_id_maker_group_consumed_idx";--> statement-breakpoint
-- obligation_collaterals_v2 PK is (obligation_key, asset); obligation_key prefix is already covered.
DROP INDEX "router_v1.14"."obligation_collaterals_v2_obligation_key_idx";--> statement-breakpoint
-- oracle_address is only used in JOINs where rows are already filtered by obligation_key; no direct filter.
DROP INDEX "router_v1.14"."obligation_collaterals_v2_oracle_address_idx";--> statement-breakpoint
-- offers_group_fk_idx is a subset of offers_group_and_hash_idx.
DROP INDEX "router_v1.14"."offers_group_fk_idx";--> statement-breakpoint
-- offers_obligation_id_side_idx is a subset of offers_obligation_side_tick_idx.
DROP INDEX "router_v1.14"."offers_obligation_id_side_idx";--> statement-breakpoint
-- pending_links_chain_type_status_idx is an exact prefix of pending_links_pending_scan_idx.
DROP INDEX "router_v1.14"."pending_links_chain_type_status_idx";--> statement-breakpoint
-- Index for maker-filtered offers endpoint with cursor pagination.
CREATE INDEX "offers_group_maker_idx" ON "router_v1.14"."offers" USING btree ("group_maker","hash","obligation_id");--> statement-breakpoint
-- Expression index for DISTINCT ON group_winners queries (Book, OfferFormulas).
-- Was on v1.13 (migration 0041) but missing from v1.14.
CREATE INDEX "offers_group_winner_expr_idx" ON "router_v1.14"."offers" (
  "group_chain_id",
  "group_maker",
  "group_group",
  "obligation_id",
  "buy",
  (CASE WHEN "buy" THEN -"tick" ELSE "tick" END),
  "block_number",
  "hash"
);
