----- Mensaje original ----- > De: "Alessandro Ferrucci" <alessandroferrucci@xxxxxxxxx> > Para: pgsql-performance@xxxxxxxxxxxxxx > Enviados: Miércoles, 26 de Abril 2017 0:19:37 > Asunto: Re: Slow query with 3 table joins > > > > After about 40 inutes the slow query finally finished and the result > of the EXPLAIN plan can be found here: > > > https://explain.depesz.com/s/BX22 > > > Thanks, > Alessandro Ferrucci 1) Looking at the "Rows removed by filter" in that explain, looks like a selectivity issue: Many (many many) rows are fetched, just to be rejected later. I think you can try a partial index on ''field (unit_id) where field_name="SHEETS_PRESENT"'', if it is practical to you. See https://www.postgresql.org/docs/current/static/indexes-partial.html for a good read about partial indexes. 2) 9.2 is a pretty old version of PG. If you are migrating yet, you should consider a more recent version HTH Gerardo -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance