bucket은 entry를 포함하는 storage space
Hash function은 bucket을 결정하는 함수
search-key에 대한 bucket의 address를 결정
다른 search key도 같은 bucket에 mapping될 수 있음
전체 bucket은 sequential하게 search되어야 함
Hash index에서 bucket은 record에 대한 pointer를 entry로 저장
Hash file organization에서 bucket은 record 자체를 저장
bucket 개수는 고정
bucket은 순서대로 할당됨, 절대 할당이 풀리지 않음

Bucket overflow는 다음과 같은 이유로 발생할 수 있음
Skew는 다음과 같은 이유로 발생할 수 있음
bucket overflow가 발생할 확률을 줄일 수는 있지만, 완전히 제거하지는 못함
overflow는 보통 overflow bucket을 통해 관리됨
Overflow chaining
Hash file organization 예시

dept_name을 key로 사용
dept_name의 binary representation의 합 modulo 10을 hash function으로 사용
uniform distribution이 되지 않았음
static hasing에서, hash function은 key를 고정된 개수의 bucket address에 매핑함
database는 시간에 따라 커지거나 작아짐
해결책: Rehashing
더 나은 해결책: bucket의 수를 유동적으로 설정 -> dynamic hashing
Linear Hashing
Extendible Hashing
Basic idea behind Dynamic Hashing
postfix or prefix hash key 사용
postfix의 길이가 i bit, 라고 하자
다수의 directory entry가 같은 bucket을 point할 수 있음
그러므로 실제 bucket의 수는 보다 적음
General extendible hash structure

Extendible Hashing의 동작
Directory size가 4이면, 각 entry는 2bit가 필요
key K에 대한 bucket을 찾으려면, global depth 사용
global depth = least significant bits of h(K)
if h(K) = 5 = 0101, global depth = 2이면, bucket은 01로 point됨
if h(K) = 7 = 0111, bucket은 11로 point됨

Bucket Split
Global depth가 local depth보다 큰 경우 (G > L)
새 bucket을 할당하고 L = L + 1
directory에 새 bucket update
overflow된 bucket에서 새 bucket으로 record들 옮김
여전히 bucket이 가득 차 있으면 더 split함


Bucket split -> Directory Doubling
G == L인경우
G를 증가시켜 directory의 크기를 2배로 키움
각 entry를 같은 bucket을 가르키는 두 entry로 만듦
이제 G > L이 됐으므로 이전 상황과 똑같아짐


Extendible hashing의 장점
Extendible hashing의 단점
Linear hashing은 대체 mechanism
directory를 사용하지 않고 long overflow chain을 해결하기 위한 dynamic hashing 기법
bucket이 overflow되면 next pointer의 bucket을 split함 그리고 next pointer는 다음 bucket으로 이동 (next pointer는 insert하는 bucket과 상관없이 bucket을 순서대로 쭉 순회)
Algorithm proceeds in rounds (next pointer가 몇바퀴 돌았냐)
current round number is level
처음 상태의 bucket 수 = N
bucket의 수는
0부터 Next-1까지의 bucket들은 split된 상태
모든 bucket이 분할되면 next pointer는 분할된 새 bucket으로 넘어가지 않고 0으로 돌아와서 다시 순회 시작
Insert
들어갈 bucket을 찾음, 자리 있으면 그냥 넣음
없으면

Search
entry r의 bucket을 찾기 위해서는
bucket이 아직 이번 round에 split되지 않음
=> 인 경우 단순히 bucket에 가서 찾으면 됨
bucket이 이미 split 됨
=> 이나 두 곳을 찾아야 함
아니면 을 찾으면 됨

Cost of periodic re-organization: ordered > hashing
빈번한 삽입/삭제가 일어나는 경우 re-organization cost를 고려해야 함
Hashing은 average access time이 작지만 worst case access time이 큼
Ordering index는 차이가 적음
query에 따른 적합성
query에 여러 index를 사용하는 경우
예시)
select ID
from instructor
where dept_name = "Finance" and salary = 80000
Bitmap index는 여러 key를 참조하는 query에 효율적임
Bitmap은 단순 bit의 나열
Bitmap index는 attribute의 각 value에 대한 bitmap을 가짐

AND, OR 연산으로 query 처리
예시) income level이 L1인 male => 10100 AND 10010 = 10000 즉 0번 record만 해당됨