21,886
社区成员
发帖
与我相关
我的任务
分享
create table email(id int unsigned primary key auto_increment, e_mail varchar(64)) engine=myisam;
insert into email(e_mail) values('caifangjie@163.com'),('caifangjie@163.com.cn'),
('caifangjie@163.cn'),
('1122@1126.com'),
( '1122@1126.com.cn'),
('1122@126.cn');
上面假设有五千万条,通过分表的技术,把126和163的记录分开,因为现实情况肯定是这样做,不可能每次都对五千万条记录进行一次索引查找。。
create table email_163 like email;
insert into email_163
select id, temp.e_mail_163
from
(
select id,
case e_mail
when substr(e_mail,-7,3)=163 then e_mail
when substr(e_mail,-10,3)=163 then e_mail
when substr(e_mail,-6, 3)=163 then e_mail
else 0
end as e_mail_163
from email order by length(e_mail_163) desc
)as temp
where temp.e_mail_163 <> '0';
因为126或者163,域名的部分都只存在三种固定的模式,,,163.com,163.cn,163.com.cn。。。。。显然域名这部分的长度是相同的,,所以通过字段比对,将163的提取到另外一个表。。。。提取126的同样如此。
这样就不用每次都对五千万条记录查询了,而且速度更快