Mysql – Does the MySQL primary key affect the efficiency of a SELECT query

MySQLprimary-keyselect

Does the primary key serve any purposes apart from uniquely identifying a specific row? For example, a table with an autoincremented primary INT key could greatly aid in search due to the option of perhaps a binary search; but does MySQL actually take advantage of this option?

If so, is the primary key required to be in order? And while we're at this question, if a table is in order of a particular column–whether primary or not–would that aid in the SELECT process if that particular column was specified in the WHERE clause?

If not, what are some of the precautions I could take in building a speed-efficient infrastructure for my database?
For example, I have a table of articles where the first two columns are: an 'ID' as the primary key, and an alphanumeric ID for the URL. To show related articles, I have a table with two columns for relating article IDs. I have noticed that multi-table SELECT query is much more faster when the "related" table logs the primary key ('ID') rather than the alphanumeric ID (which is not primary nor numeric).

Best Answer

All things InooDB, the PRIMARY KEY has a major role. As ypercube mentioned towards end of answer, InnoDB uses a clustered key structure, and the key used for clustering is the PRIMARY KEY.

It is very important to have as small footprint for PRIMARY KEY as possible: the depth of the index is the minimum payment you have to pay so as to get to a leaf node. The depth of an InnoDB PRIMARY KEY is the starting payment for any index search.

My general advice is to use AUTO_INCREMENT primary keys for InnoDB. Here are three blog posts of mine which support this: