索引的更新mysql_Mysql update 索引

执行mysql update,或者delete的时候会遇到:

相关的原因自不必说:下面有stackoverflow中的帖子:

https://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clause

我采取的是将id ,放到一个临时表中;

(2):https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause

添加select:

UPDATEtbl SETcol =(SELECT...FROM(SELECT....FROM)ASx);

这里面讲述了,mysql 5.7以上添加select 还是不好用,

However, beware that from MySQL 5.7.6 and onward, the optimiser may optimise out the subquery, and still give you the error. Luckily, the optimizer_switch variable can be used to switch off this behaviour; although I couldn't recommend doing this as anything more than a short term fix, or for small one-off tasks.

SEToptimizer_switch ='derived_merge=off';

Thanks to Peter V. Mørch for this advice in the comments.

Example technique was from Baron Schwartz, originally published at Nabble, paraphrased and extended here.

(3);执行带索引:

1\  update t set t.sex = 'm' where t.id in (select id from d);   //explain 感觉很慢;

正确做法:

update t,d set t.sex = 'm'where t.id = d.id; //soso..

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值