Had a quick question about joins in mysql and indexing. If I had 2 tables:
table1
id
name
table2
table1id
table2title
And I join table2 and table1 using id and table1id would I add a index to id on table1 and table1id in table2? Or would I just add an index to one of the tables? Im using MySQL with MyISAM version 5.x
If
table1.idis a primary key, then you don’t need to index it. (Primary keys are automatically indexed)If not, then you’ll need to index
table1.idandtable2.table1idUse “EXPLAIN” in you selects to see what indexes you are hitting.