Move subselects into the main pager query (take 2)

Make one query rather than a myriad.

Change-Id: I031dde9456116308c02a316145b29ac95fac8370
Merge "Move subselects into the main pager query (take 2)"