CREATE INDEX IF NOT EXISTS ai_jobs_pending_claim_scope_idx
    ON ai_jobs (task_type, model_profile, priority DESC, scheduled_at DESC, created_at DESC)
    WHERE status = 'pending';

CREATE INDEX IF NOT EXISTS ai_jobs_running_lease_idx
    ON ai_jobs ((COALESCE(heartbeat_at, started_at, updated_at)))
    WHERE status = 'running';

CREATE INDEX IF NOT EXISTS ai_jobs_queue_stats_idx
    ON ai_jobs (task_type, model_profile, status);

CREATE INDEX IF NOT EXISTS ai_jobs_owner_stats_idx
    ON ai_jobs (owner_service, task_type, model_profile, status);
