I'm struggling with indexes, primary keys and foreign keys... And the need of having them all.
If I have two tables, both of them have an integer as a primary key.
The first table references through a FK to the second table's primary key.
- On both tables I have a primary key index on the ID column
- I created a FK constraint on the
table1.ref_fieldreferencing the PK of the second table (table2.id) - and I added an index on
table1.ref_field
Is this the best way to organize these indexes, primary and foreign keys?
DELETEfrom the referenced table then it can save you a lot of I/O and CPU avoiding maintaining an unused index. I do think it should be created by default, just have an option to suppress its creation. – Craig Ringer Nov 25 '13 at 05:32