下面这条查询语句,同样的数据,有时只需在1分钟,有时需要23分钟之多。
每次先使用 RESET QUERY CACHE 也得不到确定的结果,但基本上,如果先关掉mysql,再开启,运行,就会要23分钟。
mysql还有别的缓存机制吗?
有一段时间试验, 发现先在某个表无记录时空运行一次,然后 再在有数据时正式运行,可以1分钟,
有一段时间好象发现,在存储过程运行到这条语句之前,在其它客户端(SQLyog Enterprise) 运行一条无关的语句 :select * from xxx(任意表); 也能使下面这句在1分钟。
select d.LocalNetID,d.bscid,d.SiteID,d.CellID,c.bcchArfcn,d.bsic,
c.LocalNetID,c.bscid,c.SiteID,c.CellID,a.Longitude,a.Latitude,
a.CILongitude,a.CILatitude,a.NearDist
from plan_ci_info d FORCE INDEX (INDEX_CI_Info)
join plan_cell_info b on b.LocalNetID=d.LocalNetID and b.BSCID=d.BSCID and b.SiteID=d.SiteID
and b.CellID=d.CellID and d.CILocalNetID is null
join plan_cell_info c on c.bcchArfcn = d.bcch and concat(c.ncc,c.bcc) = d.bsic
join plan_ci_site_temp a on a.localnetid = b.localnetid and a.bscid=b.bscid and a.siteid=b.siteid
and a.CIlocalnetid = c.localnetid and a.CIbscid=c.bscid and a.CIsiteid=c.siteid;
每次先使用 RESET QUERY CACHE 也得不到确定的结果,但基本上,如果先关掉mysql,再开启,运行,就会要23分钟。
mysql还有别的缓存机制吗?
有一段时间试验, 发现先在某个表无记录时空运行一次,然后 再在有数据时正式运行,可以1分钟,
有一段时间好象发现,在存储过程运行到这条语句之前,在其它客户端(SQLyog Enterprise) 运行一条无关的语句 :select * from xxx(任意表); 也能使下面这句在1分钟。
select d.LocalNetID,d.bscid,d.SiteID,d.CellID,c.bcchArfcn,d.bsic,
c.LocalNetID,c.bscid,c.SiteID,c.CellID,a.Longitude,a.Latitude,
a.CILongitude,a.CILatitude,a.NearDist
from plan_ci_info d FORCE INDEX (INDEX_CI_Info)
join plan_cell_info b on b.LocalNetID=d.LocalNetID and b.BSCID=d.BSCID and b.SiteID=d.SiteID
and b.CellID=d.CellID and d.CILocalNetID is null
join plan_cell_info c on c.bcchArfcn = d.bcch and concat(c.ncc,c.bcc) = d.bsic
join plan_ci_site_temp a on a.localnetid = b.localnetid and a.bscid=b.bscid and a.siteid=b.siteid
and a.CIlocalnetid = c.localnetid and a.CIbscid=c.bscid and a.CIsiteid=c.siteid;
甚至还有这个 concat(c.ncc,c.bcc) = d.bsic 表数量看看。 如果过大,那速度无论如何都难提起来。 join的相关字段建立索引
select count(*) from t where id<100000000
第一次查询花费5秒,第二次同样的查询来的时候,MYSQL已经不去做查询了,直接从缓存中取出结果显示出来。内部有查询SQL命令---查询结果这样的对应关系。
到结果而不需要再去解析和执行sql
mysql>SHOWVARIABLESLIKE’%query_cache%’;
+------------------------------+---------+
|Variable_name|Value|
+------------------------------+---------+
|have_query_cache|YES|--查询缓存Cache是否可用
|query_cache_limit|1048576|--可缓存Cache具体查询结果最大值
|query_cache_min_res_unit|4096|
|query_cache_size|599040|--查询缓存Cache大小
|query_cache_type|ON|--阻止或是支持查询缓存Cache
|query_cache_wlock_invalidate|OFF|
+------------------------------+---------+