Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 100807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:39:01+00:00 2026-05-11T00:39:01+00:00

What is the difference between MySQL unique and non-unique index in terms of performance?

  • 0

What is the difference between MySQL unique and non-unique index in terms of performance?

Let us say I want to make an index on a combo of 2 columns, and the combination is unique, but I create a non-unique index. Will that have any significant effect on the performance or the memory MySQL uses?

Same question, is there is difference between primary key and unique index?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:39:01+00:00Added an answer on May 11, 2026 at 12:39 am

    UNIQUE and PRIMARY KEY are constraints, not indexes. Though most databases implement these constraints by using an index. The additional overhead of the constraint in addition to the index is insignificant, especially when you count the cost of tracking down and correcting unintentional duplicates when (not if) they occur.

    Indexes are usually more effective if there you have a high selectivity. This is the ratio of number of distinct values to the total number of rows.

    For example, in a column for Social Security Number, you may have 1 million rows with 1 million distinct values. So the selectivity is 1000000/1000000 = 1.0 (although there are rare historical exceptions, SSN’s are intended to be unique).

    But another column in that table, ‘gender’ may only have two distinct values over 1 million rows. 2/1000000 = very low selectivity.

    An index with a UNIQUE or PRIMARY KEY constraint is guaranteed to have a selectivity of 1.0, so it will always be as effective as an index can be.

    You asked about the difference between a primary key and a unique constraint. Chiefly, it’s that you can have only one primary key constraint per table (even if that constraint’s definition includes multiple columns), whereas you can have multiple unique constraints. A column with a unique constraint may permit NULLs, whereas columns in primary key constraints must not permit NULLs. Otherwise, primary key and unique are very similar in their implementation and their use.

    You asked in a comment about whether to use MyISAM or InnoDB. In MySQL, they use the term storage engine. There are bunch of subtle differences between these two storage engines, but the chief ones are:

    • InnoDB supports transactions, so you can choose to roll back or commit changes. MyISAM is effectively always autocommit.
    • InnoDB enforces foreign key constraints. MyISAM doesn’t enforce or even store foreign key constraints.

    If these features are things you need in your application, then you should use InnoDB.


    To respond to your comment, it’s not that simple. InnoDB is actually faster than MyISAM in quite a few cases, so it depends on what your application’s mix of selects, 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 performance comparison of the storage engines. InnoDB wins over MyISAM frequently enough that it’s clearly not possible to say one is faster than the other.

    As with most performance-related questions, the only way to answer it for your application is to test both configurations using your application and a representative sample of data, and measure the results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Yes, it is possible, but not terribly straightforward. The complicating… May 11, 2026 at 11:15 am
  • added an answer It is fine in hidden fields. It is only required… May 11, 2026 at 11:15 am
  • added an answer the .NET 2.0 sdk tool TLBIMP can create an assembly… May 11, 2026 at 11:15 am

Related Questions

What is the difference between MySQL unique and non-unique index in terms of performance?
What is the difference between early and late binding?
What is the difference between TrueType fonts and Type-1 fonts?
What is the difference between Build Solution and Batch Build in Visual Studio 2008?
What is the difference between a Group and a Match in .NET's RegEx?
What is the difference between publishing a website with visual studio and just copying
What is the difference between different optimization levels in GCC? Assuming I don't care
What is the difference between the AddRange and Concat functions on a generic List?
What is the difference between display:block and display:inline
What is the difference between the following class methods? Is it that one is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.