同时发5个查询语句给mysql,查询速度明显比同时1个查询慢

比如1个数据库连接,串行执行:
select   *   from   table1   where   field1   like   '%abc% '   耗时50ms
select   *   from   table2   where   field1   like   '%abc% '   耗时50ms
select   *   from   table3   where   field1   like   '%abc% '   耗时50ms
select   *   from   table4   where   field1   like   '%abc% '   耗时50ms
select   *   from   table5   where   field1   like   '%abc% '   耗时50ms

5个数据库连接,并行同时执行:
select   *   from   table1   where   field1   like   '%abc% '   耗时220ms
select   *   from   table2   where   field1   like   '%abc% '   耗时220ms
select   *   from   table3   where   field1   like   '%abc% '   耗时220ms
select   *   from   table4   where   field1   like   '%abc% '   耗时220ms
select   *   from   table5   where   field1   like   '%abc% '   耗时220ms

为什么并行执行,查询效率明显比串行低(同一张表,原先只要50ms,现在却要220ms),是不是mysql端没有优化好?

作者: muziling   发布时间: 2011-05-12

并行执行220ms
串行总共250ms

作者: rucypli   发布时间: 2011-05-12

这举个例子,实际上有60多张表,主键做like查询,总共要花7秒,现在想弄成多线程的,本想至少可以缩减到2s,结果发现单线程查询只要200ms,多线程查询时,却花掉500ms。

是不是同时做查询,mysql服务端却是一个一个地串行执行

作者: muziling   发布时间: 2011-05-12

假设是单个硬盘 取数据肯定是串行取出数据

作者: rucypli   发布时间: 2011-05-12

普通硬盘都有几十M的读取速度,这点查询数据量,应该没问题吧。看了下,有可能时间是花在sending data上了

作者: muziling   发布时间: 2011-05-12