pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kent Tong <kent.tong.mo@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: huge discrepancy between EXPLAIN cost and actual time (but the table has just been ANALYZED)
Date: Mon, 08 May 2023 09:44:18 -0400
Message-ID: <338272.1683553458@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKs98dFv5pyZ-2yE+M6W0YFA5SXgB=Hv-sg9CPz1RfB4zTTTxw@mail.gmail.com>
References: <CAKs98dFv5pyZ-2yE+M6W0YFA5SXgB=Hv-sg9CPz1RfB4zTTTxw@mail.gmail.com>

Kent Tong <kent.tong.mo@gmail.com> writes:
> I have a complex query involving over 15 joins and a CTE query and it takes
> over 17s to complete.

If you want constructive comments about that, you're going to need to show
us the whole thing (and the underlying tables' schemas).  Little bits in
isolation are not very intelligible.

https://wiki.postgresql.org/wiki/Slow_Query_Questions

One thought is that you might need to raise from_collapse_limit and/or
join_collapse_limit to at least 15 to get the planner to do a complete
search of the join-order space.

			regards, tom lane





view thread (4+ messages)  latest in thread

Message-ID: <338272.1683553458@sss.pgh.pa.us>
Permalink:  ../338272.1683553458@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/338272.1683553458@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, kent.tong.mo@gmail.com
  Subject: Re: huge discrepancy between EXPLAIN cost and actual time (but the table has just been ANALYZED)
  In-Reply-To: <338272.1683553458@sss.pgh.pa.us>
  References: <CAKs98dFv5pyZ-2yE+M6W0YFA5SXgB=Hv-sg9CPz1RfB4zTTTxw@mail.gmail.com> <338272.1683553458@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