SELECT DISTINCT
    magic_id
FROM magicTree
JOIN magicRun USING(magic_id)
LEFT JOIN magicNodeResult USING(magic_id, node)
WHERE
    magicRun.state = 'new'
AND magicNodeResult.magic_id IS NULL
-- WHERE hook %s
ORDER BY
    magicRun.magic_id
