SlideShare a Scribd company logo
WareValley
http://www.WareValley.com
Database Audit and Protection [ DB 접근통제 ]
Database Encryption [ DB 암호화 ]
Database Vulnerability Assessment [ DB 취약점 분석 ]
Database SQL Query Approval [ DB 작업결재 ]
Database Performance Monitoring and Management [ DB 성능관리 및 개발 ]
WareValley
Oracle Architecture
Consistent vs Current
오렌지팀 윤석준 선임연구원
Database security and management, WareValley.
http://www.WareValley.com
Consistent vs Current Mode
 Consistent Mode : Query 문 실행시점의 Block으로 값을 읽음
 Current Mode : Query 실행 중 Table을 찾아간 시점의 Block값을 읽음
Database security and management, WareValley.
http://www.WareValley.com
UPDATE in Consistent Mode
Tx 1 : UPDATE emp SET sal = sal + 100
WHERE empno = 7788;
Tx 2 : UPDATE emp SET sal = sal + 200
WHERE empno = 7788;
(( 수행 중 ))
 e.g. empno = 7788 인 sal 값이 1,000 인 경우
 Query 시점 : sal = 1,000
-> 수행 후 sal = 1,100
 Query 시점 : sal = 1,000
-> 수행 후 sal = 1,200
Lost Update 발생 ( 최종 sal = 1,200 )
Database security and management, WareValley.
http://www.WareValley.com
UPDATE in Current Mode
Tx 1 : UPDATE emp SET sal = sal + 100
WHERE empno = 7788;
Tx 2 : UPDATE emp SET sal = sal + 200
WHERE empno = 7788;
(( 수행 중 ))
 e.g. empno = 7788 인 sal 값이 1,000 인 경우
 Table Block 읽을 시점 : sal = 1,000
-> 수행 후 sal = 1,100
 Table Block 읽을 시점 : sal = 1,100
-> 수행 후 sal = 1,300
Current Mode 님 쫌 짱이신듯…
인줄 알았는데 But 다음 페이지에서… (너덜너덜)
Database security and management, WareValley.
http://www.WareValley.com
UPDATE in Current Mode 2
Tx 1 : UPDATE T SET no = no + 1
WHERE no > 50000;
Tx 2 : INSERT INTO T (no) VALUES (100001);
(( 수행 중 ))
 e.g. T의 no 값은 unique하며, 1 ~ 10만까지 record가 있을 경우
Tx2 의 레코드가 어느 Block에 들어가느냐에 따라서
Tx1 에 의해 갱신된 레코드 수는 50,000개 일수도 있고, 50,001개 일수도 있다.
Database security and management, WareValley.
http://www.WareValley.com
READ in Consistent Mode, UPDATE in Current Mode
Tx 1 : UPDATE emp SET sal = sal + 100
WHERE empno = 7788
AND sal = 1000;
Tx 2 : UPDATE emp SET sal = sal + 200
WHERE empno = 7788
AND sal = 1000;
(( 수행 중 ))
 e.g.
READ 를 Consistent Mode 로 찾아서
UPDATE 시 sal 값 1100 을 읽어와서 1300으로 갱신
뭔가 쫌….
UPDATE
(
SELECT sal FROM emp
WHERE empno = 7788
AND sal = 1000
)
SET sal = sal + 200
Database security and management, WareValley.
http://www.WareValley.com
SELECT update target in Consistent Mode, UPDATE in Current Mode
Tx 1 : UPDATE emp SET sal = sal + 100
WHERE empno = 7788
AND sal = 1000;
Tx 2 : UPDATE emp SET sal = sal + 200
WHERE empno = 7788
AND sal = 1000;
(( 수행 중 ))
 e.g.
Consistent Mode 에서 UPDATE 할 대상들을 가져와서
UPDATE 시 Consistent Mode에서 수행한 조건들을 한번 더 Check
이제 이 녀석이 짱 먹어도 될까 ?그럼 이건 과연 완벽할까 ?
for c in
(
SELECT rowid rid, emp, sal FROM emp
WHERE empno = 7788
AND sal = 1000
)
loop
UPDATE emp SET sal = sal + 200
WHERE empno = c.empno
AND sal = c.sal
AND rowid = c.rid
end loop;
Database security and management, WareValley.
http://www.WareValley.com
Inconsistent Update
UPDATE Account2 A2
SET amount = A2.amount + (SELECT amount FROM Account1 WHERE id = A2.id)
WHERE id = 7788;
 e.g.
