From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <dgrowleyml@gmail.com>
Cc: gzh <gzhcoder@126.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Different execution plan between PostgreSQL 8.4 and 12.11
Date: Tue, 11 Oct 2022 09:59:43 -0400
Message-ID: <299199.1665496783@sss.pgh.pa.us> (raw)
In-Reply-To: <CAApHDvr3EpRpuFxrW6pag8KhG8V_yPO_0BriMhcY_337ELY+nQ@mail.gmail.com>
References: <23fe7e4b.5866.183bc03584f.Coremail.gzhcoder@126.com>
<3810464.1665331329@sss.pgh.pa.us>
<3bb0d13f.1d81.183bfbcf7e4.Coremail.gzhcoder@126.com>
<3977622.1665369954@sss.pgh.pa.us>
<5cac5c06.25be.183c507f02f.Coremail.gzhcoder@126.com>
<CAApHDvr3EpRpuFxrW6pag8KhG8V_yPO_0BriMhcY_337ELY+nQ@mail.gmail.com>
David Rowley <dgrowleyml@gmail.com> writes:
> It feels like something is a bit lacking in our cost model here. I'm
> just not sure what that is.
The example you show is the same old problem that we've understood for
decades: for cost-estimation purposes, we assume that matching rows
are more or less evenly distributed in the table. Their actual
location doesn't matter that much if you're scanning the whole table;
but if you're hoping that a LIMIT will be able to stop after scanning
just a few rows, it does matter.
While it'd be pretty easy to insert some ad-hoc penalty into the
LIMIT estimation to reduce the chance of being fooled this way,
that would also discourage us from using fast-start plans when
they *do* help. So I don't see any easy fix.
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, dgrowleyml@gmail.com, gzhcoder@126.com
Subject: Re: Different execution plan between PostgreSQL 8.4 and 12.11
In-Reply-To: <299199.1665496783@sss.pgh.pa.us>
References: <23fe7e4b.5866.183bc03584f.Coremail.gzhcoder@126.com> <3810464.1665331329@sss.pgh.pa.us> <3bb0d13f.1d81.183bfbcf7e4.Coremail.gzhcoder@126.com> <3977622.1665369954@sss.pgh.pa.us> <5cac5c06.25be.183c507f02f.Coremail.gzhcoder@126.com> <CAApHDvr3EpRpuFxrW6pag8KhG8V_yPO_0BriMhcY_337ELY+nQ@mail.gmail.com> <299199.1665496783@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