CREATE INDEX IF NOT EXISTS ai_jobs_owner_error_stats_idx
    ON ai_jobs (owner_service, task_type, model_profile, error_code, updated_at DESC)
    WHERE status = 'failed';
