fix(perf): bound truth-chain quality reads
All checks were successful
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 4m29s
CD Pipeline / build-and-deploy (push) Successful in 15m43s
AWOOOI Harbor 110 Local Repair / workflow-shape (push) Successful in 1s
AWOOOI Harbor 110 Local Repair / harbor-110-local-repair (push) Successful in 18s
CD Pipeline / post-deploy-checks (push) Successful in 11m37s

This commit is contained in:
Your Name
2026-07-17 04:59:22 +08:00
parent 937134aaa1
commit 0382c120e9
6 changed files with 557 additions and 201 deletions

View File

@@ -0,0 +1,70 @@
-- Bound truth-chain quality reads to indexed, structured incident references.
-- Run outside an explicit transaction because CONCURRENTLY requires it.
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS btree_gin;
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_aol_incident_text_created
ON automation_operation_log ((incident_id::text), created_at DESC)
WHERE incident_id IS NOT NULL;
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_aol_input_incident_created
ON automation_operation_log ((input ->> 'incident_id'), created_at DESC)
WHERE input ? 'incident_id';
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_aol_output_incident_created
ON automation_operation_log ((output ->> 'incident_id'), created_at DESC)
WHERE output ? 'incident_id';
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_aol_input_source_incidents_gin
ON automation_operation_log
USING GIN ((COALESCE(input #> '{source_refs,incident_ids}', '[]'::jsonb)));
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_aol_output_source_incidents_gin
ON automation_operation_log
USING GIN ((COALESCE(output #> '{source_refs,incident_ids}', '[]'::jsonb)));
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_outbound_source_incident_ids_gin
ON awooop_outbound_message
USING GIN ((COALESCE(source_envelope #> '{source_refs,incident_ids}', '[]'::jsonb)));
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_outbound_source_code_refs_gin
ON awooop_outbound_message
USING GIN ((COALESCE(source_envelope #> '{source_refs,code_refs}', '[]'::jsonb)));
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_outbound_callback_incident_recent
ON awooop_outbound_message (
project_id,
(source_envelope #>> '{callback_reply,incident_id}'),
queued_at DESC
)
WHERE source_envelope #>> '{callback_reply,incident_id}' IS NOT NULL;
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_outbound_alert_incident_recent
ON awooop_outbound_message (
project_id,
(source_envelope #>> '{alert_notification,incident_id}'),
queued_at DESC
)
WHERE source_envelope #>> '{alert_notification,incident_id}' IS NOT NULL;
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_outbound_source_incident_recent
ON awooop_outbound_message (
project_id,
(source_envelope #>> '{source_refs,incident_id}'),
queued_at DESC
)
WHERE source_envelope #>> '{source_refs,incident_id}' IS NOT NULL;
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_outbound_top_incident_recent
ON awooop_outbound_message (
project_id,
(source_envelope ->> 'incident_id'),
queued_at DESC
)
WHERE source_envelope ->> 'incident_id' IS NOT NULL;
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_outbound_project_content_preview_trgm
ON awooop_outbound_message
USING GIN (project_id, content_preview gin_trgm_ops)
WHERE content_preview IS NOT NULL;

View File

@@ -0,0 +1,14 @@
-- Roll back only indexes owned by the structured truth-chain migration.
DROP INDEX CONCURRENTLY IF EXISTS idx_outbound_project_content_preview_trgm;
DROP INDEX CONCURRENTLY IF EXISTS idx_outbound_top_incident_recent;
DROP INDEX CONCURRENTLY IF EXISTS idx_outbound_source_incident_recent;
DROP INDEX CONCURRENTLY IF EXISTS idx_outbound_alert_incident_recent;
DROP INDEX CONCURRENTLY IF EXISTS idx_outbound_callback_incident_recent;
DROP INDEX CONCURRENTLY IF EXISTS idx_outbound_source_code_refs_gin;
DROP INDEX CONCURRENTLY IF EXISTS idx_outbound_source_incident_ids_gin;
DROP INDEX CONCURRENTLY IF EXISTS idx_aol_output_source_incidents_gin;
DROP INDEX CONCURRENTLY IF EXISTS idx_aol_input_source_incidents_gin;
DROP INDEX CONCURRENTLY IF EXISTS idx_aol_output_incident_created;
DROP INDEX CONCURRENTLY IF EXISTS idx_aol_input_incident_created;
DROP INDEX CONCURRENTLY IF EXISTS idx_aol_incident_text_created;