如下,有两张表:
表PSchance :
ProblemStep           value
UCQT1234              0.825
UNDT5678              0.765
UNAT9101               0.465表Sampletr
ProblemStep          value        ID      Key
UCQT1234             NULL        1         a
UNDT5678             NULL        2         s
UNAT9101              NULL        3         f
UCQT1234             NULL        4         a
UNAT9101              NULL        5         a现在要根据表PSchance中ProblemStep对应的value值,填入表Sampletr中ProblemStep对应的value值。
两个表,一个有18W,一个有68W。我写的SQL语句如下,但效率很低,算了下要跑5天才能跑完:
UPDATE sampletr SET sampletr. value = (SELECT  value FROM PSchancetr WHERE PSchancetr.ProblemStep = sampletr.ProblemStep)     
觉得连接查询效率好滴。麻烦大神帮忙写一下,折磨了我两天了,好痛苦啊。

解决方案 »

  1.   

    在两表的ProblemStep上建立索引没有
      

  2.   


    alter table PSchance add index ix_ps_ProblemStep(ProblemStep)alter table Sampletr add index ix_sa_ProblemStep(ProblemStep)
      

  3.   

    create index x1 on sampletr(ProblemStep);
    create index x2 on PSchancetr(ProblemStep);update sampletr,PSchancetr
    set sampletr. value=PSchancetr.value
    where PSchancetr.ProblemStep = sampletr.ProblemStep;
      

  4.   

    update sampletr a inner join PSchancetr b
    on  a.ProblemStep = b.ProblemStep;
     set a. value=b.value
      

  5.   

    内链接和
    update sampletr,PSchancetr
    set sampletr. value=PSchancetr.value
    where PSchancetr.ProblemStep = sampletr.ProblemStep;
    相比是不是效率更高?
    索引已经建过了。今天把18W的表拆成6张5W的表,刚跑完第一张5W的表,使用连接查询,2个半小时。
      

  6.   

    explain  update sampletr,PSchancetr
    set sampletr. value=PSchancetr.value
    where PSchancetr.ProblemStep = sampletr.ProblemStep;贴出结果
      

  7.   

    就说嘛,70w数据小case啊,索引足够