Search Postgresql Archives

Re: indexing primary and foreign keys w/lookup table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




CREATE TABLE stuff_by_account (
    account_id    BIGINT REFERENCES accounts(id),
    stuff_id    BIGINT REFERENCES stuff(id)
);
CREATE INDEX stuff_by_account_account_id ON stuff_by_account(account_id);
CREATE INDEX stuff_by_account_stuff_id ON stuff_by_account(stuff_id);

do I need any/all of these indexes for my lookup table to work well? I am thinking I can get rid of stuff_id and accounts_id. Thoughts?

You should have indexes on the fields used in joins.

So if you join stuff_by_account to accounts using account_id, make sure there is an index on both sides of that (primary key already has one but the lookup table needs one too).

Foreign keys need them because when a row gets added/removed, the index is used to quickly make sure the data is in the external table.

--
Postgresql & php tutorials
http://www.designmagick.com/


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux