I have a table that 'translates' codes between two types. The structure
recno | integer | not null default
kahcode | character(25) | not null
othercodetype | character varying(40) | not null
othercode | character varying(40) | not null
othercoden | numeric(20,0) |
"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 appears to use a sequential access according to the explain plan.
In Informix, to get around this the LIKE could be changed to address a
substring of the 'otherCode' - ie :
AND otherCode[1,3] = 'ABC'
This would then use the index.
I have tried making the PostGreSQL code:
AND SUBSTRING(otherCode FROM 1 FOR 3) = 'ABC'
But this still comes up with a sequential scan. Is there a way to force
an indexed read?
(I did prove that it was using a sequential scan by dropping the index
and retrying the query - same time - the explain plan is accurate)
DDI: 01903 828769
pgsql-novice by date
|Next:||From: Tom Lane||Date: 2004-08-22 17:19:18|
|Subject: Re: Partial key usage |
|Previous:||From: Arthur van Dorp||Date: 2004-08-22 10:22:34|
|Subject: Re: Installing PostgreSQL in a Linux Environment|