Skip to content
Advertisement

Is it possible to get this PostgreSQL query down from 50ms to the order of a few ms?

I have a query that I want to make as fast as possible. It’s this:

I get the following plan:

Which is not terrible, I guess. But the actual query is more involved + I’ll be running this query in parallel on different shards. So I’m really focussed on getting this lightning quick. Is there anything I’m missing, or is this just the limit of postgres ? It seems a bit ‘slow’ in my mind, to join 40K records (rtsepezocoav_p_70_103719) with 10K records (rtco).

rtsepezocoav_p_70_103719 has indexes on: (ad_id, pe_id, se_id) (ad_id, se_id) (co_id)

rtco has index on (lo_id)

One of the first things that comes to mind, why does it use a “Bitmap Heap Scan” instead of an index only scan ?

When I do:

I get an index only scan, and it takes 15ms (also seems long).

I’m on Postgres 12.

Advertisement

Answer

Thx for the tips, but in all honesty I think I was indeed performing a premature opimization…

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