-- optimization_features: index on organization for org filter dropdown query
-- (SELECT ... WHERE organization IS NOT NULL — was 506ms full seq scan)
CREATE INDEX "optimization_features_organization_idx" ON "optimization_features"("organization");

-- optimization_events: composite indexes for PR query UNION branches (personal accounts)
-- Branch 2: WHERE user_id = $1 AND is_optimization_found = true AND event_type IN (...)
-- (existing [user_id, event_type] missed is_optimization_found — couldn't seek directly)
CREATE INDEX "optimization_events_user_id_is_optimization_found_event_type_c_idx" ON "optimization_events"("user_id", "is_optimization_found", "event_type", "created_at" DESC);

-- Branch 3: WHERE current_username = $1 AND is_optimization_found = true AND event_type IN (...)
-- (existing [current_username, event_type] missed is_optimization_found)
CREATE INDEX "optimization_events_current_username_is_optimization_found_eve_idx" ON "optimization_events"("current_username", "is_optimization_found", "event_type", "created_at" DESC);
