Jump to content

Unique Index versus Primary Key on VarChar Column


Recommended Posts

We have a varchar(32) serving as a primary key.  I know this is bad and we will eventually rewrite the code and redesign the database schema.  Luckily the rows in the table never get more than about 1,000 since it just stores session data.  For now I am wondering if I would see any performance increases by switching to an auto-increment int(10) primary key and switching the varchar to a unique index.  Also wondering if MyISAM would store less meta data in the MYI file.

 

So it would go from this:

 

sessionkey | varchar(32) primary key

unixtimestamp | int(11) unsigned

data | text

 

To this:

 

session_id | int(10) primary key auto inc

sessionkey | varchar(32) unique

unixtimestamp | int(11) unsigned

data | text

 

Thoughts?

Second one is an ideal case to design a table. Don't take Varchar as your primary key, if you don't want to make auto-increment then use any functions and create random key as a primary key, but not varchar.

Agreed, however queries will still be doing look ups against the varchar value even with this change and not the primary_key.  No time to change that much code and test it all at this point.  Just wanting to know if this is worth the change.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.