-- Step 7: Batch update odd_selections - remaining rows

-- Batch 2: Next 3M rows
WITH batch AS (
    SELECT os.db_id
    FROM odd_selections os
    JOIN odd_categories oc ON os.odd_category_db_id = oc.db_id
    WHERE os.sport IS NULL
    LIMIT 3000000
)
UPDATE odd_selections SET sport = oc.sport
FROM batch b
JOIN odd_categories oc ON odd_selections.odd_category_db_id = oc.db_id
WHERE odd_selections.db_id = b.db_id;

-- Batch 3: Next 3M rows
WITH batch AS (
    SELECT os.db_id
    FROM odd_selections os
    JOIN odd_categories oc ON os.odd_category_db_id = oc.db_id
    WHERE os.sport IS NULL
    LIMIT 3000000
)
UPDATE odd_selections SET sport = oc.sport
FROM batch b
JOIN odd_categories oc ON odd_selections.odd_category_db_id = oc.db_id
WHERE odd_selections.db_id = b.db_id;

-- Batch 4: Remaining rows
UPDATE odd_selections SET sport = oc.sport
FROM odd_categories oc
WHERE odd_selections.odd_category_db_id = oc.db_id AND odd_selections.sport IS NULL;

-- Final index
CREATE INDEX IF NOT EXISTS idx_odd_selections_sport ON odd_selections(sport) WHERE sport IS NOT NULL;
