Jump to content

Unique Index versus Primary Key on VarChar Column


s0c0

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.