query: define pred_to_patterns

Turns a pred into a list of patterns whose disjunction covers the
pattern.
query: add Transaction to manage xids