Re: Slow query with 3 table joins

From: Gerardo Herzig <gherzig(at)fmed(dot)uba(dot)ar>
To: Alessandro Ferrucci <alessandroferrucci(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow query with 3 table joins
Date: 2017-04-26 12:27:19
Message-ID: 141643966.192926.1493209639777.JavaMail.root@fmed.uba.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

----- Mensaje original -----
> De: "Alessandro Ferrucci" <alessandroferrucci(at)gmail(dot)com>
> Para: pgsql-performance(at)postgresql(dot)org
> Enviados: Miércoles, 26 de Abril 2017 0:19:37
> Asunto: Re: [PERFORM] 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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Gerardo Herzig 2017-04-26 15:00:52 Re: Slow query with 3 table joins
Previous Message Johan Fredriksson 2017-04-26 11:35:57 Re: Slow query with 3 table joins