当前位置:网站首页>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
边栏推荐
- 如何提升数据质量
- PHP implements stripe subscription
- Take stock of 10 new layer1 to prepare for the next bull market
- GBase 8c系统表信息函数(二)
- [video game training] non contact object size and shape measurement 2020 video game G
- Flutter | specifies the type of page return value
- AWS Part 4 one machine and one secret
- Summarize the plan, clarify the direction, concentrate and start a new situation -- the Counterpart Assistance Project of hexu software has achieved remarkable results
- How to open a low commission account? Is it safe?
- C language macro definition
猜你喜欢

English语法_指示代词 - So

Pipeline pipeline project is built by declarative and jenkinsfile under Jenkins
CA digital certificate

English grammar_ Demonstrative pronoun -such / the same

Understanding polymorphism and letting different "people" do the same thing will produce different results

数仓数据指标和标签体系区别

Table custom table encapsulation

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

Detailed overview of data standards -2022

Delete all data of specified query criteria in Oracle
随机推荐
二叉搜索树的简易实现及剖析
分布式之 CAP 原则
Gbase 8C string operator
高数_第1章空间解析几何与向量代数__两点距
Mobile terminal H5 - a lifeline timeline
采坑websocket總結
Multi data source configuration of mongodb
Redis data structure
English grammar_ Demonstrative pronoun -such / the same
Pytest interface automated testing framework | how to get help
Summary of pit websocket
Pytest interface automation testing framework | multi process running case
Simple implementation and analysis of binary search tree
【低代码】低代码发展的局限性
Blockbuster | certik: Web3.0 industry safety report release in the second quarter of 2022 (PDF download link attached)
蓝绿部署、金丝雀发布、A/B测试是什么
Gbase 8C bit string operator (I)
Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
Gbase 8C string Operator
The universal esp32c3 configures partition tables based on the Arduino ide framework