From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andreas Joseph Krogh <andreas@visena.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Very poor performance with Nested Loop Anti Join
Date: Mon, 01 Aug 2016 19:15:05 -0400
Message-ID: <21013.1470093305@sss.pgh.pa.us> (raw)
In-Reply-To: <VisenaEmail.26.df42f82acae38a58.156463942b8@tc7-visena>
References: <VisenaEmail.26.df42f82acae38a58.156463942b8@tc7-visena>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
Andreas Joseph Krogh <andreas@visena.com> writes:
> This query performs terribly slow (~26 minutes, 1561346.597ms):
Seems like the key misestimation is on the inner antijoin:
> -> Hash Anti Join (cost=654.21..4008.72 rows=1 width=8) (actual time=9.016..40.672 rows=76174 loops=1)
> Hash Cond: (il.invoice_id = creditnote.credit_against)
> -> Seq Scan on onp_crm_invoice_line il (cost=0.00..3062.01 rows=78001 width=8) (actual time=0.005..11.259 rows=78614 loops=1)
> -> Hash (cost=510.56..510.56 rows=11492 width=8) (actual time=8.940..8.940 rows=372 loops=1)
> Buckets: 16384 Batches: 1 Memory Usage: 143kB
> -> Seq Scan on onp_crm_invoice creditnote (cost=0.00..510.56 rows=11492 width=8) (actual time=0.014..7.882 rows=11507 loops=1)
> Filter: ((sent_date <= '2016-06-27'::date) AND ((status_key)::text = 'INVOICE_STATUS_INVOICED'::text))
> Rows Removed by Filter: 149
If it realized that this produces 78k rows not 1, it'd likely do something
smarter at the outer antijoin.
I have no idea why that estimate's so far off though. What PG version is
this? Stats all up to date on these two tables? Are the rows excluded
by the filter condition on "creditnote" significantly different from the
rest of that table?
regards, tom lane
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, andreas@visena.com
Subject: Re: Very poor performance with Nested Loop Anti Join
In-Reply-To: <21013.1470093305@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