-- P0 post-reboot CPU pressure: bound truth-chain automation_operation_log lookups.
-- Run outside an explicit transaction because CREATE INDEX CONCURRENTLY requires it.

CREATE EXTENSION IF NOT EXISTS pg_trgm;

CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_automation_operation_log_incident_text
ON automation_operation_log ((incident_id::text))
WHERE incident_id IS NOT NULL;

CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_automation_operation_log_input_text_trgm
ON automation_operation_log
USING gin ((coalesce(input::text, '')) gin_trgm_ops);

CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_automation_operation_log_output_text_trgm
ON automation_operation_log
USING gin ((coalesce(output::text, '')) gin_trgm_ops);
