When an ExecutionEntity is deleted, we check whether there are any TaskEntities/EventSubscriptions/Jobs associated with this execution. if so, we remove them.
This leads to an increasingly large number of queries, which is most cases are pointless.
at most one query is performed for entities (Jobs/Tasks/EventSubscriptions...) associated with an execution within a single command
Idea (back from discussion with Tom): the parser could set properites like "isTaskUsed" or "isEventSubscriptionUsed" on the process definition / scope activity.
Based on such properties we should be able to reduce the number of queries.