SlideShare a Scribd company logo
1 of 119
Transaction
트랜잭션이 뭔가요?
DB에서
상호작용의 단위
ACID
Atomicity
Consistency
Isolation
Durability
Atomicity
다 실행하거나
아무것도 안하거나
유저가 포인트로
아이템을 삽니다
1. 포인트를 깎는다.
2. 아이템을 지급한다.
그런데..
아이템을 생성하다
죽으면?
포인트만 나갔네…?
포인트만 나갔네…?
망했어?
안망했어?
Consistency
일관성
DB Constraints
PRIMARY KEY
UNIQUE
FOREIGN KEY
ENUM
위반하는 트랜잭션은
OUT!
Isolation
혼자 있고 싶습니다
모두 나가 주세요
고립성(Isolation)
다른 트랜잭션의
연산 작업이
끼어들지 못하도록
보장하는 것을
의미한다.
Durability
한번 커밋된 내용은
시스템 문제,
DB 일관성 체크 등
무슨 짓을 해도
영원히 반영
뭐 알아서
잘 만들었겠죠
Q.
왜
대충 DB ACID
검색하면 나오는
뻔한 얘기를 하고 있나요?
우리중 스파이가 있는 것 같아
Isolation
BEGIN TRANSACTION
BEGIN
TRANSACTION
BEGIN
TRANSACTION
BEGIN
TRANSACTION
BEGIN
TRANSACTION
다른 트랜잭션의
연산 작업이
끼어들지 못하도록
보장하는 것을
의미한다.
BEGIN
TRANSACTION
BEGIN
TRANSACTION
????????
먼저 시작한 놈이
뭘 하려는 거지?
BEGIN
TRANSACTION
BEGIN
TRANSACTION
????????
먼저 시작한 놈이
뭘 하려는 거지?
BEGIN
TRANSACTION
BEGIN
TRANSACTION
SELECT *
WHERE id=1
이러면 망하는데?
INSERT
id=1
BEGIN
TRANSACTION
BEGIN
TRANSACTION
????????
BEGIN
TRANSACTION
BEGIN
TRANSACTION
SLEEP(10000)
타협
타협 Level
Isolation Level
Serializable
내가 건드린건
보지 마
Read-Write Lock
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 20
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 20
1
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 20
120
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2
UPDATE users
SET age=21
where id=1
DB
1, 20
1 Locked!
20
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 20
1
2
20
20
Locked!
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 20
1
Locked!
Release!
2
20
20
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2
UPDATE users
SET age=21
where id=1
DB
1, 21
1
Release!
2
3
20
20
SELECT age
FROM users
WHERE id=1
기다리기 싫어요!
MORE 타협
REPEATABLE READ
첫인상
첫 READ
첫 READ가
트랜잭션 내내 유지
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 20
120
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 20
120
UPDATE users
SET age=21
where id=1
T1 Snapshot
1, 20
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 21
120
UPDATE users
SET age=21
where id=1
2
T1 Snapshot
1, 20
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 21
120
UPDATE users
SET age=21
where id=1
T1 Snapshot
1, 20 2
어
스냅샷이
20이네?
3
SELECT age
FROM users
WHERE id=1
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 21
120
UPDATE users
SET age=21
where id=1
T1 Snapshot
1, 20 2
그럼 20
디비가 뭐라든…
20 3
그 시점에 커밋된걸
보고 싶어요!
READ COMMITTED
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
120
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
120
UPDATE users
SET age=21
where id=1
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 21
120
UPDATE users
SET age=21
where id=1
2
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 21
120
UPDATE users
SET age=21
where id=1
2
어 21이네?
3
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 21
120
UPDATE users
SET age=21
where id=1
2
21 3
ACID 필요없어!
그냥 졸라 빠르게!
READ UNCOMMITTED
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 21
120
UPDATE users
SET age=21
where id=1
2
21
3
사실 뭔가
생략되어있어요
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 21
120
UPDATE users
SET age=21
where id=1
COMMIT
2
21
3
커밋을 안하고
롤백하면?
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
UPDATE users
SET age=21
where id=1
ROLLBACK
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
120
UPDATE users
SET age=21
where id=1
ROLLBACK
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
120
UPDATE users
SET age=21
where id=1
ROLLBACK
2
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
120
UPDATE users
SET age=21
where id=1
2
ROLLBACK
어 우리 커밋 안했는데
기다려야하는거 아니에요?
몰라 대충 넣어
SELECT age
FROM users
WHERE id=1
T1 T2 DB
1, 21
120
UPDATE users
SET age=21
where id=1
ROLLBACK
2
SELECT age
FROM users
WHERE id=1
21
3
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 21
120
UPDATE users
SET age=21
where id=1
2
21
3
ROLLBACK
4
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
120
UPDATE users
SET age=21
where id=1
2
21
3
ROLLBACK
4
롤백롤백
SELECT age
FROM users
WHERE id=1
T1 T2
SELECT age
FROM users
WHERE id=1
DB
1, 20
120
UPDATE users
SET age=21
where id=1
2
21
3
ROLLBACK
4
롤백롤백
????????
Q:
이럴거면 뭐하러
트랜잭션을 쓰죠?
A: 몰라요
권장하지 않아요.
MySQL Default
REPEATABLE READ
Postgres Default
READ COMMITTED
짜잘짜잘하게 다른데
그런건 알아서!
하고싶은 말
트랜잭션은
생각보다 만능이
아닙니다…
Execution Order
를 보장해주지 않아요.
끗

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Transaction