下面是我的朋友表,
我包括2个条目以显示它是如何工作的,当用户添加一个人作为朋友时,它将2个条目插入到具有此代码的数据库中;如何将一个mysql表分成多个表并查询正确的区域?
<?PHP
//status 0=approved 1=declined approval 3=pending approval
$sql = "insert into friend_friend (userid,friendid,status,submit_date)
values
('$_SESSION[auto_id]','$friendid','0',now()),
('$friendid','$_SESSION[auto_id]','3',now())"; //Line above is my user ID, the other users ID, status 0 for approved on my side, date
//next entry is the receiving users entry, there ID, my ID, 3 for not approved yet, date
executeQuery($sql);
//So that code above is my php that adds a friend
//Below is my table scheme for the friends table
CREATE TABLE IF NOT EXISTS `friend_friend` (
`autoid` int(11) NOT NULL AUTO_INCREMENT,
`userid` int(10) DEFAULT NULL,
`friendid` int(10) DEFAULT NULL,
`status` enum('1','0','3') NOT NULL DEFAULT '0',
`submit_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`alert_message` enum('yes','no') NOT NULL DEFAULT 'yes',
PRIMARY KEY (`autoid`),
KEY `userid` (`userid`),
KEY `friendid` (`friendid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1756421 ;
--
-- Dumping data for table `friend_friend`
--
INSERT INTO `friend_friend` (`autoid`, `userid`, `friendid`, `status`, `submit_date`, `alert_message`) VALUES
(637229, 2, 1, '1', '2007-10-18 01:02:00', 'no');
INSERT INTO `friend_friend` (`autoid`, `userid`, `friendid`, `status`, `submit_date`, `alert_message`) VALUES
(637230, 1, 2, '1', '2007-10-18 01:02:00', 'no');
INSERT INTO `friend_friend` (`autoid`, `userid`, `friendid`, `status`, `submit_date`, `alert_message`) VALUES
(637231, 22901, 1, '1', '2007-10-18 02:24:05', 'no');
INSERT INTO `friend_friend` (`autoid`, `userid`, `friendid`, `status`, `submit_date`, `alert_message`) VALUES
(637232, 1, 22901, '1', '2007-10-18 02:24:05', 'no');
?>
我所想要做的是最多分裂friend_friend表为根据用户ID号码的多个表
像1-20,000之间的所有用户ID的去一个表,所有用户ID 20,001-40,000,40,001- 60000都去不同的表
我不知道如何做到这一点最好的,我需要检测添加了新的朋友,当以及用户
我假设的检索时,朋友列表中的用户应查询该表在我的代码顶部,添加用户的2个条目将不得不被分成2个查询并更新不同的表格?
为什么你想分裂用户ID的? – Milhous 2009-08-08 03:06:44
由于这个表格变大了,我认为在一个较小的表上运行查询会更好,它在一年内已经有1,700,000行,这个表的数量可能是几百万行,它是我网站上访问量最大的表,通常每天都会有数以千计的查询与之对抗,并且@当交通繁忙时 – JasonDavis 2009-08-08 06:11:30
嗨Jasondavis,您是否找到适合您的问题的正确解决方案?分区或分片之后,最佳方法是什么?现在你的桌子尺寸是多少?感谢您对此的帮助?这是你的问题的评论在http://stackoverflow.com/questions/1247841 – Bujji 2012-05-21 18:35:26