UNIQUE( col1, col2 ) creates what indexes? - Mailing list pgsql-general

From Rob Hoopman
Subject UNIQUE( col1, col2 ) creates what indexes?
Date
Msg-id 3C8A4BCF.9070201@tuna.nl
Whole thread Raw
Responses Re: UNIQUE( col1, col2 ) creates what indexes?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi all,

I've created a table:
  CREATE TABLE locales (
    -- table specific columns
    iso639         varchar(2) NOT NULL,
    iso3166        varchar(2),
    fallback       boolean DEFAULT false,

    id            bigserial,

    PRIMARY KEY(id),
    UNIQUE(iso639, iso3166)
  );

As the manual states this creates an index on the table, but what index is .

EXPLAIN tells me it does an index scan when doing
    SELECT * FROM locales WHERE iso639 = 'fr';
    or
    SELECT * FROM locales WHERE iso639 = 'fr' AND iso3166 = 'CA';
    or
    SELECT * FROM locales WHERE iso639 = 'fr' AND fallback = TRUE;

but is doing a seq scan when doing
    SELECT * FROM locales WHERE iso3166 = 'CA';
    or
    SELECT * FROM locales WHERE iso3166 = 'CA' AND fallback = TRUE;

At first I thought this might be due to the iso3166 field not being NOT
NULL but that doesn't seem to be the case. Can anyone tell me what I am
missing?


Regards,
Rob



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: RULE with conditional behaviour?
Next
From: Tom Lane
Date:
Subject: Re: RULE with conditional behaviour?