I have a table in mySQL where the 'id' column is the PRIMARY KEY:
CREATE TABLE `USERS` (
`ID` mediumint(9) NOT NULL auto_increment,
.....
PRIMARY KEY (`ID`),
KEY `id_index` (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=267 DEFAULT CHARSET=latin1;
I've also added an index as follows:
CREATE INDEX id_index ON USERS (id);
Did I need to do this? Or is the primary key automatically indexed?
The end aim is here is to speed up queries which join on the id column of table USERS.
Thanks
No, you don't need do this.
Primary key is automatically indexed. What you need is to index column that is foreign key in other table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With