countRows method

MssqlQuery countRows()

SELECT COUNT_BIG(*) over the rows this query returns.

A count is not "the same query with the projection swapped": swapping the projection of a SELECT DISTINCT yields the number of source rows, and on a GROUP BY the size of the first group. A query whose shape collapses rows — DISTINCT, GROUP BY, HAVING — is therefore counted through a derived table that preserves that shape, while an ordinary query is counted in place.

Rows, not entities: on a query joined to a child table this counts join result rows, and a parent that has three children contributes three of them. countDistinct over the parent key is the other question.

Implementation

MssqlQuery countRows() =>
    _aggregateOverResult(countAll(big: true), 'countRows()');