- input query → relational algebra
- parser checks syntax & verifies if the query expression is correct or not
- The process of choosing suitable execution strategy to process a query (translated algebra)
- how to reduce the number of disk access
- how to reduce the size of intermediate result
- how to reduce the response time
ex)
← 효율성 ↑ex)
← 효율성 ↑
- The query-evaluation engine generates an executable code
from the optimized algebra, executes the code and finally
returns the answer
- Q: Retrieve name of students who register 'C413' course
- Step 1) → SQL Query
FROM S,E WHERE S.Sno=E.Sno AND Cno='C413'
- Step 2) → Relational Algebra (parser & translator)
- Step 3) → More Efficient Relational Algebra (optimization)
- read(A)
- A := A-50
- write(A)
- read(B)
- B := B+50
- write(B)
Atomicity issue
in a case of failure
- step 3 / step 6 사이에 failure 발생하면 데이터에 문제가 생길 수 있음
- 트랜잭션은 DB를 완벽하고 정확하게 update하거나 update하지 말아야함
Consistency issue
- 위 드랜잭션 수행 전후의 A와 B의 합은 유지되어야함
- 트랜잭션 수행 전후의 데이터의 일관성이 유지되어야함
Isolation issue
in a case of multiple transactions
- step 3 / step 6 사이에 다른 트랜잭션 T2가 DB에 억세스하면, T2의 결과가 틀릴 수 있음
- T2:
- isolation(고립)이란 여러 개의 트랜잭션이 동시에 수행될때 서로 영향을 주지 않으면서 각 트랜잭션이 완료되어야함
- 해결방안: 트랜잭션을 순차적으로 수행하는 방법 etc.
Durability issue
- 한번 완료된 트랜잭션의 결과는 계속 유지되어야함
- 트랜잭션 완료 후 SW, HW failure가 발생해도 결과가 유지되어야함
- 완료된 트랜잭션의 결과는 휘발성 메모리보다는 하드디스크에 저장하는 것이 안정적임
Atomicity: failure 상황 발생해도 데이터에 문제가 생기지 않도록 update 여부 결정
Consistency: 전후 데이터의 합 이 일정해야함
Isolation: multiple transaction에서 동일한 곳 접근할때는 순차적으로
Durability: 비휘발성 메모리에 저장
Active 상태
- 트랜잭션의 초기 상태 및 실행 중인 상태
Partially committed (부분 완료) 상태
- 트랜잭션의 마지막 operation이 실행된 직후의 상태
Failed (실패) 상태
- 트랜잭션이 완료되기 전에 더 이상 정상적인 수행이 불가능한 상태
Aborted (중단) 상태
- 트랜잭션 실패로 진입하는 상태
- 트랜잭션 중단 상태 이후 처리 방법
- restart the transaction
- kill the transaction
Committed (완료) 상태
- 트랜잭션을 성공적으로 완료한 상태
ex)
create domain hourly-wage float(3) constraint value-test check(value >= 4.00)
ex)
create domain GENDER char(1) constraint value-test check(value in ('남', '여'))
ex)
create table 학생 (이름 varchar(15) not null, 학년 INT, 성별 GENDER, ← 자료형 자리에 DOMAIN CONSTRAINT 이름 PRIMARY KEY(이름), CONSTRAINT 학년제약 CHECK(학년>=1)); ← CONSTRAINT 추가
ex)
create table account (branch-name char(15), account-number char(10) not null, balance integer, primary key(account-number), foreign key(branch-name) references branch) ← 외래키 제약조건
ex)
create table account (branch-name char(15), account-number char(10) not null, balance integer, primary key(account-number), foreign key(branch-name) references branch ← 쉼표 없음에 주의 on delete cascade ← on delete cascade; 쉼표 없음에 주의 on update cascade) ← on update cascade; 쉼표 없음에 주의
on delete cascade
- branch relation에서 어떤 tuple이 삭제되면, account relation에서 해당 branch_name을 가지고 있는 튜플도 함께 삭제
on update cascade
- branch relation에서 어떤 tuple의 branch_name이 갱신되면, account relation에서 해당 branch_name의 값도 함께 갱신