数据库设计提高效率

时间:2012-02-17 14:59:54

标签: mysql

我正在使用PHP和mysql构建一个小插件,它基本上会采取许多不同的操作(大约50个)并将它们存储在数据库中。它将保留用户执行的50个操作中的每个操作的所有记录,并且用户数可以达到50,000。所以你可以看到在一个表中存储了很多条目。

这是表:

-- Table
CREATE TABLE `[db_prefix]entries` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `user_id` int(11) NOT NULL,
  `content_id` int(11) NOT NULL,
  `lang_key` varchar(100) collate utf8_unicode_ci NOT NULL,
  `params` text collate utf8_unicode_ci NOT NULL,
  `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `type` varchar(100) collate utf8_unicode_ci NOT NULL,
  `view`  enum('true','false') collate utf8_unicode_ci NOT NULL default 'true',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

基本上,对于单个用户,将在一次加载用户整整一个月的操作。

有没有办法在create table语句中创建索引?我可能会索引user_id和content_id

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

-- Table
CREATE TABLE `[db_prefix]entries` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `user_id` int(11) NOT NULL,
  `content_id` int(11) NOT NULL,
  `comment_id` int(11) NOT NULL,
  `lang_key` varchar(100) collate utf8_unicode_ci NOT NULL,
  `params` text collate utf8_unicode_ci NOT NULL,
  `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `type` varchar(100) collate utf8_unicode_ci NOT NULL,
  `view`  enum('true','false') collate utf8_unicode_ci NOT NULL default 'true',
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`),
  KEY `content_id` (`content_id`),
  KEY `date` (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
相关问题