Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jeff
Last active July 26, 2019 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeff/50e287ddb80b416c15cac6775617884c to your computer and use it in GitHub Desktop.
Save jeff/50e287ddb80b416c15cac6775617884c to your computer and use it in GitHub Desktop.
-- little slower
WITH linked_outputs AS (
SELECT templates.id AS id FROM (
SELECT DISTINCT(template_output) AS id
FROM action_trigger.event WHERE template_output IS NOT NULL
UNION
SELECT DISTINCT(error_output) AS id
FROM action_trigger.event WHERE error_output IS NOT NULL
UNION
SELECT DISTINCT(async_output) AS id
FROM action_trigger.event WHERE async_output IS NOT NULL
) templates
)
SELECT id FROM action_trigger.event_output WHERE id NOT IN (SELECT id FROM linked_outputs);
-- little faster
SELECT ateo.id
FROM action_trigger.event_output AS ateo
WHERE NOT EXISTS (SELECT 1 FROM action_trigger.event WHERE template_output = ateo.id)
AND NOT EXISTS (SELECT 1 FROM action_trigger.event WHERE error_output = ateo.id)
AND NOT EXISTS (SELECT 1 FROM action_trigger.event WHERE async_output = ateo.id);
-- very slow!
SELECT ateo.id
FROM action_trigger.event_output AS ateo
LEFT JOIN action_trigger.event AS ate ON (
ateo.id = ate.template_output
OR ateo.id = ate.error_output
OR ateo.id = ate.async_output
)
WHERE ate IS NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment