1500是指字符数,字符数应该在5W左右你的意思是先把1500条记录insert到一个临时表tmp_table,然后 然后 select* from table inner join tmp_talbe on table.str = tmp_table.str 这样么? 1500是字符串数,大概3W个字符 你的意思是把1500个字符中插入到临时表tmp里,然后再 select* from white inner join tmp on white.str=tmp.str 么? 我刚测了下 select* from white inner join tmp on white.str=tmp.str 执行时间10S id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE tmp index str str 770 NULL 2531 Using index 1 SIMPLE white eq_ref str str 770 bayes.tmp.str 1 直接执行 select * from white where str in(''xxx','xxx'...) 执行时间9S id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE white range str str 770 NULL 2531 Using where感觉效果差不多一样
你说 每次post过来的字符串数量平均为1500
那是指 1500 的单词吗?就算不是(是串长度)那么以平均每个单词20个字符计算,也有75个单词
你的过滤条件是 str in $tmp (str in ('xxx','xxx'....))也就是对表中的每一条记录都要做 1500(75)次字符串比较,而命中率至多是1/1500(1/75)你认为这样做合适吗?
数据库的强项在于记录间的比较,而你却在做弱势的列间比较
你可以用传入的数据构造出一个临时表(每行一个单词),再去与主表关联操作。这样才能发挥数据库的优势再有,你的连续 2 条 update 语句不能合并在一起吗?
1500是指字符数,字符数应该在5W左右你的意思是先把1500条记录insert到一个临时表tmp_table,然后
然后 select* from table inner join tmp_talbe on table.str = tmp_table.str 这样么?
1500是字符串数,大概3W个字符
你的意思是把1500个字符中插入到临时表tmp里,然后再 select* from white inner join tmp on white.str=tmp.str 么?
我刚测了下
select* from white inner join tmp on white.str=tmp.str 执行时间10S
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tmp index str str 770 NULL 2531 Using index
1 SIMPLE white eq_ref str str 770 bayes.tmp.str 1 直接执行 select * from white where str in(''xxx','xxx'...) 执行时间9S
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE white range str str 770 NULL 2531 Using where感觉效果差不多一样
2、将两条 update 合并,应该能减少 10 秒
你测的结果差不多可能是如下原因
1.查询表的数据没有达到一定量
2.两种查询方式查出的结果集不同
3.查询字段未加索引或加的不对
4.被其他索引过多而影响
5.其他原因
我认为比较明显的就是第2个原因
你联表查时没有指定查询字段,联表出的字段肯定要比不连表的要多
还有联表查询会有一对多的情况,那样一条记录就会变成多条的,要加group by