UPDATE Account2 A2
SET amount = (SELECT A2.amount + amount FROM Account1 WHERE id = A2.id)
WHERE id = 7788;
Consistent ModeCurrent Mode
Current Mode Current Mode
Database security and management, WareValley.
http://www.WareValley.com
Things to Remeber
 Oracle 에서 SELECT 는 Consistent Mode로 읽는다.
 DML ( INSERT, UPDATE, DELETE, MERGE ) 는
Consistent Mode로 대상을 식별한 후
Current Mode로 읽어서 갱신한다.
 Oracle Consistent Model을 잘 이해하고,
Query 작성시 Coding Style에 따라
미묘한 차이가 생길 수 있다는 사실을 인지하라.

More Related Content

More from Seok-joon Yun

Pro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformancePro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, Performance
Seok-joon Yun
 
Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07
Seok-joon Yun
 
Doing math with python.ch06
Doing math with python.ch06Doing math with python.ch06
Doing math with python.ch06
Seok-joon Yun
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05
Seok-joon Yun
 
Doing math with python.ch04
Doing math with python.ch04Doing math with python.ch04
Doing math with python.ch04
Seok-joon Yun
 
Doing math with python.ch03
Doing math with python.ch03Doing math with python.ch03
Doing math with python.ch03
Seok-joon Yun
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02
Seok-joon Yun
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01
Seok-joon Yun
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
Seok-joon Yun
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threads
Seok-joon Yun
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
Seok-joon Yun
 
