1. 程式人生 > >高併發之解決庫存減為負的方案

高併發之解決庫存減為負的方案

1.資料庫查詢優化

要求庫存大於0的時候才可以執行更新操作

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

2.資料庫設計優化

防止使用者訂單重複

訂單裡面的使用者ID定義為唯一索引