Plan building bugfix

Fixes problems where certain patterns and predicates caused the execution planning to loop forever