codeintel: Improve queries that require a distinct `COUNT(*)`
Created by: efritz
In several places in the codeintel dbstore/lsifstore, we do the following:
- start a transaction
- run a base query to count total rows (with filter but without limit/offset)
- run a query returning wanted data (with filter and limit/offset)
We can possibly run these queries together (see this SO question) with a window function. This may reduce the total cost of two queries with one slightly more expensive query.
Each of these cases may see a performance boost. The traces I've seen when optimizing #32328 (closed) leads me to believe that there is some non-trivial overhead in these separate count queries (200ms for a count + 200ms for the real query vs possibly 300ms for a single query).