From: Tom Lane <tgl@sss.pgh.pa.us>
To: Eudald ValcĂ rcel Lacasa <eudald.valcarcel@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Issue executing query from container
Date: Wed, 15 Jul 2020 10:42:42 -0400
Message-ID: <3065070.1594824162@sss.pgh.pa.us> (raw)
In-Reply-To: <CANEx+AW1zPOXaobpcbh6DPxbRdFFJrhbXgbxNpA51YfnjhHrGQ@mail.gmail.com>
References: <CANEx+AWsQETay6WmKUw=8HPZ3L9bvk1AveF5wrOQD+tAPyN3WA@mail.gmail.com>
<2961873.1594763498@sss.pgh.pa.us>
<CANEx+AW1zPOXaobpcbh6DPxbRdFFJrhbXgbxNpA51YfnjhHrGQ@mail.gmail.com>
=?UTF-8?Q?Eudald_Valc=C3=A0rcel_Lacasa?= <eudald.valcarcel@gmail.com> writes:
> After running the query both manually and with the script, I've the
> following logs:
> MANUALLY:
> Update on import_temp_2 tmp (cost=116.73..17352.10 rows=5557 width=293)
> -> Hash Join (cost=116.73..17352.10 rows=5557 width=293)
> Hash Cond: (lower((tmp.email)::text) = lower((bl.value)::text))
> -> Seq Scan on import_temp_2 tmp (cost=0.00..14864.20
> rows=370496 width=193)
> Filter: (status = 1)
> -> Hash (cost=116.70..116.70 rows=3 width=130)
> Buckets: 32768 (originally 1024) Batches: 2
> (originally 1) Memory Usage: 3841kB
> -> Foreign Scan on blacklist_central bl
> (cost=100.00..116.70 rows=3 width=130)
> AUTOMATED:
> Update on import_temp_2 tmp (cost=100.00..13295.86 rows=15 width=500)
> -> Nested Loop (cost=100.00..13295.86 rows=15 width=500)
> Join Filter: (lower((tmp.email)::text) = lower((bl.value)::text))
> -> Seq Scan on import_temp_2 tmp (cost=0.00..13118.74
> rows=1007 width=400)
> Filter: (status = 1)
> -> Materialize (cost=100.00..116.71 rows=3 width=130)
> -> Foreign Scan on blacklist_central bl
> (cost=100.00..116.70 rows=3 width=130)
So the question is why you are getting an estimate of 370496 import_temp_2
rows with status = 1 in the first case, and only 1007 rows in the second.
I suspect that the true number of rows is quite large, causing the
nested-loop plan to run slowly. (Is the row estimate of 3 for the
foreign scan anywhere near reality, either?)
You may need to insert a manual ANALYZE in your automated process to
ensure that import_temp_2 has up-to-date stats before you try to do
this step. It seems somewhat likely that autovacuum takes care of
that for you in the "manual" case, but its reaction time is too slow
to fill the gap for the automated process.
regards, tom lane
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, eudald.valcarcel@gmail.com
Subject: Re: Issue executing query from container
In-Reply-To: <3065070.1594824162@sss.pgh.pa.us>
References: <CANEx+AWsQETay6WmKUw=8HPZ3L9bvk1AveF5wrOQD+tAPyN3WA@mail.gmail.com> <2961873.1594763498@sss.pgh.pa.us> <CANEx+AW1zPOXaobpcbh6DPxbRdFFJrhbXgbxNpA51YfnjhHrGQ@mail.gmail.com> <3065070.1594824162@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