Re: Need indexes on inherited tables? - Mailing list pgsql-sql

From Franco Bruno Borghesi
Subject Re: Need indexes on inherited tables?
Date
Msg-id 1088283980.1215.19.camel@taz.oficina
Whole thread Raw
In response to Need indexes on inherited tables?  ("Phil Endecott" <spam_from_postgresql_sql@chezphil.org>)
Responses Re: Need indexes on inherited tables?
List pgsql-sql
Table T is not inheriting any indexes, neither the primary key constraint. That means that the search is going to use
anindex scan on table B and a sequential scan on table T (unless of course you add a primary key constraint or an index
ontable T).<br /><br /> You can check this things doing: <br /> ->SET enable_seqscan TO off;<br /> ->EXPLAIN
SELECT* FROM B WHERE id=5; <br /> you'll see an index scan on table B and sequential scans on the other tables.<br
/><br/> Doing:<br /> ->SELECT C.relname AS table_name, C2.relname AS index_name FROM pg_index I LEFT JOIN pg_class C
ON(I.indrelid=C.oid) LEFT JOIN pg_class C2 ON (C2.oid=I.indexrelid) WHERE  C.relname ILIKE '<table_name>'<br
/><br/> you can find out what indexes are available for table_name (or \d <table_name> in psql).<br /><br /><br
/>On Sat, 2004-06-26 at 16:29, Phil Endecott wrote: <blockquote type="CITE"><pre><font color="#737373"><i>Dear
Postgresqlexperts, 

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.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
</i></font></pre></blockquote>

pgsql-sql by date:

Previous
From: "Phil Endecott"
Date:
Subject: Need indexes on inherited tables?
Next
From: "Phil Endecott"
Date:
Subject: Re: Need indexes on inherited tables?