Re: Array index not used for query on first element?

From: "John D(dot) Burger" <john(at)mitre(dot)org>
To: General PostgreSQL List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Array index not used for query on first element?
Date: 2007-12-08 03:44:41
Message-ID: 2C51C748-814C-4A20-800B-B61C51FDE87E@mitre.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:

>> It seemed reasonable to me that a select on the first element of an
>> array column could use an index on the column, but, as seen in this
>> example, I can't get it to do so:
>
> Nope. The operators that go along with a btree index are equality,
> less than, etc on the whole indexed column. btree knows nothing
> about extracting array elements.

I guess I was working by analogy with queries like this:

select * from someTable where textColumn like 'foo%';

This will happily use an ordinary btree index on textColumn, right?
(Although I know it's only for the C locale with the default op
class.) Anyway, I guess this is a far more common case than matching
the prefix of an array. Like another poster suggested, I can have an
additional expression index on the first element of my array column.

- John Burger
MITRE

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alex Vinogradovs 2007-12-08 03:54:12 Re: record-based log shipping
Previous Message Greg Smith 2007-12-08 03:44:14 Re: record-based log shipping