-- Extend referral commission indexes to include id DESC so ORDER BY commission DESC, id DESC
-- is fully satisfied by the index. Avoids expensive filesort when many referrals share the same
-- commission (e.g. 20k with 0 commission).
DROP INDEX idx_users_d_referer1_commission ON db_users_d;
DROP INDEX idx_users_d_referer2_commission ON db_users_d;
DROP INDEX idx_users_d_referer3_commission ON db_users_d;

CREATE INDEX idx_users_d_referer1_commission ON db_users_d (referer_id_1, to_referer_1 DESC, id DESC);
CREATE INDEX idx_users_d_referer2_commission ON db_users_d (referer_id_2, to_referer_2 DESC, id DESC);
CREATE INDEX idx_users_d_referer3_commission ON db_users_d (referer_id_3, to_referer_3 DESC, id DESC);
