美文网首页
sql语句中的坑

sql语句中的坑

作者: loloxiaoz | 来源:发表于2018-06-03 13:28 被阅读0次

1、update无主键时lock table 连接数打满
update 必须是主键,否则可能死锁
http://blog.csdn.net/claram/article/details/54023216
2、select for update
高并发情况下如何保证数据事务性
悲观锁
$sql = "select id from appReportCount where id=$id for update";
$executor->query($sql);
$sql = "update appReportCount set cnt=cnt+$count,loginCnt=loginCnt+$loginCnt,uniqSNCnt=uniqSNCnt+$uniqSNCnt where id=$id";
$executor->exec($sql);
3、order by column 容易忘记索引
4、select * from * 中字段有longtext,变慢
5、join 表顺序以及 where条件

相关文章

网友评论

      本文标题:sql语句中的坑

      本文链接:https://www.haomeiwen.com/subject/bumwsxtx.html