Postgres v10 is not using the index in a subquery

Posted on

Question :

I have a subquery that will return 3 records, to later add the result of some calculations (using some functions).

When I am running the full query, Postgres is calculating a high number of expected rows and decides not to use the index. but when I use just the subquery, the index is used.
Plese refer to the attached screenshots.

Have any of you experienced this?

Thank you,

The EXPLAIN for the full query is as follows:

Full query Explain

When I analyze the subquery, the index gets used.

Subquery Explain

Answer :

The use of the function in the outer query was preventing parallelism.
After setting the functions to PARALLEL SAFE , it started working fine using the index. Thank you @mustaccio!!

Please refer to the parallelism documentation in the following links:

Leave a Reply

Your email address will not be published. Required fields are marked *