0

I am trying to do a select distinct on a table with 5 millions of data which is taking approximately 2 minutes. My intent is to improve the speed to to seconds. enter image description here

Query: - select distinct accounttype from t_fin_do where country_id='abc'


Tried composite index, the cost just went up enter image description here

2
  • Please do not post the execution plan as an image. Paste it as formatted text and make sure you preserve the indention of the plan. To do that, copy the text result and paste the text, then put ``` on the line before the plan and on a line after the plan. Jun 8, 2020 at 13:09
  • 1
    Which Postgres version are you using? I am surprised that this isn't a parallel plan Jun 8, 2020 at 13:12

1 Answer 1

0

You can try to create a partial and covering index for this query with:

 create index on t_fin_do(country_id, accounttype) where country_id='abc';

Depending on the selectivity of country_id this could be faster than a table seq scan.

1
  • From the original plan "rows removed by filter: 3" - the query has to go through all rows Jun 8, 2020 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.