pithos: Refactor statistics subquery

Use CTE to get current population.

Add partial index to versions table.