[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2
Seok-joon Yun
 
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4Seok-joon Yun
 
오렌지6.0 교육자료
오렌지6.0 교육자료오렌지6.0 교육자료
오렌지6.0 교육자료
Seok-joon Yun
 
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
Seok-joon Yun
 
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
Seok-joon Yun
 
[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX Lock[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX Lock
Seok-joon Yun
 
[KOSSA] C++ Programming - 18th Study - STL #4
[KOSSA] C++ Programming - 18th Study - STL #4[KOSSA] C++ Programming - 18th Study - STL #4
[KOSSA] C++ Programming - 18th Study - STL #4
Seok-joon Yun
 
[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3
Seok-joon Yun
 
[KOSSA] C++ Programming - 16th Study - STL #2
[KOSSA] C++ Programming - 16th Study - STL #2[KOSSA] C++ Programming - 16th Study - STL #2
[KOSSA] C++ Programming - 16th Study - STL #2
Seok-joon Yun
 

More from Seok-joon Yun (20)

Pro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, PerformancePro typescript.ch07.Exception, Memory, Performance
Pro typescript.ch07.Exception, Memory, Performance
 
Doing math with python.ch07
Doing math with python.ch07Doing math with python.ch07
Doing math with python.ch07
 
Doing math with python.ch06
Doing math with python.ch06Doing math with python.ch06
Doing math with python.ch06
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05
 
Doing math with python.ch04
Doing math with python.ch04Doing math with python.ch04
Doing math with python.ch04
 
Doing math with python.ch03
Doing math with python.ch03Doing math with python.ch03
Doing math with python.ch03
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threads
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2[2015-07-20-윤석준] Oracle 성능 관리 2
[2015-07-20-윤석준] Oracle 성능 관리 2
 
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
[2015 07-06-윤석준] Oracle 성능 최적화 및 품질 고도화 4
 
오렌지6.0 교육자료
오렌지6.0 교육자료오렌지6.0 교육자료
오렌지6.0 교육자료
 
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
 
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
[2015-06-19] Oracle 성능 최적화 및 품질 고도화 2
 
[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX Lock[2015-06-05] Oracle TX Lock
[2015-06-05] Oracle TX Lock
 
[KOSSA] C++ Programming - 18th Study - STL #4
[KOSSA] C++ Programming - 18th Study - STL #4[KOSSA] C++ Programming - 18th Study - STL #4
[KOSSA] C++ Programming - 18th Study - STL #4
 
[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3[KOSSA] C++ Programming - 17th Study - STL #3
[KOSSA] C++ Programming - 17th Study - STL #3
 
[KOSSA] C++ Programming - 16th Study - STL #2
[KOSSA] C++ Programming - 16th Study - STL #2[KOSSA] C++ Programming - 16th Study - STL #2
[KOSSA] C++ Programming - 16th Study - STL #2
 

[Oracle Architecture][2015 04-17] Consistent vs Current

  • 1. WareValley http://www.WareValley.com Database Audit and Protection [ DB 접근통제 ] Database Encryption [ DB 암호화 ] Database Vulnerability Assessment [ DB 취약점 분석 ] Database SQL Query Approval [ DB 작업결재 ] Database Performance Monitoring and Management [ DB 성능관리 및 개발 ] WareValley Oracle Architecture Consistent vs Current 오렌지팀 윤석준 선임연구원
  • 2. Database security and management, WareValley. http://www.WareValley.com Consistent vs Current Mode  Consistent Mode : Query 문 실행시점의 Block으로 값을 읽음  Current Mode : Query 실행 중 Table을 찾아간 시점의 Block값을 읽음
  • 3. Database security and management, WareValley. http://www.WareValley.com UPDATE in Consistent Mode Tx 1 : UPDATE emp SET sal = sal + 100 WHERE empno = 7788; Tx 2 : UPDATE emp SET sal = sal + 200 WHERE empno = 7788; (( 수행 중 ))  e.g. empno = 7788 인 sal 값이 1,000 인 경우  Query 시점 : sal = 1,000 -> 수행 후 sal = 1,100  Query 시점 : sal = 1,000 -> 수행 후 sal = 1,200 Lost Update 발생 ( 최종 sal = 1,200 )
  • 4. Database security and management, WareValley. http://www.WareValley.com UPDATE in Current Mode Tx 1 : UPDATE emp SET sal = sal + 100 WHERE empno = 7788; Tx 2 : UPDATE emp SET sal = sal + 200 WHERE empno = 7788; (( 수행 중 ))  e.g. empno = 7788 인 sal 값이 1,000 인 경우  Table Block 읽을 시점 : sal = 1,000 -> 수행 후 sal = 1,100  Table Block 읽을 시점 : sal = 1,100 -> 수행 후 sal = 1,300 Current Mode 님 쫌 짱이신듯… 인줄 알았는데 But 다음 페이지에서… (너덜너덜)
  • 5. Database security and management, WareValley. http://www.WareValley.com UPDATE in Current Mode 2 Tx 1 : UPDATE T SET no = no + 1 WHERE no > 50000; Tx 2 : INSERT INTO T (no) VALUES (100001); (( 수행 중 ))  e.g. T의 no 값은 unique하며, 1 ~ 10만까지 record가 있을 경우 Tx2 의 레코드가 어느 Block에 들어가느냐에 따라서 Tx1 에 의해 갱신된 레코드 수는 50,000개 일수도 있고, 50,001개 일수도 있다.
  • 6. Database security and management, WareValley. http://www.WareValley.com READ in Consistent Mode, UPDATE in Current Mode Tx 1 : UPDATE emp SET sal = sal + 100 WHERE empno = 7788 AND sal = 1000; Tx 2 : UPDATE emp SET sal = sal + 200 WHERE empno = 7788 AND sal = 1000; (( 수행 중 ))  e.g. READ 를 Consistent Mode 로 찾아서 UPDATE 시 sal 값 1100 을 읽어와서 1300으로 갱신 뭔가 쫌…. UPDATE ( SELECT sal FROM emp WHERE empno = 7788 AND sal = 1000 ) SET sal = sal + 200
  • 7. Database security and management, WareValley. http://www.WareValley.com SELECT update target in Consistent Mode, UPDATE in Current Mode Tx 1 : UPDATE emp SET sal = sal + 100 WHERE empno = 7788 AND sal = 1000; Tx 2 : UPDATE emp SET sal = sal + 200 WHERE empno = 7788 AND sal = 1000; (( 수행 중 ))  e.g. Consistent Mode 에서 UPDATE 할 대상들을 가져와서 UPDATE 시 Consistent Mode에서 수행한 조건들을 한번 더 Check 이제 이 녀석이 짱 먹어도 될까 ?그럼 이건 과연 완벽할까 ? for c in ( SELECT rowid rid, emp, sal FROM emp WHERE empno = 7788 AND sal = 1000 ) loop UPDATE emp SET sal = sal + 200 WHERE empno = c.empno AND sal = c.sal AND rowid = c.rid end loop;
  • 8. Database security and management, WareValley. http://www.WareValley.com Inconsistent Update UPDATE Account2 A2 SET amount = A2.amount + (SELECT amount FROM Account1 WHERE id = A2.id) WHERE id = 7788;  e.g. UPDATE Account2 A2 SET amount = (SELECT A2.amount + amount FROM Account1 WHERE id = A2.id) WHERE id = 7788; Consistent ModeCurrent Mode Current Mode Current Mode
  • 9. Database security and management, WareValley. http://www.WareValley.com Things to Remeber  Oracle 에서 SELECT 는 Consistent Mode로 읽는다.  DML ( INSERT, UPDATE, DELETE, MERGE ) 는 Consistent Mode로 대상을 식별한 후 Current Mode로 읽어서 갱신한다.  Oracle Consistent Model을 잘 이해하고, Query 작성시 Coding Style에 따라 미묘한 차이가 생길 수 있다는 사실을 인지하라.