Re: Index use and slow queries

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Russell Smith <mr-russ(at)pws(dot)com(dot)au>
Cc: "Tom Pfeifer" <tpfeifer(at)tela(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Index use and slow queries
Date: 2005-03-13 06:26:12
Message-ID: 14749.1110695172@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Russell Smith <mr-russ(at)pws(dot)com(dot)au> writes:
> On Sun, 13 Mar 2005 04:40 pm, Tom Pfeifer wrote:
>> I get really slow repoonse times when using the following select statement (About 20 seconds).
>> maach=# explain select * from tst where tst_id = 639246;

> Before 8.0, bigint would not use an index unless you cast it, or quote it.

> explain select * from tst where tst_id = 639246::int8;
> explain select * from tst where tst_id = '639246';

... or you compare to a value large enough to be int8 naturally, eg

> explain select * from tst where tst_id = 123456639246;

The issue here is that (a) 639246 is naturally typed as int4, and
(b) before 8.0 we couldn't use cross-type comparisons such as int8 = int4
with an index.

You can find a whole lot of angst about this issue and related ones
if you care to review the last six or eight years of the pgsql-hackers
archives. It was only recently that we found a way to support
cross-type index operations without breaking the fundamental
type-extensibility features of Postgres. (In hindsight, we spent way
too much time fixated on the notion that we needed to find a way to
implicitly convert the non-indexed value to match the indexed column's
type, rather than biting the bullet and supporting cross-type operations
directly with indexes. Oh well, hindsight is always 20/20.)

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Miroslav Šulc 2005-03-13 15:32:52 How to read query plan
Previous Message Russell Smith 2005-03-13 06:07:46 Re: Index use and slow queries