菜鸟请教下 关于update语句的性能问题:
比如 isused 的值只有 0 或 1update t_test set isused = 0 where index_col = 123 and isused = 1;update t_test set isused = 0 where index_col = 123;
这两条语句 性能上有区别吗?如果 isused 的值在int 范围里变动,更新的又比较频繁,有必要把isused也加上索引吗 

解决方案 »

  1.   

    性能上差得不太多的
    isused不需要加索引
      

  2.   

     index_col = 123 会有多少? 
     index_col = 123 and isused = 1 又会有多少记录?搞清楚这些只后才知道有什么差别,如何处理。
      

  3.   

    index_col = 123 会有多少?
    几千条记录吧index_col = 123 and isused = 1只有几十条 
      

  4.   

    添加 (index_col , isused)的复合索引。 然后使用这个 update t_test set isused = 0 where index_col = 123 and isused = 1;
      

  5.   

    多谢各位老大的回复 还想请教些问题 
    1. 就像上面的 where后面会用到 isused这个字段  但 他又会频繁的更新 怎么权衡要不要索引呢2. 有的表会根据某些条件频繁的删除 和 插入 要不要对where后的字段加索引呢,要考虑哪些问题?