From: tv@fuzzy.cz
To: anthony.shipman@symstream.com
Cc: pgsql-performance@postgresql.org
Cc: tv@fuzzy.cz
Subject: Re: strange query plan with LIMIT
Date: Wed, 8 Jun 2011 10:33:15 +0200
Message-ID: <22bab989ef6b6b073db4cecca0a19dd7.squirrel@sq.gransy.com> (raw)
In-Reply-To: <201106081508.05668.anthony.shipman@symstream.com>
References: <201106071802.08272.anthony.shipman@symstream.com>
<30c6caeda38eb66a15665d147a5db451.squirrel@sq.gransy.com>
<201106081508.05668.anthony.shipman@symstream.com>
> What seems odd to me is that the only difference between the two is the
> limit
> clause:
>
> select * from tdiag where (create_time >= '2011-06-03
> 09:49:04.000000+0' and create_time < '2011-06-06 09:59:04.000000+0') order
> by
> diag_id limit 1;
>
> select * from tdiag where (create_time >= '2011-06-03
> 09:49:04.000000+0' and create_time < '2011-06-06 09:59:04.000000+0') order
> by
> diag_id;
>
> and yet the plan completely changes.
As Claudio Freire already pointed out, this is expected behavior. With
LIMIT the planner prefers plans with low starting cost, as it expects to
end soon and building index bitmap / hash table would be a waste. So
actually it would be very odd if the plan did not change in this case ...
Anyway I have no idea how to fix this "clean" - without messing with
enable_* or cost variables or other such dirty tricks.
regards
Tomas
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: tv@fuzzy.cz, anthony.shipman@symstream.com
Subject: Re: strange query plan with LIMIT
In-Reply-To: <22bab989ef6b6b073db4cecca0a19dd7.squirrel@sq.gransy.com>
* 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