move key WQL restrictions from WHERE/IN to JOIN

We were seeing order of magnitude performance impacts for using things like this:
````
...WHERE type_id IN (SELECT id from cards....
````
instead of this:
````
..JOIN (select id from cards...) AS type_table ON cards.type_id = type_table.id
````

This PR attempts to implement and generalize that approach.