Solution for speeding up a slow SELECT DISTINCT query in Postgres

前端 未结 3 1363
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 20:23

The query is basically:

SELECT DISTINCT \"my_table\".\"foo\" from \"my_table\" WHERE...

Pretending that I\'m 100% certain the DISTINC

3条回答
  •  無奈伤痛
    2020-12-30 20:40

    Oftentimes, you can make such queries run faster by working around the distinct by using a group by instead:

    select my_table.foo 
    from my_table 
    where [whatever where conditions you want]
    group by foo;
    

提交回复
热议问题