From: Ferdinand Smit <ferdinand@telegraafnet.nl>
To: pgsql-admin@postgresql.org
Subject: Index problems
Date: Wed, 3 Dec 2003 11:54:48 +0100
Message-ID: <200312031154.48776.ferdinand@telegraafnet.nl> (raw)
Hi,
When trying to explain a developer of our organisation the reson why the index
was'nt used, i was confused my self.
The simple question is: Why does the analyzer only use the index when the
table has a few differend values ?
As you can see, when de seqscan is off, the query is mutch faster. It does'nt
matter how big the table is, i've tried this with 100 times more, the result
is the same.
I've tried this on version 7.3.2 and 7.3.4.
Regards,
Ferdinand Smit
==========
test=# SELECT r, count(r) FROM test GROUP BY r;
r | count
----+-------
0 | 1344
1 | 288
2 | 440
3 | 1096
4 | 256
5 | 696
6 | 2048
7 | 512
8 | 6424
9 | 128
10 | 976
11 | 16
12 | 1488
13 | 80
14 | 136
15 | 112
16 | 56
17 | 56
18 | 16
19 | 184
(20 rows)
test=# VACUUM FULL ANALYZE test;
VACUUM
test=# EXPLAIN ANALYZE SELECT * FROM test WHERE r = 13;
QUERY PLAN
--------------------------------------------------------------------------------------------------
Seq Scan on test (cost=0.00..277.40 rows=207 width=4) (actual
time=0.05..24.19 rows=80 loops=1)
Filter: (r = 13)
Total runtime: 24.31 msec
(3 rows)
test=# SET enable_seqscan = off;
SET
test=# EXPLAIN ANALYZE SELECT * FROM test WHERE r = 13;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Index Scan using key_regio2 on test (cost=0.00..285.83 rows=207 width=4)
(actual time=0.30..0.73 rows=80 loops=1)
Index Cond: (r = 13)
Total runtime: 0.87 msec
(3 rows)
test=# SET enable_seqscan = on;
SET
test=# DELETE FROM test WHERE r > 10;
DELETE 2144
test=# VACUUM FULL ANALYZE test;
VACUUM
test=# EXPLAIN ANALYZE SELECT * FROM test WHERE r = 13;
QUERY PLAN
--------------------------------------------------------------------------------------------------
Seq Scan on test (cost=0.00..240.60 rows=638 width=4) (actual
time=20.87..20.87 rows=0 loops=1)
Filter: (r = 13)
Total runtime: 20.93 msec
(3 rows)
test=# DELETE FROM test WHERE r > 5;
DELETE 10088
test=# VACUUM FULL ANALYZE test;
VACUUM
test=# EXPLAIN ANALYZE SELECT * FROM test WHERE r = 13;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Index Scan using key_regio2 on test (cost=0.00..5.69 rows=1 width=4) (actual
time=0.25..0.25 rows=0 loops=1)
Index Cond: (r = 13)
Total runtime: 0.33 msec
(3 rows)
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-admin@postgresql.org
Cc: ferdinand@telegraafnet.nl
Subject: Re: Index problems
In-Reply-To: <200312031154.48776.ferdinand@telegraafnet.nl>
References: <200312031154.48776.ferdinand@telegraafnet.nl>
* 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