Skip to content
Advertisement

How I can index this query in Postgresql?

I’m trying to index my query to optimize the execution time. I tried some b-tree, hash, GIN and GISP index but none of them have been used by the Postgres planner. And even when I define enable_seqscan = OFF, to force the use of my indexes, the time of execution persists or get worse. How I can efficiently index this query?

Obs: English is not my main language, so sorry for any textual problems

I’m using three tables, with 10k, 100k and 100k entries each. See code below. And my PostgreSQL version is 9.6.

Some indexes that I tried:

My tables:

My query:

The actual execution time in my notebook is 3.6-5.7 seconds, but I need to reach a maximum of 1-2 seconds.

Advertisement

Answer

You should think about compound indexes each covering the joins and the filter here as far as possible. Try if the following indexes help.

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