当前位置:网站首页>What is the function of the select... For UPDATE statement? Can you lock tables or rows?
What is the function of the select... For UPDATE statement? Can you lock tables or rows?
2022-07-24 00:26:00 【It's hard not to write code all day】
Catalog
1 Sentence meaning
In the project code , notice
select * from xxl_job_lock where lock_name = 'schedule_lock' for update
What does the above code mean
select Query statements are not locked , however select …for update In addition to the function of query , And lock it , And it's a pessimistic lock .
So is it a row lock or a table lock , It depends on whether the index is used / Primary key .
Useless index / A primary key is a table lock , Otherwise, it is a row lock .
2 Ideas
Create a new table , We use xxl-job The inside of the table 
His watch , This field is the primary key

We first turn off automatic submission
Auto submit needs to be turned off , adopt set @@autocommit=0; Set to manual submit .0 On behalf of hand submit ,1 On behalf of auto submit .
It must be closed first , Otherwise, as soon as the statement is executed , Just submitted , We can't see the result we want
After the closing , Execute statement
select * from xxl_job_lock where lock_name = 'schedule_lock' for update
The above query statement means , Not only to query , And for this sql Statement to lock ; After locking , Other threads need to operate this table , Just got stuck , Wait until this sql Statement execution complete , Operations of other threads on this table , Will execute , Or I'll be waiting , In this way, the exclusive lock is realized
We can use select for update , It's an exclusive lock . To put it bluntly xxl-job Use a database table as a distributed lock , Make sure there are multiple xxl-job admin Under the node , Still, only one scheduling thread task can be executed at the same time
Multithreading , Operate on the same database , We can use this database
Create a separate table , This table can be used as a distributed lock
边栏推荐
- AWS Part 4 one machine and one secret
- GBase 8c系统表信息函数(一)
- PHP implements stripe subscription
- GBase 8c 访问权限查询函数(一)
- Redis数据结构
- Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
- GBase 8c 会话信息函数(六)
- English语法_指示代词 -such / the same
- Gbase 8C session information function (4)
- Gbase 8C access authority query function (II)
猜你喜欢

高数_第1章空间解析几何与向量代数__两点距

What are blue-green deployment, Canary release and a/b test

IIS deployment.Netcore

Method of C language annotation
![[translation] Introduction to go RPC: Hello World](/img/dd/7887f056bc031fe50253078dd355d0.png)
[translation] Introduction to go RPC: Hello World

Distributed cap principle

书写SQL必养成的好习惯

Codeforces Round #807 (Div. 2)(A-D)

EFCore高级Saas系统下单DbContext如何支持不同数据库的迁移

Summarize the plan, clarify the direction, concentrate and start a new situation -- the Counterpart Assistance Project of hexu software has achieved remarkable results
随机推荐
Gbase 8C access authority query function (I)
GBase 8c 会话信息函数(五)
GBase 8c 访问权限访问函数(四)
Lac automatic dialing experiment of L2TP
Problem note - unable to open include file: "direct.h": no such file or directory
inode、软链接、硬链接
[low code] limitations of low code development
Multi data source configuration of mongodb
Happiness of progress and growth
Gbase 8C access authority query function (V)
Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
Classic example of C language - print the input two digits in reverse order
IIS deployment.Netcore
vulnhub wpwn: 1
【语音合成】TensorFlowTTS 中文文本转语音
EFCore高级Saas系统下单DbContext如何支持不同数据库的迁移
GBase 8c 位串操作符(一)
Gbase 8C session information function (4)
Gbase 8C session information function (6)
GBase 8c系统表信息函数(三)