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

  • SEARCH
  • Home
  • 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 8796785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:42:08+00:00 2026-06-13T23:42:08+00:00

I’m using MySQL with InnoDB. I don’t need a primary key in terms of

  • 0

I’m using MySQL with InnoDB.

I don’t need a primary key in terms of semantics, so does a primary key (or rather, a unique index) make for faster queries than a non-unique index?

I have two columns that are suitable for indexes but are non-unique. However, combinations of the two columns are always unique. The columns are also non-null.

Is it better to just set the two non-unique columns as indexes, or to instead create a primary key over the combination of the two columns?

The access pattern will normally be modifying two or four rows where the first column is a given value (and the second column will be different, as I mentioned every combination is unique).

For example, col1 and col2 being like

1 1
1 2
1 3
1 5
2 1
2 2
2 3
2 5
3 1
3 2
3 3

an example would be change rows (1, 2) and (1, 3) at a time

A follow up question is about datatypes. col1 fits in a smallint and col2 in a tinyint. However, I’m not sure what the performance implications are of using smaller-than-int types and also different types, when combining into a single index. The manual says multiple columns are concatenated when used for primary key. Is it better to use the same type, smallint? Or even use ints? In terms of memory access, are not aligned, full word accesses the fastest? Does this have an impact here?

  • 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. Editorial Team
    Editorial Team
    2026-06-13T23:42:10+00:00Added an answer on June 13, 2026 at 11:42 pm

    Whether you use it or not, InnoDB always has a primary key, kind of. InnoDB uses a clustered index for storing the data, which basically means that primary key and the data are in the same place. If you don’t define a suitable index, it creates an internal index. This also means that the primary key is “free”; it doesn’t require any extra space since the data is stored in the index. If you always find rows to update by using both columns, you should definitely make a composite primary index. Even if you don’t use two columns every time to filter data, you will probably benefit from a composite primary index.

    As for the data types, I’d make both as small as possible. I’m not sure about the specifics of how the index is handled in memory, but you’re probably not going to be able to measure any significant difference due to memory access differences and the smaller index size wouldn’t hurt.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.