Analysis and summary of the impact of MySQL transactions on efficiency

Analysis and summary of the impact of MySQL transactions on efficiency

1. Database transactions will reduce database performance. In order to ensure data consistency and isolation, transactions need to lock transactions.

2. If other transactions need to operate this part of data, they must wait for the last transaction to end (commit, rollback).

Examples

create table acct(
    acct_no varchar(32),
    acct_name varchar(32),
    balance decimal(16,2)
);
 
insert into acct values
    ('0001','Jerry', 1000),
    ('0002','Tom', 2000);
 
start transaction; -- Start transaction update acct set balance = balance - 100 where acct_no = '0001'; -- Simulate the deductor update acct set balance = balance + 100 where acct_no = '0002'; -- Simulate the payee commit; -- Transaction commit rollback; -- Transaction rollback

Knowledge point expansion:

Transactions

  • Atomicity: All operations of the entire transaction are either successfully committed or rolled back if they fail.
  • Consistency: refers to the transaction converting the database from one consistent state to another consistent state, and the integrity of the database is not destroyed before and after the transaction starts.
  • Isolation: requires that a transaction modify data in the database and that the modification is not visible to other transactions until it is completed.
  • Persistence: Once a transaction is committed, the changes it makes are permanently saved to the database. At this point, even if the system crashes, the modified data that has been submitted will not be lost.

Big Business

Transactions that take a long time to run and operate on a large amount of data

  • Locking too much data, causing a lot of blocking and lock timeouts
  • Rollback takes a long time
  • Long execution time, which may cause master-slave delay

How to handle big transactions:

  • Avoid processing too much data at once
  • Remove unnecessary select operations from transactions

This concludes this article on the impact of MySQL transactions on efficiency. For more information on the impact of MySQL transactions on efficiency, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to implement distributed transactions in MySQL XA
  • Implementation of Node connection to MySQL query transaction processing
  • MySQL database transaction example tutorial
  • Seven solutions for classic distributed transactions between MySQL and Golan
  • MySQL transaction isolation level details
  • Detailed explanation of transactions and indexes in MySQL database
  • MySQL transaction analysis

<<:  Vue3+Vite+TS implements secondary encapsulation of element-plus business components sfasga

>>:  HTML table layout example explanation

Recommend

CentOS7 deployment Flask (Apache, mod_wsgi, Python36, venv)

1. Install Apache # yum install -y httpd httpd-de...

Detailed explanation of the correct way to open em in CSS

Why do we say “usually 1em=16px”? The default tex...

JavaScript Basics: Immediate Execution Function

Table of contents Immediately execute function fo...

Docker installation and configuration steps for MySQL

Table of contents Preface environment Install Cre...

How to design and optimize MySQL indexes

Table of contents What is an index? Leftmost pref...

Summary of some common configurations and techniques of Nginx

Preface This article lists several common, practi...

How to calculate the value of ken_len in MySQL query plan

The meaning of key_len In MySQL, you can use expl...

A brief discussion on the Linux kernel's support for floating-point operations

Currently, most CPUs support floating-point units...

VPS builds offline download server (post-network disk era)

motivation Due to learning needs, I purchased a v...

Solve the problem of setting Chinese language pack for Docker container

If you use docker search centos in Docker Use doc...