From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mark <mwchambers@gmail.com>
Cc: Jeff Janes <jeff.janes@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Query planner / Analyse statistics bad estimate rows=1 with maximum statistics 10000 on PostgreSQL 10.2
Date: Wed, 02 Jan 2019 13:19:25 -0500
Message-ID: <7363.1546453165@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFh58O-R=LYKHkMcNVpToa4oyXjPsrrZVKCYCks96q3agDycqQ@mail.gmail.com>
References: <CAFh58O_Myr6G3tcH3gcGrF-=OExB08PJdWZcSBcEcovaiPsrHA@mail.gmail.com>
<CAMkU=1xe=d66bz56mw0Zs8VNa1yh7rNpGQxzsrDidAyfCr+Pwg@mail.gmail.com>
<CAFh58O9ttZpyCM+nDb7DMQsi1ca+Z1c=B50eP2Vf3AQiNZsF9w@mail.gmail.com>
<2025.1546445499@sss.pgh.pa.us>
<CAFh58O-R=LYKHkMcNVpToa4oyXjPsrrZVKCYCks96q3agDycqQ@mail.gmail.com>
Mark <mwchambers@gmail.com> writes:
> Am I correct in my understanding that any row that has been modified (i.e.
> UPDATE) is in state HEAPTUPLE_INSERT_IN_PROGRESS so it will not be included
> in the sample?
An update will mark the existing tuple as delete-in-progress and then
insert a new tuple (row version) that's insert-in-progress.
A concurrent ANALYZE scan will definitely see the old tuple (modulo
sampling considerations) but it's timing-dependent which state it sees it
in --- it could still be "live" when we see it, or already
delete-in-progress. ANALYZE might or might not see the new tuple at all,
depending on timing and where the new tuple gets placed. So "count/sample
delete-in-progress but not insert-in-progress" seems like a good rule to
minimize the timing sensitivity of the results. It's not completely
bulletproof, but I think it's better than what we're doing now.
> I'm going to rework the application so there is less time between the
> DELETE and the COMMIT so I will only see the problem if ANALYZE runs during
> this smaller time window.
Yeah, that's about the best you can do from the application side.
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, mwchambers@gmail.com, jeff.janes@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: Query planner / Analyse statistics bad estimate rows=1 with maximum statistics 10000 on PostgreSQL 10.2
In-Reply-To: <7363.1546453165@sss.pgh.pa.us>
References: <CAFh58O_Myr6G3tcH3gcGrF-=OExB08PJdWZcSBcEcovaiPsrHA@mail.gmail.com> <CAMkU=1xe=d66bz56mw0Zs8VNa1yh7rNpGQxzsrDidAyfCr+Pwg@mail.gmail.com> <CAFh58O9ttZpyCM+nDb7DMQsi1ca+Z1c=B50eP2Vf3AQiNZsF9w@mail.gmail.com> <2025.1546445499@sss.pgh.pa.us> <CAFh58O-R=LYKHkMcNVpToa4oyXjPsrrZVKCYCks96q3agDycqQ@mail.gmail.com> <7363.1546453165@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