mysql比较需要太多时间

时间:2011-06-27 08:36:21

标签: php mysql

我在下面列出了3个表:

 CREATE TABLE `user` (
  `uid` int(10) NOT NULL AUTO_INCREMENT,
  `kid` int(3) NOT NULL,
  `Email` varchar(255) DEFAULT NULL,
  `del` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`uid`),
  KEY `kid` (`kid`),
  KEY `email` (`Email`)
) ENGINE=MyISA

CREATE TABLE `blacklist_global` (
  `bgid` int(10) NOT NULL AUTO_INCREMENT,
  `email` varchar(255) NOT NULL,
  `kid` int(3) DEFAULT NULL,
  `stmp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`bgid`),
  UNIQUE KEY `email` (`email`),
  KEY `kid` (`kid`)
) ENGINE=MyISAM

CREATE TABLE `verteiler_user` (
  `vuid` int(10) NOT NULL AUTO_INCREMENT,
  `uid` int(3) NOT NULL,
  `vid` int(3) NOT NULL,
  `del` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`vuid`),
  KEY `uid` (`uid`)
) ENGINE=MyISAM

user中的每个条目也在表verteiler_user中。现在我想delete来自用户where user.uid = verteiler_user.uid and verteiler_user.vid=XX and user.uid = XXX

的每个条目

所以我现在通过php从表user获取所有来自blacklist_global的所有来源。 问题是,在黑名单中我可以输入*@heloooo.de所以我想删除域名helooo.de中的每封电子邮件,但它非常慢。

是否可以仅在mysql中执行此操作?没有php?或者任何提示,这样做更快?

1 个答案:

答案 0 :(得分:0)

这可能会得到您所需要的。在将其用于生产数据之前先进行测试。

DELETE FROM user WHERE uid = ? AND uid in (SELECT uid from verteiler_user WHERE vid = ?)

根据评论编辑:

DELETE FROM user WHERE uid IN (SELECT uid FROM blacklist_global WHERE email LIKE '%@somedomain.com')