标题: MySQL for update skip locked 与 for update nowait [打印本页] 作者: 立聪堂德州十三局店 时间: 2024-12-25 17:43 标题: MySQL for update skip locked 与 for update nowait 理论(下方有实操)
不适用与并发条件下加锁保证数据不出错的场景,因为它遇见目标数据加锁就跳过。(MySQL官方文档原文:Queries that skip locked rows return an inconsistent view of the data. SKIP LOCKED is therefore not suitable for general transactional work. However, it may be used to avoid lock contention when multiple sessions access the same queue-like table.)。
它能跳过仅仅是它能跳过,不代表没加skip locked的X或S锁遇见这个锁不会发生阻塞。
MySQL8才有的特性,5.7会报错: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 'skip locked' at line 1。
坑:MySQL8才有的特性,5.7会报错: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 'nowait' at line 1。