pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: DiasCosta <diascosta@diascosta.org>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Fabrízio de Royes Mello <fabrizio@timbira.com.br>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: SQL Query never ending...
Date: Thu, 21 Jun 2018 17:08:07 -0400
Message-ID: <2311.1529615287@sss.pgh.pa.us> (raw)
In-Reply-To: <fe5176de-f40b-9c87-738e-54e9a4f7aee9@diascosta.org>
References: <de60a87c-ad5e-65b4-5779-406bb30af2d5@diascosta.org>
	<CAPfkCSAcyip6kPfiCQN28Jq44ORc9LT65OKTvUu_N2wfWmMNBA@mail.gmail.com>
	<CAKFQuwbatjY68E5FyNV4PXj+zNWo-vSSL5Pz3AQ+7FFxgM-+jg@mail.gmail.com>
	<fe5176de-f40b-9c87-738e-54e9a4f7aee9@diascosta.org>

DiasCosta <diascosta@diascosta.org> writes:
> This is the query plan for only 19684 rows.

I think you're getting a bad query plan, mostly as a result of two
factors:

* Poor row estimates.  It looks like the bottom-most misestimations
are on temp tables, which makes me wonder whether you've ANALYZEd
those tables.  Your application has to do that explicitly after
populating the tables; auto-analyze can't help on temp tables.

* Too many tables --- I count 33 table scans in this query.  You
might get better planning results by raising join_collapse_limit
and/or from_collapse_limit, but it will come at a cost in planning
time, and in any case a query with this many tables is never likely
to be cheap.  You might want to think about restructuring your schema
to not need so many tables, or maybe just do some hand optimization
of the query to eliminate unnecessary joins.  (It looks to me like
at least some of the joins to tt_eotb1 might be unnecessary?)

			regards, tom lane




view thread (6+ messages)  latest in thread

Message-ID: <2311.1529615287@sss.pgh.pa.us>
Permalink:  ../2311.1529615287@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2311.1529615287@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, diascosta@diascosta.org, david.g.johnston@gmail.com, fabrizio@timbira.com.br
  Subject: Re: SQL Query never ending...
  In-Reply-To: <2311.1529615287@sss.pgh.pa.us>
  References: <de60a87c-ad5e-65b4-5779-406bb30af2d5@diascosta.org> <CAPfkCSAcyip6kPfiCQN28Jq44ORc9LT65OKTvUu_N2wfWmMNBA@mail.gmail.com> <CAKFQuwbatjY68E5FyNV4PXj+zNWo-vSSL5Pz3AQ+7FFxgM-+jg@mail.gmail.com> <fe5176de-f40b-9c87-738e-54e9a4f7aee9@diascosta.org> <2311.1529615287@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox