views:

13

answers:

1

this is a fairly simple question, but it's one i can't find a firm answer on.

i have a parent table in postgres, and then several child tables which have been defined. a trigger has been established, and the children tables only have data inserted if a field, say field x, meets a certain criteria.

when i query the parent table with a field based upon x, postgres knows to immediately go to the child table that is related to that particular value of x.

that all being said, i don't need to specify a particular index on the column 'x' do i? postgres already knows how to sort on it, and by adding an index to the parent 'x', postgres is therefore generating unique indexes on x for each of the new child tables.

creating that index is a bit redundant, right?

+1  A: 

Creating an index on the child table for x, if x only has one value (or a very, very small number of values) if probably a loss, yes. The planner would scan the whole table anyway.

If x is a timestamp and you're specifying a timeframe that may not be a whole partition, or if x is another range or set of values, an index would be a win most likely.

Edit: When I say one value or range of values, I mean, per child table.

rfusca
x is a site name that is a predefined list. so, for example, the parent table may be 'city_description', with column 'city'. say i have 10 children tables, 'chicago_city_description', 'dallas_city_description', 'nyc_city_description'..., where my trigger makes the decision for the child table based upon the value of 'city'. this column will never be a timestamp. so getting rid of the index is fine?
okie.floyd
If x is a site name and there is one site name per child table - get rid of the index.
rfusca
much obliged. thanks for the info.
okie.floyd