pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSurprising sequence scan when function call used
3+ messages / 3 participants
[nested] [flat]
* Surprising sequence scan when function call used
@ 2000-10-25 17:26 Will Fitzgerald <fitzgerald@inetmi.com>
0 siblings, 2 replies; 3+ messages in thread
From: Will Fitzgerald @ 2000-10-25 17:26 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Surprising sequence scan when function call used
@ 2000-10-26 03:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: Will Fitzgerald <fitzgerald@inetmi.com>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2000-10-26 03:22 UTC (permalink / raw)
To: Will Fitzgerald <fitzgerald@inetmi.com>; +Cc: pgsql-sql
"Will Fitzgerald" <fitzgerald@inetmi.com> writes:
> vdsq=> explain select * from login where login.login = lower('foo');
> Seq Scan on login (cost=0.00..1361.86 rows=609 width=62)
7.0 is a little bit stupid about cross-data-type comparisons (lower()
yields text, not char(n)). This example works OK in current sources,
but until 7.1 comes out you'll need to write something like
where login.login = lower('foo')::char;
Or change the login field to type text...
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Surprising sequence scan when function call used
@ 2000-10-26 04:08 Hosokawa Tetsuichi <hosokawa@good-day.co.jp>
parent: Will Fitzgerald <fitzgerald@inetmi.com>
1 sibling, 0 replies; 3+ messages in thread
From: Hosokawa Tetsuichi @ 2000-10-26 04:08 UTC (permalink / raw)
To: pgsql-sql
see
functional index
On Wed, 25 Oct 2000 13:26:51 -0400
"Will Fitzgerald" <fitzgerald@inetmi.com> wrote:
> 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?
--
* Hosokawa Tetsuichi
* hosokawa@good-day.co.jp
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-10-26 04:08 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-10-25 17:26 Surprising sequence scan when function call used Will Fitzgerald <fitzgerald@inetmi.com>
2000-10-26 03:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2000-10-26 04:08 ` Hosokawa Tetsuichi <hosokawa@good-day.co.jp>
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