From: Tom Lane <tgl@sss.pgh.pa.us>
To: Pierre-Frédéric Caillaud <lists@boutiquenumerique.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: The usual sequential scan, but with LIMIT !
Date: Mon, 06 Sep 2004 12:40:41 -0400
Message-ID: <14846.1094488841@sss.pgh.pa.us> (raw)
In-Reply-To: <opsdwm0iujcq72hf@musicbox>
References: <4134BF36.3000504@syscor.com>
<413BA104.1040508@geizhals.at>
<b068057c040905181998476d1@mail.gmail.com>
<opsdwm0iujcq72hf@musicbox>
=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= <lists@boutiquenumerique.com> writes:
> Now, if I LIMIT the query to 10 rows, the index should be used all the
> time, because it will always return few rows... well, it doesn't !
Not at all. From the planner's point of view, the LIMIT is going to
reduce the cost by about a factor of 10/1403, since the underlying plan
step will only be run partway through. That's not going to change the
decision about which underlying plan step is cheapest: 10/1403 of a
cheaper plan is still always less than 10/1403 of a more expensive plan.
Later, you note that LIMIT with ORDER BY does affect the plan choice
--- that's because in that situation one plan alternative has a much
higher startup cost than the other (namely the cost of a sort step).
A small LIMIT can allow the fast-startup plan to be chosen even though
it would be estimated to be the loser if run to completion.
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, lists@boutiquenumerique.com
Subject: Re: The usual sequential scan, but with LIMIT !
In-Reply-To: <14846.1094488841@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