Object-Relational 데이터베이스
목차
객체-관계(Object-Relational) 모델 개요
1
복합 자료형
2
SQL에서의 구조형/상속/배열/다중집합
3
SQL의 참조형 및 객체 식별자
4
객체 -관계 특징구현
5
RDBMS/OODBMS/ORDBMS
6
관계형 데이터 모델의 문제
• 전통적인 데이타베이스 응용 프로그램들은 은행 업무나 급여 관리 등의 자료 처리 작업들로 구성
• 그러나, CAD/CAM, 과학 실험, 통신, 지리 정보 시스템, 멀 티미디어등과 같은 보다 복잡한 데이터 응용을 지원하는 데는 충분하지 못함
• 복잡한 응용 프로그램들은 중첩 레코드 구조, 다중값 속 성, 상속등 전통적인 프로그래밍 언어들에서 지원돼 온 복합 자료형 필요
3/24
관계형 데이터 모델의 문제
• 이를 위해 복합 자료형을 지원하는 객체 기반 데이타베 이스 등장
• 관계형 데이타베이스를 쓰기 위해서는 이들을 단순한 SQL 자료형으로 변환될 필요가 있음
• 객체-관계형 자료 모델
– 복합 자료형과 객체지향 등 풍부한 형 시스템을 지원함으로써 기 존의 관계형 모델을 확장한 것
– 이를 지원하기 위해서는 SQL등의 관계형 질의어도 확장되어야
함
5/24
객체-관계형 자료 모델 개요
(Object-Relational Data Models)
관계형(Relational) 자료 모델
객체-관계형 자료모델
상속(Inheritance)
typei field0 field1 field2 field…n
typej field0 field1 field2
… fieldn
복합자료형
(e.g. 구조형,다중집합, 배열 등…)
함수(function) 및 메소드(method) 정의 (polymorphism)다형성
자료추상화 (Data Abstraction)
관계형 모델에 기반
객체지향적 요소
Structured User-Defined Types
Attributes & Behavior
Encapsulated : functions & methods
Observers & Mutators
Type Hierarchies
User-Defined CAST, ordering
Typed tables & reference types
확장된 형(type) 시스템
collection types
large-object support
User-defined data types
기타 …
복합 자료형
(Relational) 관계형 모델
객체관계형 (Object- Relational)
모델
다중값 속성
(multi-valued attr.)
keywords복합 속성
(composite attr.)
address
street
city state
SQL:1999에서
구조형(Structured Type) 정 의
구조형 필드를 속성으로 갖는 테이블 생성
필드로 구분하여 각 필드 를 분리된 속성들로 구성
배열형 속성 또는 다중집합 속성으로 표현 다중값 속성을 별도의 릴레이션으로 분리
복합 속성 및 다중값 속성 표현 차이점
7/24
구조형 (SQL1999 : Structured User- Defined Type)
명칭
구조형(Structured Type)or 사용자 정의 구조형 (Structured User-Defined Type)
특징
다수의 속성(attributes)들로 구성되며 각 속성은 내장타입(built-in type), 중첩(nested)레코드 타입, 배열다중집합이 될 수 있다. 메소드, 함수, 프로시져에 의해 행동을 정의할 수 있다.
시스템이 정의한 observer 및 mutator functions(e.g. get..(), set..())에 의 해 각 속성이 은닉된다. 또한, 시스템이 정의한 기본함수들은 재정의 될 수 없다.
사용자 정의 함수에 의한 사용자 정의 타입간 비교연산 수행
형-상속(type-inheritance)지원
구문형식
CREATE TYPE name
[ UNDER supertype-name ] AS ( attribute-name type, … ) [ [ NOT ] INSTANTIABLE ] [ NOT ] FINAL
[ REF ref-option ] [ method-spec, … ]
SQL:1999의 구조형(Structured type) 요약
구조형 정의 및 테이블생성 예제
firstname lastname
city
zipcode name
street
dateOfBirth customer
address
E-R 모델
방법3 방법 1
create type Name as (
firstname varchar(20), lastname varchar(20)) final
create table customer ( name Name, address Address, dateOfBirth date)
create type Address as ( street varchar(20), city varchar(20), zipcode varchar(9)) not final
방법2
create type CustomerType as ( name Name, address Address, dateOfBirth date) not final
create table customer of CustomerType
create table customer_r (
name row ( firstname varchar(20), lastname varchar(20)), address row ( street varchar(20),
city varchar(20), zipcode varchar(9)), dateOfBirth date)
구조형으로 복합 속성 표현
“ 사용자 정의형 행(row) ” 으로 테이블 생성
“ 이름 없는 행형(row type) ” 을 사용한 테이블 생성
접근 방법 :
- name.firstname : name 속성의 firstname 반환 - Name : Name 구조형의 값 반환
예) select name.lastname, address.city from customer
CustomerType형을 정의하고 customer 테이블 생성
firstname 속성과 lastname 속성 을 갖는 복합 속성Name 표현
9/24
구조형 - method
선언방법
구조형의 형 정의와 함께 메소드 선언 메소드 몸체는 별도의 SQL문장으로 정의
특징
하위형의 정의에서 메소드 재정의 허용 예. CREATE TYPE P AS …
METHOD salary() RETURNS DECIMAL(9,2)
CREATE TYPE C UNDER P AS …OVERRIDING METHOD salary() RETURNS DECIMAL(9,2)
재정의되는 메소드는 상위형의 메소드와 동일한 시그너쳐(signature)를 갖 도록 선언되어야 한다.
정의 SQL-invoked functions “attached” to user-defined type
선언 예
CREATE TYPE CustomerType as ( name Name,…) not final
METHOD ageOnDate(onDate date) returns interval year
CREATE INSTANCE METHOD ageOnDate(onDate date) returns interval year
for CustomerType begin … end
몸체 예
이 메소드가CustomerType을 위한 메소드임을 나타냄 이 메소드가 Customer 형 인스턴
스에 대해 수행된다는 것을 나타냄
구조형 값의 생성
생성자 함수
SQL:1999에서는 생성자 함수를 사용하여 구조형 값을 생성
구조형과 같은 이름을 갖는 함수가 해당 형의 생성가가 됨
예) Name구조형의 생성자 정의
create function Name
(firstname varchar(20), lastname varchar(20)) returns Name
begin
set self. firstname
=firstname
;set self. lastname
=lastname
;end
예) Name구조형 값 생성
insert into Customer
values
(new Name
(‘John’, ‘Smith’),new Address
(‘…’, ‘…’, ‘…’),date ‘1960-8-22’)
Name 형 변수 생성
11/24
형 상속 (Type Inheritance)
형 상속(SQL:1999)
구조형은 다른 구조형의 하위형(subtype)이 될 수 있다.
하위 구조형은 상위 구조형의 메소드와 속성들을 상속받는다 .
하위 구조형은 상위 구조형의 메소드를 재정의 할 수 있다 .
SQL1999에서는 단일 상속만 지원.
FINAL vs. NOT FINAL
FINAL로 정의된 구조형은 다른 구조형의 상위형(supertype)이 될 수 없다.
NOT FINAL로 정의된 구조형은 다른 구조형의 상위형(supertype) 이 될 수 있다.
EER 모델 SQL:1999 스키마정의
형 상속 (Type Inheritance)
Person city
zipcode street
address
ISA
Student Teacher
degree dept. salary dept.
릴레이션
create type Person as ( name Name,
address Address))
create type Student under Person as
( degree varchar(20), dept varchar(20))
create type Teacher under Person as ( salary integer, dept varchar(20))
create table Tstudent of Student
create table Tteacher of Teacher
1stname name 2ndname
Tstudent
(name, address, degree, dept)
Tteacher
(name, address, salary,
dept)
13/24
테이블 상속 (Table Inheritance)
테이블 상속
하위테이블의 형(type)은 부모테이블의 형(type)의 하위형(subtype)으로 정의.
하위테이블의 모든 튜플은 암묵적으로 상위테이블에 있게 된다.
즉, People 테이블에 대해 질의를 할 경우, 그 테이블에 직접적으로 삽입된 투플 만 찾는 것이 아니라 students나 teachers와 같은 하위 테이블에 삽입된 투플도 찾게 됨.
예) create table
people
ofPerson
create tablestudents
ofStudent
under
people
create table
teachers
ofTeacher
underpeople
• SQL에서 질의에 people 대신에 “Only people”을 사용함으로써 하위 테이블이 아닌 people에만 있는 투플을 찾을 수 있음
people
students teachers
테이블 상속 (Table Inheritance)
하위 테이블에 대한 연속성 요구
즉, 하위 테이블에 있는 투플이 모든 상속된 속성에 대해 같은 값을 가지고 있다면 , 해당 투플이 부모 테이블의 투플에 대응한다라고 말한다. 따라서 그 러한 투플은 같은 개체를 나타낸다 .
1. 상위 테이블의 각 튜플은 해당 하위 테이블 각각에서의 많아야 한 튜플에 해당한 다.
(e.g. students(또는 teachers) 테이블에서 단 하나의 튜플만이 people테이블에 대응된다.)
2. SQL:1999 에서는 서로에 대응하는 모든 튜플은 한 튜플에서 끌어내야 한다는 추 가적인 제약을 가지고 있다(한 테이블에 삽입된다)
(e.g. students이면서 teachers인 튜플은 허용하지 않는다. 즉, 모든 엔티티는 정 확히 단 하나의 가장 구체적인 형을 가져야만 한다.)
15/24
다중상속
다음과 같은 다중 상속을 한 구조형 정의 가능
create type teaching_assistant under student, teacher
위의 경우 name, address, department의 속성들이 student와 teacher 모두에 존재하여 문 제 발생
그러나, Name, address는 동일한 people에서 계승되므로 충돌이 일어나지 않음
department는 student와 teacher에서 서로 다르게 정의되어 문제
아래와 같은 구조형 정의로 해결
as 절의 이용하여 새로운 이름 할당
create type teaching_assitant under
student with (department as student_dept),
teacher with (department as teacher_dept)
SQL의 배열과 다중집합형
SQL의 집단형 (Collection Types)
배열 (array) 다중집합 (multiset)
SQL:1999에 추가된 데이터타입
원소에 순서가 있는 집합체
SQL:2003에 추가된 데이터타입
한 원소가 여러 번 등장할 수 있는 순서 없는 집합체
선언예제
create type Publisher as
(
name varchar(20), branch varchar(20)) create type Book as
(
title varchar(20),
author_array varchar(20) array[10], pub_date date,
publisher Publisher,
keyword_set varchar(20) multiset) create table books of Book
최대 10명인 작가이름의 배열 (저자의 순서가 정의됨)
키워드들의 다중집합
(순서가 중요하지 않음)
17/24
집단 (Collection) 값 관련 연산 예
튜플생성
insert into table books
(title, author_array, pub_date, publisher, keyword_set) values(‘DB’, ARRAY[‘Lee’,’Cho’,’Choi’], date ’2006-1-1, new Publisher(‘McGraw’,’Seoul’),
multiset[‘SQL’,’DBMS’])
튜플갱신 update books set
author_array[1] = ‘Joshua’;
튜플검색
‘database’를 키워드로 갖는 모든 책 검색
select title from books
where ‘database’ in ( unnest (keyword_set))
제목이 ‘DB’인 책의 첫 번째 및 두 번째 저자를 검색
select author_array[0], author_array[1] from books where title = ‘DB’
각 책과 해당 책의 작가에 대해 “제목, 저자명” 형태의 릴레이션 반환
select B.title, A.author
from books as B, unnest (B.author_array) as A(author)
비중첩 (unnesting)
정의
중첩된 릴레이션을 중첩이 더 적은(fewer) 또는 전혀 없는 릴레이션 값-속성의 형태로 변경비중첩(unnesting)의 예
title author_
array publisher keyword_se t
{name
…} (pub_name, pub_branch) Compilers {Smith,
Jones} (McGraw-Hill,
New York) {parsing, analysis}
Networks {Jones,
Frick} (Oxford,
London) {Internet, Web}
[중첩된 릴레이션]
title author publisher pub_branch keyword Compilers Smith McGraw-Hill New York parsing Compilers Jones McGraw-Hil New York parsing Compilers Smith McGraw-Hill New York analysis Compilers Jones McGraw-Hil New York analysis Networks Jones Oxford London Internet Networks Frick Oxford London Internet
Networks Jones Oxford London Web
Networks Frick Oxford London Web
[비중첩된 릴레이션]
select title, A.author,
publisher.name as pub_name,
publisher.branch as pub_branch, K.keyword from
books as B, unnest(B.author_array) as A(author),
unnest (B.keyword_set) as K(keyword)
19/24
중첩 (nesting)
정의
1NF 릴레이션(원자적 속성으로 구성된 릴레이션)을 중첩된 릴레이션으로 변환중첩(unnesting)의 예
title author_set publisher keyword_se t
{name
…} (pub_name,pub_branch) Compilers {Smith,
Jones} (McGraw-Hill,
New York) {parsing, analysis}
Networks {Jones,
Frick} (Oxford,
London) {Internet, Web}
[중첩된 릴레이션]
title author publisher pub_branch keyword Compilers Smith McGraw-Hill New York parsing Compilers Jones McGraw-Hil New York parsing Compilers Smith McGraw-Hill New York analysis Compilers Jones McGraw-Hil New York analysis Networks Jones Oxford London Internet Networks Frick Oxford London Internet
Networks Jones Oxford London Web
Networks Frick Oxford London Web
[1NF 릴레이션]
select
title, collect(author) as author_set,
Publisher(pub_name,pub_branch) as publisher, collect(keyword) as keyword_set
from flat_book
group by title, publisher
SQL의 객체 참조형(Reference Type)
참조형(Reference Type)
테이블의 각 투플을 내부적으로 유일하게 식별 할 수 있는 식별자를 저장할 수 있는 REF 데이터 타입
이 참조 타입의 값은 객체 지향 시스템의 객체 식별자(OID)와 같이 각 투플을 참조할 수 있게 함
따라서 전체 데이타베이스에서 유일한 하나의 투플을 식별하기 위해 사용되며 투플 사 이의 관계를 표현하는데도 이용됨
구조형(Structured Type)의 속성은 다른 구조형의 인스턴스에 대한 참조가 될 수 있다.
구조형으로 선언된 테이블만 참조할 수 있다.
참조되는 테이블은 튜플의 식별자를 저장하는 속성을 가져야한다.
21/24
SQL의 객체 참조형(Reference Type)
참조형 선언 예
참조형 필드를 갖는 구조형 선언 및 테이블 생성
create type Department
(name varchar(20),
head
ref(Person) scopepeople
)create table departments of Department
create type Department ( name varchar(20), head ref(Person) )
create table departments of Department
(head with options scope people)
참조형 (Reference Type) 값의 초기화
참조형 필드를 갖는 튜플 생성
① ‘널’ 참조를 갖도록 튜플생성
insert into departments values (‘CS’, null)
② 생성된 튜플의 참조형 필드에 값 저장
update departments
set head = (select p.person_id from people as p where name=‘John’) where name=‘CS’
people 테이블의 식별자
23/24
SQL의 객체 식별자(Object-Identity)
다른 테이블에서 참조할 수 있도록 식별자 생성
자기 참조 속성(self-referential attr.)
참조되는 테이블이 튜플의 식별자를 저장하는 속성
system generated
데이터베이스가 자동으로 생성해주는 식별자
create table people of Person
ref is person_id system generated
user generated
사용자가 생성할 수 있는 식별자
create type Person
(
name
varchar(20),address
varchar(20))ref using varchar(20)
create table people of Person
ref is person_id user generated
자기 참조 속성
(self-referential attr.)
참조 속성 타입
SQL의 객체 식별자(Object-Identity) - Cont’d
자기 참조 속성이 정의된 테이블에 튜플생성
user generated 참조는 튜플생성 시에 반드시 식별자 값 제공 (e.g. insert into people (person_id, name, address) values
(
‘01284567’
, ‘John’, ’23 Coyote Run’) 참조속성이 정의된 테이블의 하위테이블
상속관계의 테이블간에는 동일한 식별자를 가질 수 없음.
주 키(primary key) 를 식별자로 사용
create type Person
(
name varchar(20) primary key, address varchar(20))
ref from( name
)create table people of Person ref is person_id derived
식별자 값
25/24
경로식 (path expression)
경로식(path expression)
참조 대상 튜플에 대한 역참조 기능
예)
select head->name, head->address from departments
or
select deref(head).name from departments
Department Schema name
head
Person Schema name
address
Ident.
O-R 특징 구현
복합자료형(e.g. 구조형, 배열 등..)을 관계형 데이터베이스의 형 시스템으로 변환
다중집합속성(객체-관계형모델) → 다중 값 속성(관계형모델)
구조형(객체-관계형모델) → 복합 속성(관계형모델)
테이블상속(객체-관계형모델) → ISA 계층구조(관계형모델)
하위 테이블의 저장 방법 1
주 키(primary key)와 지역적 속성들만 저장
상속받은 속성들(주 키 제외)은 상위테이블과 조인연산을 통해 구함
하위 테이블의 저장 방법 2
각 테이블마다 상속받은 속성과 지역적 속성을 모두 저장
튜플 삽입시 해당 튜플은 삽입 대상 테이블에만 저장, 추론을 통해 상위 테이블들에 해당 튜플의 존재가 전달됨.
27/24
RDBMS, OODBMS, ORDBMS
항목
관계형 (Relational)
DBMS
객체 -지향형 (Object-Oriented)
DBMS
객체 -관계형 (Object-Relational)
DBMS
저장내용
데이터, 프로시져, … 객체(데이터+메소드), … 데이터, 프로시져, 메소드, 함수, …자료모델
단순자료형 단순자료형,복합자료형
단순자료형, 복합자료형
표준안
SQL2 ODMG-2.0 SQL3주요제품
Oracle 7.x(Oracle), System 10/11(Sybase),Dynamic Server(Infomix),
DB/2(IBM),
OpenIngres(Computer Associates)
Oracle 8.x(Oracle), Universal Server(Informix),
Universal Database(IBM), UniSQL/X(UniSQL),
OSMOS(Unisys), Postgres(UC Berkley) Jasmine(Computer
Associates),
Gemstone(Gemstone), O2(O2),
ObjectStore(Object Design),
Objectivity/DB(Objectivity), Versant ODBMS(Versant)