-- Migration: Add covering index for reward_configs to optimize subtask rewards queries
-- Date: 2026-01-26
--
-- This migration adds a covering index to optimize queries that load rewards for multiple subtasks.
-- The index includes all columns needed for the query, allowing PostgreSQL to perform
-- index-only scans without accessing the main table.
--
-- Covering index for reward_configs query
-- Includes all columns needed for rewards selection to avoid table lookups
CREATE INDEX IF NOT EXISTS idx_reward_configs_task_id_covering 
ON reward_configs(task_id, position) 
INCLUDE (id, project_id, value, use_progression);

COMMENT ON INDEX idx_reward_configs_task_id_covering IS 'Covering index for rewards query - includes all selected columns to avoid table lookups. Enables index-only scans for better performance when loading rewards for multiple tasks.';
