UNIQUE and PRIMARY KEY are constraints, not indexes. Although most databases implement these restrictions using an index. The additional overhead of restrictions in addition to the index is not significant, especially when you are calculating the cost of tracking and correcting inadvertent duplicates when (and not if) they arise.
Indexes are usually more effective if you have high selectivity. This is the ratio of the number of different values ββto the total number of rows.
For example, a column for a social security number might have 1 million rows with 1 million different values. Thus, selectivity of 1,000,000 / 1,000,000 = 1.0 (although there are rare historical exceptions, SSNs must be unique).
But the other column in this gender table can have only two different values ββof more than 1 million rows. 2/1000000 = very low selectivity.
An index with a UNIQUE or PRIMARY KEY constraint guarantees selectivity of 1.0, so it will always be as effective as the index.
You asked about the difference between a primary key and a unique constraint. This basically means that you can have only one primary key constraint per table (even if this constraint definition includes several columns), while you can have several unique constraints. A column with a unique constraint can be NULL, while columns in the primary key constraints must not be NULL. Otherwise, the primary key and uniqueness are very similar in their implementation and use.
You asked in a comment about whether to use MyISAM or InnoDB. In MySQL, they use the term "storage engine." There are many subtle differences between the two storage engines, but the main ones are:
- InnoDB supports transactions, so you can roll back or commit changes. MyISAM effectively always auto-commutes.
- InnoDB provides foreign key constraints. MyISAM does not apply or even retain foreign key restrictions.
If these features are necessary for your application, you should use InnoDB.
To answer your comment, it is not so simple. InnoDB is actually faster than MyISAM in quite a few cases, so it depends on your application combining selections, updates, concurrent queries, indexes, buffer configuration, etc.
See http://www.mysqlperformanceblog.com/2007/01/08/innodb-vs-myisam-vs-falcon-benchmarks-part-1/ for a very thorough comparison of storage performance. InnoDB often wins over MyISAM, which is clearly impossible to say that one is faster than the other.
As with most performance questions, the only way to answer it for your application is to check both configurations using the application and a representative sample of the data and measure the results.