mysql compare takes too much time
I'm Using 3 tables here listed below:
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
and
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
and
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
every entry in table user
is also in table verteiler_user
. now i want to delete
every entry from user where user.uid = verteiler_user.uid and verteiler_user.vid=XX and user.uid = XXX
so atm i开发者_运维知识库m doing it from php fetch all entrys from table user
, all from blacklist_global
.
the problem is, in the blacklist i could enter *@heloooo.de so i want to delete every email from the domain helooo.de but its very very slow.
is it possible to do it only in mysql
? without php
? or any tip, of doing this faster ?
This might get what you need. Test it first before using it on production data.
DELETE FROM user WHERE uid = ? AND uid in (SELECT uid from verteiler_user WHERE vid = ?)
Edited based on comment:
DELETE FROM user WHERE uid IN (SELECT uid FROM blacklist_global WHERE email LIKE '%@somedomain.com')
精彩评论