MySQL update诡异,为什么MySQL UPDATE会永远消失?

我想弄清楚为什么我们之一

迁移脚本永远在我们正在尝试进行更新

从另一个表连接以获取相关的数据.

每个表(A,B)有大约100,000行.

# now populate the ACHIEVEMENT_INSTANCE.OBJECTIVE_INSTANCE_ID

update A a, B b

set a.INSTANCE_ID = b.INSTANCE_ID

where a.ID = b.ID;

看起来我们正在处理创建一些的INNER JOIN

笛卡尔积的类型在2表100,000 100,000之间

正在采取永远(可能很长时间).

根据MySQL更新默认使用内部联接不确定我们是否

可以使用一些其他类型的JOIN,它们不会那么糟糕.

UPDATE [LOW_PRIORITY] [IGNORE] table_references

SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...

[WHERE where_condition]

The table_references clause lists the

tables involved in the join. Its

syntax is described in Section

12.2.8.1, “JOIN Syntax”. Here is an example: UPDATE items,month SET

items.price=month.price WHERE

items.id=month.id; The preceding

example shows an inner join that uses

the comma operator, but multiple-table

UPDATE statements can use any type of

join allowed in SELECT statements,

such as LEFT JOIN.

解决方法:

正如Greg在评论中所述:

Do you have an index on a.ID and b.ID?

我们没有这些列的索引.一旦我们添加它们,查询花了30秒:

create index id_idx on A(id);

create index id_idx on B(id);

标签:mysql,database,sql,performance

来源: https://codeday.me/bug/20190627/1301430.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值