update A set fFlag = 1 where ID in (select ID from B)A表有百万数据,B表有几万数据,这样的执行效率非常非常低。后来我在A表的ID字段上也加了索引,但是效率还是很低,有何办法?

解决方案 »

  1.   

    update A inner join B on a.id=b.id set fFlag = 1 
      

  2.   

    update A,B  set fFlag = 1 where a.id=b.id
      

  3.   

    不是,从理论上讲,速度应该是一样的
    第二种是笛卡尔集合:不是哦,有条件WHERE a.id=b.id
      

  4.   

    explain update A set fFlag = 1 where ID in (select ID from B) ;分析一下,看看那里瓶颈.
      

  5.   


    第一种是匹配记录才进行连接第二种是连接后才匹配当然在不同的数据库系统种,具体实现方式是不同。
    若是在MySQL ,我会使用第一种方法进行记录更新。
    若是在Oracle,我会使用其他方式去更新记录(exits 函数)。所以,要看楼主是使用什么数据库系统。
      

  6.   

    这两条SQL语句都内连接,只不过第一条是显性内连接,后者是隐性内连接
      

  7.   

    大型数据库在很多细节上与mysql概念上不同。.
        [align=center]====  ====
    [/align]
    .
    贴子分数<20:对自已的问题不予重视。
    贴子大量未结:对别人的回答不予尊重。
    .
      

  8.   


    update A,B set A.fFlag = 1 where A.ID = B.ID;See the multiple update syntax on the document.
    http://dev.mysql.com/doc/refman/5.1-maria/en/update.html