4

我有三个 InnoDB 表,这三个表有一些外键。

这是架构:

CREATE TABLE IF NOT EXISTS `tbl_member` (
  `id_member` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(80) COLLATE utf8_bin NOT NULL,
  `lastname` varchar(80) COLLATE utf8_bin NOT NULL,
  `username` varchar(40) COLLATE utf8_bin DEFAULT NULL,
  `password` varchar(64) COLLATE utf8_bin NOT NULL,
  `phone` varchar(20) COLLATE utf8_bin DEFAULT NULL,
  `email` varchar(45) COLLATE utf8_bin DEFAULT NULL,
  `status` enum('active','inactive') COLLATE utf8_bin NOT NULL DEFAULT 'active',
  PRIMARY KEY (`id_member`),
  KEY `username` (`username`,`password`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=107 ;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_notification`
--

CREATE TABLE IF NOT EXISTS `tbl_notification` (
  `id_notification` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Notification ID',
  `type` enum('notification','announcement') COLLATE utf8_bin NOT NULL DEFAULT 'notification',
  `title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title',
  `notification` text COLLATE utf8_bin NOT NULL COMMENT 'Body',
  `datestart` int(13) NOT NULL COMMENT 'Date when the notification will start to be deployed',
  `dateend` int(13) NOT NULL,
  PRIMARY KEY (`id_notification`),
  KEY `datestart` (`datestart`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_notification_member`
--

CREATE TABLE IF NOT EXISTS `tbl_notification_member` (
  `id_notification_member` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `id_notification` int(10) unsigned NOT NULL COMMENT 'Notification ID',
  `id_member` int(10) unsigned NOT NULL COMMENT 'Member ID',
  `status` enum('read','unread') NOT NULL DEFAULT 'unread' COMMENT 'Defines if the notification was viewed already or not',
  `timestamp` int(15) NOT NULL COMMENT 'Time when the notification was saw',
  PRIMARY KEY (`id_notification_member`),
  KEY `id_notification` (`id_notification`),
  KEY `id_member` (`id_member`),
  KEY `timestamp` (`timestamp`),
  KEY `status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Constraints for table `tbl_notification_member`
--
ALTER TABLE `tbl_notification_member`
  ADD CONSTRAINT `tbl_notification_member_ibfk_2` FOREIGN KEY (`id_member`) REFERENCES `tbl_member` (`id_member`),
  ADD CONSTRAINT `tbl_notification_member_ibfk_3` FOREIGN KEY (`id_notification`) REFERENCES `tbl_notification` (`id_notification`) ON DELETE CASCADE;

所以你可以看到如果我删除一个通知,通知和成员之间的关系将被级联删除,这很棒,但问题是当我尝试插入数千行时。有没有办法以某种方式做到这一点,比如级联?使用索引或类似的东西?(我在已删除的表格中还有其他关系,例如部分,因此您可以仅为一个部分添加通知并限制将收到通知的用户数量)

4

1 回答 1

3

您可以通过Innodb Performance Optimization Basics增加它

还要检查您的应用程序是否可以在 READ-COMMITED 隔离模式下运行 - 如果可以 - 将其设置为默认设置为 transaction-isolation=READ-COMMITTED。此选项具有一些性能优势,特别是在锁定 5.0 时,甚至更多的是 MySQL 5.1 和行级复制。

还要检查这个

于 2013-08-26T20:28:39.283 回答