This for private social network, so I wonder,
Which approach is more accurate and valid at this time. So I estimate the tables to have million rows,
First:
CREATE TABLE `system_auth_users` (
`username` char(15) NOT NULL PRIMARY KEY,
`password` varchar(32) NOT NULL,
INDEX `username` (`username`)
)type=MyISAM;
CREATE TABLE `system_auth_info` (
`username` char(15) NOT NULL PRIMARY KEY,
`fname` varchar(15) NOT NULL,
`lname` varchar(15) NOT NULL,
`gender` char(1) NOT NULL,
`location` varchar(3) DEFAULT NULL,
`descr` varchar(15) DEFAULT NULL,
INDEX `username` (`username`)
)type=MyISAM DEFAULT CHARSET=UTF8;
CREATE TABLE `system_auth_pass_recovery` (
`username` char(15) NOT NULL PRIMARY KEY,
`token` varchar(35) NOT NULL,
`time` int(10) NOT NULL
INDEX `username` (`username`)
)type=MyISAM DEFAULT CHARSET=UTF8;
The problem is that this approach is really good for maintenance/for queries,
but it wastes free space by using duplicate row username
2 :
Second approach is to create single table for all common tasks (authorization, password recovery, profile)
CREATE TABLE `system_auth_info` (
`username` char(15) NOT NULL PRIMARY KEY, /* for password recovery, for authorization, for 'personal info' */
`password` varchar(32) NOT NULL,
`token` varchar(35) NOT NULL,
`fname` varchar(15) NOT NULL,
`lname` varchar(15) NOT NULL,
`gender` char(1) NOT NULL,
`location` varchar(3) DEFAULT NULL,
`descr` varchar(15) DEFAULT NULL,
INDEX `username` (`username`)
)type=MyISAM DEFAULT CHARSET=UTF8;
the benefit of this approach is that this one doesnt waste memory, but makes a little bit harder to maintain whole system
So, the question is, Which is approach is recommended for >= 1 000 000 rows ( including perfomance ) ?
Thanks.
PRIMARYindex is enough, the secondusernameindex (in every table) is redundant. – ypercube Jun 11 '12 at 22:35