Re: Partial key usage - Mailing list pgsql-novice

From Tom Lane
Subject Re: Partial key usage
Date
Msg-id 6092.1093195158@sss.pgh.pa.us
Whole thread Raw
In response to Partial key usage  (Steve Tucknott <steve@retsol.co.uk>)
List pgsql-novice
Steve Tucknott <steve@retsol.co.uk> writes:
>  recno         | integer               | not null default
> nextval('public.kah_kahxlate_recno_seq'::text)
>  kahcode       | character(25)         | not null
>  othercodetype | character varying(40) | not null
>  othercode     | character varying(40) | not null
>  othercoden    | numeric(20,0)         |
> Indexes:
>     "kah_kahxlate_cpk" primary key, btree (recno)
>     "ka_kahxlate_2" btree (othercodetype, othercode)
>     "kah_kahxlate_1" btree (kahcode, othercodetype)

> What can happen is that the 'othercode' can be partial - so can be
> accessed with LIKE - ie
> SELECT kahCode FROM kah_kahXlate
> WHERE otherCodeType = 'FRED'
> AND     otherCode LIKE 'ABC%';

This should be able to use an index on (othercodetype, othercode).
If it's not, I would speculate that your database collation is not C
(check "SHOW LC_COLLATE").  Non-C locales usually sort in an order
that isn't compatible with pattern matching.

You can either re-initdb in C locale, or make a specialized index
using LIKE-compatible comparison operators.  See the docs about
specialized index operator classes.

            regards, tom lane

pgsql-novice by date:

Previous
From: Steve Tucknott
Date:
Subject: Partial key usage
Next
From: Eyinagho Newton
Date:
Subject: Re: Installing PostgreSQL in a Linux Environment