gevans Posted August 3, 2009 Share Posted August 3, 2009 Hey guys, If I'm making a simple table of pages, something like this; CREATE TABLE `pages` ( `id` INT NOT NULL, `title` VARCHAR(50) NOT NULL, PRIMARY KEY(`id`) ) ENGINE = MYISAM Is there any specific character lengths that are better for optimisation? For example if I want around 50 characters (not to bothered) is 64 better? Cheers Gareth Quote Link to comment https://forums.phpfreaks.com/topic/168697-solved-best-size-for-varchar/ Share on other sites More sharing options...
fenway Posted August 3, 2009 Share Posted August 3, 2009 The closer the value is to the maximum expected value, the better... but depending on your sql mode, you may get truncated data if you go over. Quote Link to comment https://forums.phpfreaks.com/topic/168697-solved-best-size-for-varchar/#findComment-889997 Share on other sites More sharing options...
gevans Posted August 3, 2009 Author Share Posted August 3, 2009 Yea, I get that. But say I don't really care the size of the field, like a username, I'm going to restrict its length to something, and this will be checked before going into a database. But would 16 be better than 20 for the db going with the whole bits in a bytes etc..? Quote Link to comment https://forums.phpfreaks.com/topic/168697-solved-best-size-for-varchar/#findComment-890003 Share on other sites More sharing options...
gevans Posted August 3, 2009 Author Share Posted August 3, 2009 I think I found my answer with the image bellow; varchar only uses as many bytes as the string takes up [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/168697-solved-best-size-for-varchar/#findComment-890009 Share on other sites More sharing options...
fenway Posted August 4, 2009 Share Posted August 4, 2009 Until you use this column for group by / order by operations. Quote Link to comment https://forums.phpfreaks.com/topic/168697-solved-best-size-for-varchar/#findComment-890754 Share on other sites More sharing options...
gevans Posted August 5, 2009 Author Share Posted August 5, 2009 Can you explain that a little further? Quote Link to comment https://forums.phpfreaks.com/topic/168697-solved-best-size-for-varchar/#findComment-891292 Share on other sites More sharing options...
fenway Posted August 10, 2009 Share Posted August 10, 2009 As soon as mysql needs to create a temporary table -- like when you mention this column in a GROUP BY / ORDER BY clause -- then mysql will allocate the MAX length of this column. Quote Link to comment https://forums.phpfreaks.com/topic/168697-solved-best-size-for-varchar/#findComment-894753 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.