COMMIT;
ANALYZE action_trigger.event;
ANALYZE action_trigger.event_output;
+
+CREATE INDEX action_trigger_event_template_output_idx
+ ON action_trigger.event (template_output);
+
+CREATE INDEX action_trigger_event_error_output_idx
+ ON action_trigger.event (error_output);
+
+CREATE INDEX action_trigger_event_async_output_idx
+ ON action_trigger.event (async_output);
+
-- END_DEPLOYMENT --
AND evt.update_time < (NOW() - def.retention_interval)
);
- WITH linked_outputs AS (
- SELECT templates.id AS id FROM (
+ CREATE TEMPORARY TABLE tmp_purge_output ON COMMIT DROP AS
+ SELECT ateo.id FROM action_trigger.event_output ateo
+ LEFT JOIN (
SELECT template_output AS id
FROM action_trigger.event WHERE template_output IS NOT NULL
UNION
UNION
SELECT async_output AS id
FROM action_trigger.event WHERE async_output IS NOT NULL
- ) templates
- ) DELETE FROM action_trigger.event_output
- WHERE id NOT IN (SELECT id FROM linked_outputs);
+ ) linked ON (linked.id = ateo.id)
+ WHERE linked.id IS NULL
+ ;
+ DELETE FROM action_trigger.event_output
+ WHERE id IN (SELECT id FROM tmp_purge_output);
END;
$_$ LANGUAGE PLPGSQL;