pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedMatching indexes on int8 columns
3+ messages / 2 participants
[nested] [flat]
* Matching indexes on int8 columns
@ 2003-10-24 12:52 Andrew Biagioni <andrew.biagioni@e-greek.net>
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Biagioni @ 2003-10-24 12:52 UTC (permalink / raw)
To: pgsql-admin
I'm running 7.3, and I recently found out something rather disconcerting: if I
have an index on an int8 column, and I run a query such as
SELECT * FROM [tablename] WHERE [colname] = 12345
the index is NOT used, and sequential scan of the 200K rows is done, taking ~
17500 msec.; if I change the query to be:
SELECT * FROM [tablename] WHERE [colname] = '12345'
or
SELECT * FROM [tablename] WHERE [colname] = 12345::int8
then the index is used and a btree index scan id performed taking ~24 msec.
I found this workaround in a 2001 thread, leading me to believe that it's
nothing new; however, there is nothing in the docs. that I could find
(including the Momjian book), that has any reference to this problem.
My conclusion is that index-to-WHERE matching relies on some strict kind of
type matching, without any attempt at type conversion between int4 and int8.
So finally, my question. Why is this behavior present? Is it actually a
feature that I don't know enough to appreciate?
Inquiring minds want to know...
Thanks,
Andrew Biagioni
^ permalink raw reply [nested|flat] 3+ messages in thread
* Matching indexes on int8 columns?
@ 2003-10-29 19:08 Andrew Biagioni <andrew.biagioni@e-greek.net>
2003-10-30 21:00 ` Re: Matching indexes on int8 columns? Andrew Sullivan <andrew@libertyrms.info>
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Biagioni @ 2003-10-29 19:08 UTC (permalink / raw)
To: pgsql-admin
I'm running 7.3, and I recently observed something rather disconcerting,
using EXPLAIN ANALYZE.
If I have an index on an int8 column, and I run a query such as
SELECT * FROM [tablename] WHERE [colname] = 12345
the index is NOT used, and a sequential scan of the 200K rows is done,
taking ~ 17500 msec.; if I change the query to be:
SELECT * FROM [tablename] WHERE [colname] = '12345'
or
SELECT * FROM [tablename] WHERE [colname] = 12345::int8
then the index is used and a btree index scan is performed taking ~24 msec.
I found these workarounds in a Sept. 2001 thread, leading me to believe
that it's nothing new; however, there is nothing in the docs. that I
could find (including the Momjian book), that has any reference to this
problem.
My conclusion (assumption?) is that index-to-WHERE matching relies on
some strict kind of type matching, without any attempt at type
conversion between int4 and int8; but if a type conversion is forced
(e.g., by quoting the number), then the conversion is done before the
matching and all goes well.
So finally, my question. Why is this behavior present? Is it actually
a feature that I don't know enough to appreciate?
Inquiring minds want to know...
Thanks,
Andrew Biagioni
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Matching indexes on int8 columns?
2003-10-29 19:08 Matching indexes on int8 columns? Andrew Biagioni <andrew.biagioni@e-greek.net>
@ 2003-10-30 21:00 ` Andrew Sullivan <andrew@libertyrms.info>
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Sullivan @ 2003-10-30 21:00 UTC (permalink / raw)
To: pgsql-admin
On Wed, Oct 29, 2003 at 02:08:03PM -0500, Andrew Biagioni wrote:
>
> So finally, my question. Why is this behavior present? Is it actually
> a feature that I don't know enough to appreciate?
It's the side-effect of some other features in the system. If you
search on -hackers archives you'll find several attempts to find a
solution to this little problem; all of them have failed so far,
AFAIK. There was talk of making the int4-to-int8 case behave more
reasonably in 7.4, but I don't know whether it's been done.
A
--
----
Andrew Sullivan 204-4141 Yonge Street
Afilias Canada Toronto, Ontario Canada
<andrew@libertyrms.info> M2P 2A8
+1 416 646 3304 x110
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-10-30 21:00 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-24 12:52 Matching indexes on int8 columns Andrew Biagioni <andrew.biagioni@e-greek.net>
2003-10-29 19:08 Matching indexes on int8 columns? Andrew Biagioni <andrew.biagioni@e-greek.net>
2003-10-30 21:00 ` Re: Matching indexes on int8 columns? Andrew Sullivan <andrew@libertyrms.info>
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