Skip to content
Advertisement

Optimising postgresql query

I have this query which is rather slow for my liking :

Explain analyse output

Is there an index I can put on to speed this up (bearing in mind that the values for the order by will be dynamic)? I was thinking a partial index on where bust,figure,age,hair ethnicity is not null and status = ‘online’ but then not sure what column to rank on as the order by is dynamic (I’m trying to find the post similar item to a certain item).

Advertisement

Answer

Your only hope is an index on (status, deleted_at). That at least matches the equality conditions in the where clause. If you know that another column has a high proportion of null values, you can include that as a third key.

This may limit the scanning of the table. However, the performance may be more based on the sorting for the order by than scanning the table.

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