Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3M4Q-00041y-TA for pgsql-performance@arkaria.postgresql.org; Wed, 26 Apr 2017 12:29:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3M4Q-0007a4-Fk for pgsql-performance@arkaria.postgresql.org; Wed, 26 Apr 2017 12:29:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d3M2g-0004RS-0w for pgsql-performance@postgresql.org; Wed, 26 Apr 2017 12:27:34 +0000 Received: from mail.fmed.uba.ar ([157.92.152.1] helo=azteca.fmed.uba.ar) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3M2X-0008N4-8Q for pgsql-performance@postgresql.org; Wed, 26 Apr 2017 12:27:29 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by azteca.fmed.uba.ar (Postfix) with ESMTP id B1881E212BF6; Wed, 26 Apr 2017 09:27:20 -0300 (ART) X-Virus-Scanned: amavisd-new at fmed.uba.ar Received: from azteca.fmed.uba.ar ([127.0.0.1]) by localhost (azteca.fmed.uba.ar [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0d53NAi+jDrx; Wed, 26 Apr 2017 09:27:19 -0300 (ART) Received: from azteca.fmed.uba.ar (azteca.fmed.uba.ar [157.92.152.1]) by azteca.fmed.uba.ar (Postfix) with ESMTP id D5282E212BF5; Wed, 26 Apr 2017 09:27:19 -0300 (ART) Date: Wed, 26 Apr 2017 08:27:19 -0400 (EDT) From: Gerardo Herzig To: Alessandro Ferrucci Cc: pgsql-performance@postgresql.org Message-ID: <141643966.192926.1493209639777.JavaMail.root@fmed.uba.ar> In-Reply-To: Subject: Re: Slow query with 3 table joins MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [157.92.152.69] X-Mailer: Zimbra 7.2.7_GA_2942 (ZimbraWebClient - FF3.0 (Linux)/7.2.7_GA_2942) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org ----- Mensaje original ----- > De: "Alessandro Ferrucci" > Para: pgsql-performance@postgresql.org > Enviados: Mi=C3=A9rcoles, 26 de Abril 2017 0:19:37 > Asunto: Re: [PERFORM] Slow query with 3 table joins >=20 >=20 >=20 > After about 40 inutes the slow query finally finished and the result > of the EXPLAIN plan can be found here: >=20 >=20 > https://explain.depesz.com/s/BX22 >=20 >=20 > Thanks, > Alessandro Ferrucci 1) Looking at the "Rows removed by filter" in that explain, looks like a se= lectivity issue: Many (many many) rows are fetched, just to be rejected lat= er.=20 I think you can try a partial index on ''field (unit_id) where field_name= =3D"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 --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance