From: Will Fitzgerald <fitzgerald@inetmi.com>
To: pgsql-sql@postgresql.org
Subject: Surprising sequence scan when function call used
Date: Wed, 25 Oct 2000 13:26:51 -0400
Message-ID: <KPELIDPNOGGPCLGOMDLFOEIKCDAA.fitzgerald@inetmi.com> (raw)
I have a table, login, which has a field by the same name; there's an index
on that field. I was surprised to discover that a SELECT which compares the
login field to a constant uses an Index scan, but if it is compared to a
function call--for example, lower()--a sequence scan is forced.
Any idea why?
Here are more details:
vdsq=> select version();
version
---------------------------------------------------------------------
PostgreSQL 7.0.2 on i686-pc-linux-gnu, compiled by gcc egcs-2.91.66
(1 row)
vdsq=> \d login
Table "login"
Attribute | Type | Modifier
--------------+-------------+-----------------------------------------------
-
id | integer | not null default nextval('login_id_seq'::text)
login | char(8) | not null
password | char(8) | not null
jobid | integer | not null
type | smallint | not null
entryid | integer |
lastactivity | timestamp |
trackid | varchar(50) |
roundid | integer |
Indices: idx_login_entryid,
idx_login_jobid,
idx_login_login,
idx_login_password,
idx_login_type,
login_pkey
vdsq=> explain select * from login where login.login = 'foo';
NOTICE: QUERY PLAN:
Index Scan using idx_login_login on login (cost=0.00..582.61 rows=609
width=62)
EXPLAIN
vdsq=> explain select * from login where login.login = lower('foo');
NOTICE: QUERY PLAN:
Seq Scan on login (cost=0.00..1361.86 rows=609 width=62)
EXPLAIN
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-sql@postgresql.org
Cc: fitzgerald@inetmi.com
Subject: Re: Surprising sequence scan when function call used
In-Reply-To: <KPELIDPNOGGPCLGOMDLFOEIKCDAA.fitzgerald@inetmi.com>
References: <KPELIDPNOGGPCLGOMDLFOEIKCDAA.fitzgerald@inetmi.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