当前位置:网站首页>Mysql delete in 不走索引的

Mysql delete in 不走索引的

2022-06-26 06:19:00 东方-phantom

语句格式:

 explain delete  from enrollee where enrollee_id in (select uid from dup_super_id where delete_ind=1);
子查询没多少条,外部的表是大表。初步看执行计划是全表扫描。

analyze table 或者子查询都加了索引,内外表的关联字段属性也都一致,就是不走索引。

想到了写法。用inner join试试:

explain delete a from enrollee a inner join dup_super_id b where a.enrollee_id=b.uid and b.delete_ind=1;

 

为什么delete不行?

1.想到了以前的一个报错:

“SQL删除语句添加表别名:DELETE FROM table_name t WHERE t.id=1;报错了。

Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't where t.id=1' at line 1

原因,删除语句时要么不使

原网站

版权声明
本文为[东方-phantom]所创,转载请带上原文链接,感谢
https://blog.csdn.net/hkyw000/article/details/125336267