Hi,
I have a huge InnoDB table with 40 million rows -- this is the current schema:
CREATE TABLE `titles` (
`id` mediumint(8) unsigned NOT NULL,
`title` varchar(255) collate utf8_bin NOT NULL,
PRIMARY KEY (`id`),
KEY `title` (`title`(25))
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin PACK_KEYS=1
I try to find out the 'optimal' index size for the title column. The title field is UNIQUE, but I'm wasting lots of space when using an unique index or even the field title as a primary key.
Is there any formula to calculate the optimum index length for such a field? The content itself doesn't change and I know that the average length is 25 characters. This is the reason I made the index 25 characters long.
Another solution would be to make the index just 5 characters long, having to scan a couple hundreds of rows to find out the corresponding id for a given title.
A total different thing came also into my mind: delete the title index and create the MD5 value for title and store the first (or last) 4-6 bytes. Todays CPUs are fast enough to do this, and I would save some I/Os and disk space.
I appreciate any hints and suggestions!