This commit is contained in:
32
migrations/000204_add_audit_investigation_indexes.up.sql
Normal file
32
migrations/000204_add_audit_investigation_indexes.up.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- 为统一审计跨视角查询补充受控 B-tree 索引,不增加 JSONB 搜索、缓存或分区。
|
||||
CREATE INDEX idx_audit_event_action_occurred
|
||||
ON tb_audit_event (action_code, occurred_at DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_audit_event_result_occurred
|
||||
ON tb_audit_event (result, occurred_at DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_audit_event_risk_occurred
|
||||
ON tb_audit_event (risk_level, occurred_at DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_audit_event_category_occurred
|
||||
ON tb_audit_event (category, occurred_at DESC, id DESC);
|
||||
|
||||
CREATE INDEX idx_audit_event_source_occurred
|
||||
ON tb_audit_event (source, occurred_at DESC, id DESC);
|
||||
|
||||
DROP INDEX idx_audit_event_request;
|
||||
CREATE INDEX idx_audit_event_request
|
||||
ON tb_audit_event (request_id, occurred_at DESC, id DESC)
|
||||
WHERE request_id <> '';
|
||||
|
||||
DROP INDEX idx_audit_event_parent;
|
||||
CREATE INDEX idx_audit_event_parent
|
||||
ON tb_audit_event (parent_event_id, occurred_at DESC, id DESC)
|
||||
WHERE parent_event_id <> '';
|
||||
|
||||
CREATE INDEX idx_audit_resource_id_event
|
||||
ON tb_audit_event_resource (resource_type, resource_id, audit_event_id)
|
||||
WHERE resource_id IS NOT NULL;
|
||||
|
||||
CREATE INDEX idx_audit_resource_key_event
|
||||
ON tb_audit_event_resource (resource_type, resource_key, audit_event_id);
|
||||
Reference in New Issue
Block a user