Solution for speeding up a slow SELECT DISTINCT query in Postgres Solution for speeding up a slow SELECT DISTINCT query in Postgres database database