Skip to content
Advertisement

Select distinct very slow

I have a table where I store rows with external ids. Quite often I need to select latest timestamp for given external ids. Now it is a bottleneck for my app

Query:

Explain:

What could I do to make this query faster? Or probably should I use completely different query?

UPDATE:

Added new query plan as asked @jahrl. It looks like query is faster but previous query plan was made under the load and now it works similar time

Advertisement

Answer

Perhaps a basic GROUP BY query will perform better?

And, as @melcher said, don’t forget an (“external_id”, “timestamp”) index!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement