Mysql 使用select子查询更新查询和使用内部联接更新查询之间的差异

Mysql 使用select子查询更新查询和使用内部联接更新查询之间的差异,mysql,sql,database,Mysql,Sql,Database,有人能告诉我执行下面两个查询的区别吗 Update SomeTable Set Field1= 1234 Where Field2 in (Select Field_2 from SomeOthertable where x= 1) Vs 要理解执行中的差异,您需要查看执行计划 以下是一些指导: 一般来说,JOIN将比In更快,因为有更多的机会进行优化和In删除重复项。 在更新的情况下,任何重复都可能导致性能问题,因为同一行可以更新多次。这不会影响结果,因为字段值不会更改。 通常存在具有良好

有人能告诉我执行下面两个查询的区别吗

Update SomeTable 
Set Field1= 1234
Where Field2 in (Select Field_2 from SomeOthertable where x= 1)
Vs


要理解执行中的差异,您需要查看执行计划

以下是一些指导:

一般来说,JOIN将比In更快,因为有更多的机会进行优化和In删除重复项。 在更新的情况下,任何重复都可能导致性能问题,因为同一行可以更新多次。这不会影响结果,因为字段值不会更改。 通常存在具有良好性能的特征:

Update SomeTable st
    Set st.Field1 = 1234
    Where exists (Select 1
                  from SomeOthertable sot
                  where sot.Field_2 = st.Field2 and sot.x = 1
                 );
特别是,这可以利用其他一些TableField2,x上的索引。联接也可以使用此索引,但它保证只更新一次匹配的行

Update SomeTable st
    Set st.Field1 = 1234
    Where exists (Select 1
                  from SomeOthertable sot
                  where sot.Field_2 = st.Field2 and sot.x = 1
                 );