From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Szymon Juraszczyk <szymon(at)juraszczyk(dot)com> |
Cc: | <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: Query optimizer bug |
Date: | 2002-10-07 15:17:14 |
Message-ID: | 20021007081206.Q76916-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Mon, 7 Oct 2002, Szymon Juraszczyk wrote:
> The table contains some 4,7 milion rows.
>
> Let's try to have look for entries with account = 570:
>
It looks to me it's estimating that 4275 rows will match account=570. If
you're using 7.2 and have analyzed, you may want to up the number of
buckets the analyzer uses in order to get a better sampling. I think if
it had a reasonable idea of how many rows it was returning, it'd probably
pick the correct index.
(As a side note, an index on account,timestamp (or is it timestamp,
account) would possibly give the best results.)
> There's no such entries. Let's try perform SELECT, anyway. We want the
> result ordered by 'timestamp':
>
> explain analyze select * from login_history where account = 570 order by
> timestamp;
> NOTICE: QUERY PLAN:
>
> Sort (cost=16952.48..16952.48 rows=4275 width=19) (actual time=0.21..0.21
> rows=0 loops=1)
> -> Index Scan using login_history_acct_idx on login_history
> (cost=0.00..16694.67 rows=4275 width=19) (actual time=0.13..0.13 rows=0
> loops=1)
> Total runtime: 0.28 msec
>
> The response is given immediately. However, when we add LIMIT clause to
> the query, we'll have to wait for 16 seconds to get the very same, empty
> result (!?):
>
> explain analyze select * from login_history where account = 570 order by
> timestamp limit 1;
> NOTICE: QUERY PLAN:
>
> Limit (cost=0.00..27.03 rows=1 width=19) (actual time=16022.11..16022.11
> rows=0 loops=1)
> -> Index Scan using login_history_pkey on login_history
> (cost=0.00..115531.35 rows=4275 width=19) (actual time=16022.10..16022.10
> rows=0 loops=1)
> Total runtime: 16022.19 msec
From | Date | Subject | |
---|---|---|---|
Next Message | Lee Kindness | 2002-10-07 15:17:54 | Re: postmaster will not start with stale lockfile but not report why |
Previous Message | Tom Lane | 2002-10-07 14:49:32 | Re: postmaster will not start with stale lockfile but not report why |