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.
btw, I haven't created tests to reproduce the weirdness I've seen in any/or behavior, but if we see that stuff again we really should be fixing that now.  (this change may have fixed a bunch of things but I'd be shocked if there weren't any remaining issues).