Skip site navigation (1) Skip section navigation (2)

Need indexes on inherited tables?

From: "Phil Endecott" <spam_from_postgresql_sql(at)chezphil(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Need indexes on inherited tables?
Date: 2004-06-26 19:29:19
Message-ID: 1902614@chezphil.org (view raw or flat)
Thread:
Lists: pgsql-sql
Dear Postgresql experts,

I have a base table that declares a primary key spanning a couple of columns:

create table B (
  id integer,
  xx someothertype,
  .....
  primary key (id, xx)
);

and a number of derived tables that inherit from B:

create table T (
 ....
) inherits (B);

An index is automatically created for B because of the primary key.

If I search for something in T using the key columns, e.g. I do

  select * from T where id=1 and xx=something;

will the index be used?  Or must I explicity create an index on id and xx for T and each of the other derived tables?

Is it any different if I search in B and find rows that are actually in T?

(Slightly unrelated: does the index on (id,xx) help when I am searching only on id?)

Thanks for any insight anyone can offer.

--Phil.

Responses

pgsql-sql by date

Next:From: Franco Bruno BorghesiDate: 2004-06-26 21:06:20
Subject: Re: Need indexes on inherited tables?
Previous:From: Jaime CasanovaDate: 2004-06-25 18:28:56
Subject: Re: feature request ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group