当前位置:网站首页>In the process of enterprise development, I found that a colleague used the select * from where condition for update
In the process of enterprise development, I found that a colleague used the select * from where condition for update
2022-06-25 00:23:00 【SteveCode.】
Active address : Graduation season · The technique of attack er
In the workplace Introvert
In the process of enterprise development, I found that a colleague used select * from where Conditions for update
ok ! Today I learned my first hand Send a post by the way . Hey
My article for reference
Novice tutorial -MySQL Business
Interviewer asked :select…for update Will you lock the table or the row ?
Start bar ! Hey
Look at a paragraph sql, Feel if you are confused There may also be big men
BEGIN;
SELECT * FROM a WHERE `key`=1 FOR UPDATE;
UPDATE a SET `name`='songxy9991' WHERE `key` =1;
COMMIT;
SELECT @@autocommit;
SET @@autocommit =0;
SELECT * FROM a WHERE `key`=1 FOR UPDATE;
COMMIT;
UPDATE a SET `name`='songxy12' WHERE `key` =1;
We explain one by one
- Here we are. We'll talk about This transaction Holy and great . Either successful or unsuccessful . Principle 、 Uniformity 、 Isolation, 、 persistence . Wait, Ba , And the isolation level of transactions , also spring Propagation characteristics of transactions in They are all regular interview sites
BEGIN
Is to start a transaction
COMMIT;
Commit transaction
SELECT @@autocommit;
Check whether the transaction is statically auto committed
autocommit State value description
- AUTOCOMMIT=0 Disable auto submit
- AUTOCOMMIT=1 Turn on auto submit
modify state : - SET AUTOCOMMIT=0 Disable auto submit
- SET AUTOCOMMIT=1 Turn on auto submit
MySQL By default, the database will be Automatically start the transaction

Here we are Don't let him commit transactions automatically Stop him first
SET @@autocommit =0;
SELECT @@autocommit;

The real Kung Fu begins Ha
- Create table statement
DROP TABLE IF EXISTS `a`;
CREATE TABLE `a` (
`key` int(0) NOT NULL AUTO_INCREMENT,
`value` char(225) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`key`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of a
-- ----------------------------
INSERT INTO `a` VALUES (1, 'ssss', 'songxy12');
INSERT INTO `a` VALUES (2, 'yy', 'songxy');
INSERT INTO `a` VALUES (3, 'sxy', 'songxy');
INSERT INTO `a` VALUES (4, '1111', 'songxy');
INSERT INTO `a` VALUES (5, 'qqq', 'songxy');
SET FOREIGN_KEY_CHECKS = 1;
Let's take a look at the data in my previous table

First, check through the primary key
SELECT * FROM a WHERE `key`=1 FOR UPDATE;
Execute this sql I didn't COMMIT; Ha

In execution
UPDATE a SET `name`='songxy999' WHERE `key` =1;
Look up the table data

- No change
Execute the statement that commits the transaction
COMMIT;

- Is the lock OK or surface Let me try

- Wrong report ;error
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-OPLNv5n5-1655994728162)(https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4af5d417b96646b0a4a1430460b7d594~tplv-k3u1fbpfcp-watermark.image?)]
Look at the picture

This shows that the lock line
Active address : Graduation season · The technique of attack er
边栏推荐
- JPA learning 1 - overview, JPA, JPA core annotations, JPA core objects
- iNFTnews | 国内NFT发展仅限于数字藏品吗?
- ServerSocket and socket connection
- In the past 5 years, from "Diandian" to the current test development, my success is worth learning from.
- Paper review: U2 net, u-net composed of u-net
- 第三代电力电子半导体:SiC MOSFET学习笔记(五)驱动电源调研
- 人体改造 VS 数字化身
- The third generation of power electronics semiconductors: SiC MOSFET learning notes (V) research on driving power supply
- I suddenly find that the request dependent package in NPM has been discarded. What should I do?
- Analysis report on development trend and investment forecast of global and Chinese D-leucine industry from 2022 to 2028
猜你喜欢

JPA learning 2 - core annotation, annotation addition, deletion, modification and query, list query result return type, one to many, many to one, many to many

不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...

A small program written this week

Use and click of multitypeadapter in recycleview

What is the difference between one way and two way ANOVA analysis, and how to use SPSS or prism for statistical analysis

Ansible及playbook的相关操作

What are the advantages of VR panoramic production? Why is it favored?

Fast pace? high pressure? VR panoramic Inn brings you a comfortable life

Unimportant tokens can be stopped in advance! NVIDIA proposes an efficient visual transformer network a-vit with adaptive token to improve the throughput of the model

Signal integrity (SI) power integrity (PI) learning notes (XXV) differential pair and differential impedance (V)
随机推荐
How can I persuade leaders to use DDD to construct the liver project?
Helm chart仓库操作
Unmanned driving: Some Thoughts on multi-sensor fusion
More pictures | explain the Nacos parameters in detail!
5-minute NLP: summary of 3 pre training libraries for rapid realization of NER
MySQL semi sync replication
VNC viewer remote connection raspberry pie without display
Applet opening traffic master
【面试题】instancof和getClass()的区别
Binder mechanism and Aidl communication example
iNFTnews | 国内NFT发展仅限于数字藏品吗?
Go crawler framework -colly actual combat (II) -- Douban top250 crawling
Meta&伯克利基于池化自注意力机制提出通用多尺度视觉Transformer,在ImageNet分类准确率达88.8%!开源...
Eliminate duplicate dependencies
[interview question] the difference between instancof and getclass()
技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
浅析大型IM即时通讯系统开发难度
[distributed system design profile (2)] kV raft
VIM use command
Jar package merging using Apache ant