On Thu, Dec 27, 2018 at 10:25:47PM +0300, neslişah demirci wrote: > Have this explain analyze output : > > *https://explain.depesz.com/s/Pra8a <https://explain.depesz.com/s/Pra8a>* Row counts are being badly underestimated leading to nested loop joins: |Index Scan using product_content_recommendation_main2_recommended_content_id_idx on product_content_recommendation_main2 prm (cost=0.57..2,031.03 ROWS=345 width=8) (actual time=0.098..68.314 ROWS=3,347 loops=1) |Index Cond: (recommended_content_id = 3371132) |Filter: (version = 1) Apparently, recommended_content_id and version aren't independent condition, but postgres thinks they are. Would you send statistics about those tables ? MCVs, ndistinct, etc. https://wiki.postgresql.org/wiki/Slow_Query_Questions#Statistics:_n_distinct.2C_MCV.2C_histogram I think the solution is to upgrade (at least) to PG10 and CREATE STATISTICS (dependencies). https://www.postgresql.org/docs/10/catalog-pg-statistic-ext.html https://www.postgresql.org/docs/10/sql-createstatistics.html https://www.postgresql.org/docs/10/planner-stats.html#PLANNER-STATS-EXTENDED https://www.postgresql.org/docs/10/multivariate-statistics-examples.html Justin