This is the situation I'm in:
I have a (main) table which has an id
and several more columns.
Then there are 3 more tables that only contain an id
(JOINed to the id
of the main table) and a timestamp
.
The ids on all tables are defined as unique so there's an implicit index by id
which speeds up the JOIN. The problem is, if I retrieve the timestamp
after joining, it is not in the index so it forces Postgres into a bitmap index scan and a bitmap heap scan (or a seq scan, depending on the # of rows), only for that value.
The question is, should I replace the implicit index for one that contains both the id and timestamp? That would be an index which has the same data as the table, sounds like a waste of space in that regard.
Also, I think I have to keep the original index if I want the UNIQUE
check to remain in place.
UPDATE: Forgot to add, these tables have a very high constant write rate and sporadic reads, but reads access a lot of rows at once. That is why I'd rather use all inserts instead of updates in place (all in one table). The other thing is, rows from these tables might come at any order, I cannot ensure the main table row will be inserted before the small ones arrive.