如果如1楼所说, update xxx set ccc=ccc where ..... 则建立索引会提高速度.
SET @sql = CONCAT("update ", tb_name, " set alarm_level=?,alarm_value_max=?,alarm_value_min=?,alarm_value_avg=?, file_name=?,endtime=?,outage_num=?,periodcount=? where timestamp=? and srcip=? and src_port=? and dstip=? and dst_port=? and alarm_type=?" ); 这是更新语句。
where timestamp=? and srcip=? and src_port=? and dstip=? and dst_port=? and alarm_type=?需要根据这些条件建立索引,具体要看数据的分布 当然你可以建一个 (timestamp,srcip,src_port,dstip,dst_port,alarm_type) 的index
SET @sql = CONCAT("update ", tb_name,
" set alarm_level=?,alarm_value_max=?,alarm_value_min=?,alarm_value_avg=?,
file_name=?,endtime=?,outage_num=?,periodcount=? where timestamp=? and srcip=?
and src_port=? and dstip=? and dst_port=? and alarm_type=?" );
这是更新语句。
当然你可以建一个 (timestamp,srcip,src_port,dstip,dst_port,alarm_type) 的index
比如表示性别的字段,男男女女的,可选性很差!
如果是主键,没有重复的,那意味着具有很好的可选性!如果上边的where后的字段有主键的话,那没必要建立什么索引了!
以上是两个比较极端的例子,所以,楼主建立索引的时候,应当以这两个极端为范围,选择最合适的字段建立索引!
http://www.mysqlperformanceblog.com/2009/09/12/3-ways-mysql-uses-indexes/#more-1097
mysql使用索引的三种情况
二叉树查找学习下数据结构就知道索引为什么快了