s0c0 Posted September 17, 2010 Share Posted September 17, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/213681-unique-index-versus-primary-key-on-varchar-column/ Share on other sites More sharing options...
chintansshah Posted September 17, 2010 Share Posted September 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213681-unique-index-versus-primary-key-on-varchar-column/#findComment-1112200 Share on other sites More sharing options...
s0c0 Posted September 17, 2010 Author Share Posted September 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213681-unique-index-versus-primary-key-on-varchar-column/#findComment-1112231 Share on other sites More sharing options...
fenway Posted September 19, 2010 Share Posted September 19, 2010 Queries against numerical columns are always faster. Quote Link to comment https://forums.phpfreaks.com/topic/213681-unique-index-versus-primary-key-on-varchar-column/#findComment-1112688 Share on other sites More sharing options...
s0c0 Posted September 19, 2010 Author Share Posted September 19, 2010 I believe the point of my post is being missed by those responding. Quote Link to comment https://forums.phpfreaks.com/topic/213681-unique-index-versus-primary-key-on-varchar-column/#findComment-1112689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.