Best way to count distinct indexed things in PostgreSQL
peterbe.com