高并发之解决库存减为负的方案

1.数据库查询优化

要求库存大于0的时候才可以执行更新操作

update miaosha_goods set stock_count = stock_count - 1 
    where goods_id = #{goodsId} 
        and stock_count > 0

2.数据库设计优化

防止用户订单重复

订单里面的用户ID定义为唯一索引

猜你喜欢

转载自blog.csdn.net/weixin_42545256/article/details/84964744