- Shipped
- August 8, 2026 at 5:04 PM UTC
- Author
- Kamo
- Commit
- 10c3f3c
Held accounts, inbound subscriptions, members, licensees and children each aggregate in their own CTE before being joined to orgs. Joining them in one pass would multiply rows and inflate every SUM. Pure and unit-tested (26 tests): no '::' casts, every value bound, sort keys whitelisted through OrgSort. Two things the tests pin because they are easy to "tidy" into bugs -- ORDER BY and the derived predicates (mode_rank, has_stripe) must name the base CTE's projected columns, since the `o` alias is out of scope in the outer query; and a PENDING trial reports no deadline rather than the latest expired one. Verified against the live cluster: both statements execute, the count agrees with the rows, and filters/aggregates apply. Index usage is NOT demonstrated -- at 12 orgs / 9 subs CockroachDB full-scans regardless, correctly.