14. Indexing
Indexing: ์ํ๋ ๋ฐ์ดํฐ์ ๋ํ ์ ๊ทผ ์๋๋ฅผ ๋์ด๋ ๋ฐ ์ฌ์ฉ๋๋ ๋ฉ์ปค๋์ฆ
Search Key: ํ์ผ์์ ๋ ์ฝ๋๋ฅผ ์ฐพ๋ ๋ฐ ์ฌ์ฉ๋๋ ์์ฑ ๋๋ ์์ฑ ์งํฉ
์ธ๋ฑ์ค ํ์ผ์ search-key์ pointer(s)() ํํ์ ๋ ์ฝ๋๋ผ ๋ถ๋ฆผ)๋ก ๊ตฌ์ฑ
search-key pointer(s) - ์ธ๋ฑ์ค ํ์ผ์ ์ผ๋ฐ์ ์ผ๋ก ์๋ณธ ๋ฐ์ดํฐ ํ์ผ๋ณด๋ค ํจ์ฌ ์์.
๋ ๊ฐ์ง ๊ธฐ๋ณธ ์ธ๋ฑ์ค ์ข ๋ฅ
- Ordered indices: Search key๊ฐ ์ ๋ ฌ๋ ์์๋ก ์ ์ฅ
- Hash indices: Search key๊ฐ ํด์ ํจ์๋ฅผ ์ฌ์ฉํ์ฌ "buckets"์ ๊ท ์ผํ๊ฒ ๋ถ์ฐ
Index evaluation metrics
- ํจ์จ์ ์ผ๋ก ์ง์๋๋ access types
- Point queries: Search key์ ๋ํด ์ง์ ๋ ๊ฐ์ ๊ฐ๋ ๋ ์ฝ๋
- Range queries: Search key๊ฐ์ด ์ง์ ๋ ๋ฒ์ ๋ด์ ์๋ ๋ ์ฝ๋
- ๋ฐ์ดํฐ ๋ ์ฝ๋์ ๋ํ access/insertion/deletion times
- ๊ณต๊ฐ overhead
- ํจ์จ์ ์ผ๋ก ์ง์๋๋ access types
Ordered Indices
- Ordered index: ์ธ๋ฑ์ค ์ํธ๋ฆฌ์ search key๊ฐ์ ๋ฐ๋ผ ์ ๋ ฌ๋์ด ์ ์ฅ
- Clustering index
- Sequentially ordered data file์์, search key๊ฐ ๋ฐ์ดํฐ ํ์ผ์ ์์ฐจ์ ์์๋ ์ ์ํ๋ ์ธ๋ฑ์ค
- Primary index๋ผ๊ณ ๋ ํจ.
- ๊ธฐ๋ณธ ์ธ๋ฑ์ค์ search key๋ ์ผ๋ฐ์ ์ผ๋ก primary key์ด์ง๋ง, ํ์๋ ์๋
- 2์ฐจ ์ธ๋ฑ์ค
- Search key๊ฐ ๋ฐ์ดํฐ ํ์ผ์ ์์ฐจ์ ์์์ ๋ค๋ฅธ ์์๋ฅผ ์ง์ ํ๋ ์ธ๋ฑ์ค
- Nonclustering index๋ผ๊ณ ๋ ํจ.
- Index-sequential file
- Search key๋ฅผ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ๋ sequential data file์, search key์ ๋ํ clustering ์ธ๋ฑ์ค๊ฐ ์๋ ํ์ผ
Dense Index
- Dense index: ๋ฐ์ดํฐ ํ์ผ์ ๋ชจ๋ search-key๊ฐ์ ๋ํด index entry๊ฐ ๋ํ๋จ

Sparse Index

- Sparse Index: ์ผ๋ถ search-key๊ฐ์ ๋ํด์๋ง ์ธ๋ฑ์ค ์ํธ๋ฆฌ๋ฅผ ํฌํจ.
- ๋ ์ฝ๋๊ฐ search key๋ฅผ ๊ธฐ์ค์ผ๋ก ์์ฐจ์ ์ผ๋ก ์ ๋ ฌ๋์ด ์์ ๋ ์ ์ฉ ๊ฐ๋ฅ
- Search-key๊ฐ ๋ฅผ ๊ฐ์ง ๋ ์ฝ๋๋ฅผ ์ฐพ์ผ๋ ค๋ฉด
- ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ search-key๊ฐ ์ค ๊ฐ์ฅ ํฐ ๊ฐ์ ๊ฐ์ง index entry๋ฅผ ์ฐพ์.
- ํด๋น index ๋ ์ฝ๋๊ฐ ๊ฐ๋ฆฌํค๋ ๋ ์ฝ๋์์๋ถํฐ ํ์ผ ์์ฐจ ๊ฒ์
- Dense indices์ ๋น๊ต
- ๋ฐ์ดํฐ ๋ ์ฝ๋์ ์ฝ์ /์ญ์ ์ ๋ํด less space and less maintenance overhead
- ์ผ๋ฐ์ ์ผ๋ก ๋ ์ฝ๋๋ฅผ ์ฐพ๋ ๋ฐ dense index๋ณด๋ค ๋๋ฆผ.
- Access time๊ณผ space overhead ์ฌ์ด์ trade-off ์กด์ฌ
- Good compromise
- Clustering ์ธ๋ฑ์ค์ ๊ฒฝ์ฐ: ํ์ผ์ ๋ชจ๋ block์ ๋ํด index entry๋ฅผ ๊ฐ์ง sparse index. ํด๋น block์์ least search-key๊ฐ์ ํด๋น
- ์ฐธ๊ณ : Query processing์ ์ฃผ์ ๋น์ฉ์ block I/O time
- ๋ฉ๋ชจ๋ฆฌ ๋ด ๋ธ๋ก scanning ์๊ฐ์ ์ฌ์ํจ.
- ์ด ๋ฐฉ์์ dense index์ ๋์ผํ ์์ block I/O๋ฅผ ๊ฐ์ง๋ฉด์๋ space overhead๊ฐ ํจ์ฌ ์ ์.
- Clustering ์ธ๋ฑ์ค์ ๊ฒฝ์ฐ: ํ์ผ์ ๋ชจ๋ block์ ๋ํด index entry๋ฅผ ๊ฐ์ง sparse index. ํด๋น block์์ least search-key๊ฐ์ ํด๋น

Multilevel Index
- ์ธ๋ฑ์ค๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ๋ง์ง ์์ผ๋ฉด, access๊ฐ expensive
- ํด๊ฒฐ์ฑ
: Multilevel Index
- ๋์คํฌ์ ๋ณด๊ด๋ ์ธ๋ฑ์ค๋ฅผ sequential file๋ก ์ทจ๊ธํ๊ณ ๊ทธ ์์ sparse ์ธ๋ฑ์ค๋ฅผ ๊ตฌ์ถ
- Outer index: Basic ์ธ๋ฑ์ค์ sparse index
- Inner index: Basic ์ธ๋ฑ์ค ํ์ผ
- Outer index์กฐ์ฐจ ๋๋ฌด ์ปค์ ๋ฉ์ธ ๋ฉ๋ชจ๋ฆฌ์ ๋ง์ง ์์ผ๋ฉด, ๋ ๋ค๋ฅธ level์ index ์์ฑ ๊ฐ๋ฅ
- ๋ชจ๋ level์ ์ธ๋ฑ์ค๋ ํ์ผ์์์ ์ฝ์ ๋๋ ์ญ์ ์์ ์ ๋ฐ์ดํธ๋์ด์ผ ํจ.

Index Update: Insertion

- Index๋ database modification์ overhead๋ฅผ ๋ถ๊ณผ
- ๋ ์ฝ๋๊ฐ ์ฝ์ ๋๋ ์ญ์ ๋ ๋, ๊ด๊ณํ์ ๋ชจ๋ ์ธ๋ฑ์ค๊ฐ ๊ฐฑ์ ๋์ด์ผ ํจ.
- ๋ ์ฝ๋๊ฐ ๊ฐฑ์ ๋ ๋, ๊ฐฑ์ ๋ ์์ฑ์ ๋ํ ๋ชจ๋ ์ธ๋ฑ์ค๊ฐ ๊ฐฑ์ ๋์ด์ผ ํจ.
- Index update upon insertion: 1) Dense indices
- ์ฝ์ ๋๋ ๋ ์ฝ๋์ search-key๊ฐ์ ์ฌ์ฉํ์ฌ lookup ์ํ
- Search-key๊ฐ์ด ์ธ๋ฑ์ค์ ๋ํ๋์ง ์์ผ๋ฉด, insert
- Search-key๊ฐ์ด ์ธ๋ฑ์ค์ ๋ํ๋๋ฉด
- ์ธ๋ฑ์ค ์ํธ๋ฆฌ๊ฐ ๋์ผํ search-key๊ฐ์ ๊ฐ์ง ๋ชจ๋ ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ๋ฅผ ์ ์ฅํ๋ ๊ฒฝ์ฐ, ์๋ก์ด ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ๋ฅผ ์ถ๊ฐ
- ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ, ์ธ๋ฑ์ค ์ํธ๋ฆฌ๊ฐ ํด๋น search-key๊ฐ์ ๊ฐ์ง ์ฒซ ๋ฒ์งธ ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ๋ง ์ ์ฅ. ์๋ก์ด ๋ ์ฝ๋๋ฅผ ๋์ผํ search-key๊ฐ์ ๊ฐ์ง ๋ค๋ฅธ ๋ ์ฝ๋๋ค ๋ค์ ๋ฐฐ์น
- ์ธ๋ฑ์ค๋ sequential files๋ก ์ ์ง ๊ด๋ฆฌ๋จ โ ์๋ก์ด ์ํธ๋ฆฌ๋ฅผ ์ํ space๋ฅผ ์์ฑํด์ผ ํ๋ฉฐ, overflow blocks์ด ํ์ํ ์ ์์.
- Index update upon insertion: 2) Sparse indices
- ์ฝ์ ๋๋ ๋ ์ฝ๋์ search-key๊ฐ์ ์ฌ์ฉํ์ฌ lookup ์ํ
- ์ธ๋ฑ์ค๊ฐ ํ์ผ์ ๊ฐ ๋ธ๋ก์ ๋ํ ์ํธ๋ฆฌ๋ฅผ ์ ์ฅํ๋ ๊ฒฝ์ฐ, ์ธ๋ฑ์ค๋ฅผ ์์ ํ ํ์๊ฐ ์์.
- ์๋ก์ด block์ด ์์ฑ๋๋ ๊ฒฝ์ฐ: ์๋ก์ด ๋ธ๋ก์ ์ฒซ ๋ฒ์งธ search-key๊ฐ์ด ์ธ๋ฑ์ค์ ์ฝ์ ๋จ.
- ์๋ก์ด ๋ ์ฝ๋๊ฐ ๋ธ๋ก์์ ๊ฐ์ฅ ์์ search-key๊ฐ์ ๊ฐ์ง๋ ๊ฒฝ์ฐ: ๋ธ๋ก์ ๊ฐ๋ฆฌํค๋ ์ธ๋ฑ์ค ์ํธ๋ฆฌ๋ฅผ ์ ๋ฐ์ดํธ

Index Update: Deletion

- Index update upon deletion: 1) Dense indices
- (Case 1) ์ญ์ ๋ ๋ ์ฝ๋๊ฐ ํด๋น search-key๊ฐ์ ๊ฐ์ง ํ์ผ ๋ด ์ ์ผํ ๋ ์ฝ๋์ธ ๊ฒฝ์ฐ, ์ธ๋ฑ์ค์์๋ search-key๊ฐ ์ญ์ ๋จ.
- ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ
- ์ธ๋ฑ์ค ์ํธ๋ฆฌ๊ฐ ๋์ผํ search-key๊ฐ์ ๊ฐ์ง ๋ชจ๋ ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ๋ฅผ ์ ์ฅํ๋ ๊ฒฝ์ฐ, ์ญ์ ๋ ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ ์ญ์
- ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ, ์ธ๋ฑ์ค ์ํธ๋ฆฌ๊ฐ ํด๋น search-key๊ฐ์ ๊ฐ์ง ์ฒซ ๋ฒ์งธ ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ๋ง ์ ์ฅ
- (Case 2) ์ญ์ ๋ ๋ ์ฝ๋๊ฐ ํด๋น search-key๊ฐ์ ๊ฐ์ง ์ฒซ ๋ฒ์งธ ๋ ์ฝ๋์ธ ๊ฒฝ์ฐ, ์ธ๋ฑ์ค ์ํธ๋ฆฌ๋ฅผ ์ ๋ฐ์ดํธํ์ฌ ๋ค์ ๋ ์ฝ๋๋ฅผ ๊ฐ๋ฆฌํค๋๋ก ํจ.
- (Case 3) ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ, ์ธ๋ฑ์ค ๊ฐฑ์ ์ required๋์ง ์์.
- Index update upon deletion: 2) Sparse indices
- (Case 1) ์ธ๋ฑ์ค๊ฐ ์ญ์ ๋ ๋ ์ฝ๋์ search-key๊ฐ๊ณผ ์ผ์นํ๋ index entry๋ฅผ ํฌํจํ์ง ์๋ ๊ฒฝ์ฐ, ์๋ฌด๊ฒ๋ ํ์ง ์์.
- ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ
- (Case 2) ์ญ์ ๋ ๋ ์ฝ๋๊ฐ ํด๋น search-key๋ฅผ ๊ฐ์ง ์ ์ผํ ๋ ์ฝ๋์ธ ๊ฒฝ์ฐ, index entry๋ฅผ ํ์ผ์์ ๋ค์ search-key๊ฐ์ผ๋ก ๋์ฒด
- ๋ค์ search-key๊ฐ์ด ์ด๋ฏธ index entry๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ฉด, ํด๋น ์ํธ๋ฆฌ๋ ์ญ์ ๋จ. -) ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ, search-key๊ฐ์ ๋ํ index entry๊ฐ ์ญ์ ๋ ๋ ์ฝ๋๋ฅผ ๊ฐ๋ฆฌํค๋ ๊ฒฝ์ฐ, ์ธ๋ฑ์ค ์ํธ๋ฆฌ๋ฅผ ์ ๋ฐ์ดํธํ์ฌ ๋์ผํ search-key๊ฐ์ ๊ฐ์ง ๋ค์ ๋ ์ฝ๋๋ฅผ ๊ฐ๋ฆฌํค๋๋ก ํจ.
- (Case 2) ์ญ์ ๋ ๋ ์ฝ๋๊ฐ ํด๋น search-key๋ฅผ ๊ฐ์ง ์ ์ผํ ๋ ์ฝ๋์ธ ๊ฒฝ์ฐ, index entry๋ฅผ ํ์ผ์์ ๋ค์ search-key๊ฐ์ผ๋ก ๋์ฒด
2์ฐจ ์ธ๋ฑ์ค: An example
instructorํ์ผ์salaryํ๋์ ๋ํ 2์ฐจ ์ธ๋ฑ์ค
- ์ธ๋ฑ์ค ๋ ์ฝ๋๋ ํด๋น ํน์ search-key๊ฐ์ ๊ฐ์ง ๋ชจ๋ ์ค์ ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ๋ฅผ ํฌํจํ๋ bucket์ ๊ฐ๋ฆฌํด
- 2์ฐจ ์ธ๋ฑ์ค๋ denseํด์ผ ํจ.
- Index ์ ๋ฐ์ดํธ ๊ณผ์ ์ clustering ์ธ๋ฑ์ค์ dense index ๊ฒฝ์ฐ์ ๋์ผ
- 2์ฐจ(nonclustering) ์ธ๋ฑ์ค๋ฅผ ์ฌ์ฉํ ์์ฐจ์ ์ค์บ HDD์์ expensive
- ๊ฐ ๋ ์ฝ๋ ์ ๊ทผ ์ ๋์คํฌ์์ ์๋ก์ด block์ ๊ฐ์ ธ์์ผ ํ ์ ์์.
Indices on Multiple Keys
- Composite search key
- ๋ ๊ฐ ์ด์์ ์์ฑ์ ํฌํจํ๋ search key
- ์:
instructorrelation์ ์์ฑ(name, ID)์ ๋ํ ์ธ๋ฑ์ค - ๊ฐ์ ์ฌ์ ์์ผ๋ก(lexicographically) ์ ๋ ฌ๋จ.
- E.g. ๋ฐ
name๋ง์ผ๋ก queryํ๊ฑฐ๋,(name, ID)๋ก query ๊ฐ๋ฅ
B -Tree(and B-Tree) Index Files
B -Tree Index Files
- Index-sequential file organization์ ๋จ์
- ํ์ผ์ด ์ปค์ง์ ๋ฐ๋ผ overflow blocks์ด ๋ง์ด ์์ฑ๋์ด ์ฑ๋ฅ ์ ํ
- ๋น์ฉ์ด ๋ง์ด ๋ค๊ณ ์ฃผ๊ธฐ์ ์ธ ์ ์ฒด ํ์ผ reorganization ํ์
- B -tree index ๊ตฌ์กฐ์ ์ด์
- ์ฝ์ /์ญ์ ์ ์๊ณ localํ ๋ณํ๋ง์ผ๋ก ์๋์ผ๋ก self-reorganizes
- ์ฑ๋ฅ ์ ์ง๋ฅผ ์ํด ์ ์ฒด ํ์ผ์ reorganization์ด ํ์ํ์ง ์์.
- B -trees์ (์ฌ์ํ) ๋จ์
- ์ถ๊ฐ์ ์ธ ์ฝ์ /์ญ์ overhead, ๊ณต๊ฐ overhead
- B -trees์ ์ฅ์ ์ด ๋จ์ ๋ณด๋ค ํฌ๊ธฐ ๋๋ฌธ์ ๋๋ฆฌ ์ฌ์ฉ๋จ.
- B -tree๋ ๋ค์ ์์ฑ์ ๋ง์กฑํ๋ rooted tree
- Root์์ leaf๊น์ง์ ๋ชจ๋ ๊ฒฝ๋ก๋ ๊ธธ์ด๊ฐ ๊ฐ์: Balanced tree
- Root๋ leaf๊ฐ ์๋ ๊ฐ node๋ ์ ์ฌ์ด์ children์ ๊ฐ์ง.
- ์ต์ , ์ต๋ ๊ฐ์ children(pointers)
- Leaf node๋ ์ ์ฌ์ด์ ๊ฐ์ ๊ฐ์ง.
- ์ต์ , ์ต๋ ์ ๊ฐ(not pointers)
- ํน์ํ ๊ฒฝ์ฐ๋ค
- Root๊ฐ leaf๊ฐ ์๋ ๊ฒฝ์ฐ, ์ต์ 2๊ฐ์ children์ ๊ฐ์ง.
- Root๊ฐ leaf์ธ ๊ฒฝ์ฐ, 0๊ณผ ์ฌ์ด์ ๊ฐ์ ๊ฐ์ง ์ ์์.
- B -tree๋ multilevel ์ธ๋ฑ์ค์ด์ง๋ง, multilevel index-sequential ํ์ผ๊ณผ๋ ๋ค๋ฅธ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง.
B -Tree Node Structure
- Typical node
... - ๋ search-key๊ฐ
- ๋ children ๋๋ records/buckets of ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ
- ์ฐธ๊ณ : ์ต๋ ๊ฐ์ pointers์ ๊ฐ์ key๊ฐ์ด ์์ ์ ์์.
- ๋
ธ๋ ๋ด์ search-keys๋ ์ ๋ ฌ๋จ.
- (์ฒ์์ ์ค๋ณต๋ keys๊ฐ ์๋ค๊ณ ๊ฐ์ , ์ดํ์ ์ค๋ณต์ ๋ค๋ฃฐ ๊ฒ)
Leaf Nodes in B -Trees
- Leaf node์ ์์ฑ
- ์ ๋ํด, ํฌ์ธํฐ ๋ search-key๊ฐ ๋ฅผ ๊ฐ์ง ํ์ผ ๋ ์ฝ๋๋ฅผ ๊ฐ๋ฆฌํด
- ์ ๊ฐ leaf nodes์ด๊ณ ์ธ ๊ฒฝ์ฐ, ์ search-key๊ฐ์ ์ search-key๊ฐ๋ณด๋ค ์์.
- ์ search-key ์์๋ก ๋ค์ leaf node๋ฅผ ๊ฐ๋ฆฌํด
- ์์ฐจ ์ฒ๋ฆฌ๋ฅผ ์ ์ํ๊ฒ ํ๊ธฐ ์ํด ๋ชจ๋ leaf nodes๋ฅผ search-key ์์๋ก chain together
- B -tree ์ธ๋ฑ์ค๊ฐ dense index๋ก ์ฌ์ฉ๋๋ ๊ฒฝ์ฐ(์ ํ์ ์ธ ๊ฒฝ์ฐ, ๋ชจ๋ search-key๊ฐ์ด ์ผ๋ถ leaf node์ ๋ํ๋์ผ ํจ. ๊ทธ๋ฌ๋, non-leaf node์ ๋ํ๋๋ search-key๋ ๋ ์ฝ๋ ์ญ์ ๋ก ์ธํด leaf node์ ๋ํ๋์ง ์์ ์ ์์.
Non-Leaf Nodes in B -Trees
- Non-leaf nodes๋ leaf nodes์ ๋ํ multi-level sparse ์ธ๋ฑ์ค๋ฅผ ํ์ฑ
- ๊ฐ์ ํฌ์ธํฐ๋ฅผ ๊ฐ์ง non-leaf node์ ๊ฒฝ์ฐ
- ์ด ๊ฐ๋ฆฌํค๋ subtree์ ๋ชจ๋ search-keys๋ ๋ณด๋ค ์์.
- ์ ๋ํด, ๊ฐ ๊ฐ๋ฆฌํค๋ subtree์ ๋ชจ๋ search-keys๋ ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ ๋ณด๋ค ์์.
- ์ด ๊ฐ๋ฆฌํค๋ subtree์ ๋ชจ๋ search-keys๋ ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์.
- ์ฐธ๊ณ : Non-leaf nodes๋ ๊ทธ๋ค ์ฌ์ด์ ์ค๋ณต๋ search-key๊ฐ์ ๊ฐ์ง์ง ์์.
- ์ผ๋ฐ์ ์ธ ๊ตฌ์กฐ

Example of B -Tree index for instructor (, search key: name)

Example of B -Tree index for instructor ()

- Root๋ ์ต์ 2๊ฐ์ children์ ๊ฐ์ ธ์ผ ํจ.
- Interal nodes๋ 3์์ 6 ์ฌ์ด์ children์ ๊ฐ์ ธ์ผ ํจ. (๊ณผ ์ฌ์ด)
- Leaf nodes๋ 3๊ณผ 5 ์ฌ์ด์ ๊ฐ์ ๊ฐ์ ธ์ผ ํจ. (๊ณผ ์ฌ์ด)
- ํธ๋ฆฌ์ ๋์ด๊ฐ ์ด์ ()์ ๋นํด ๋ฎ์์ก์์ ์ฃผ๋ชฉํ ๊ฒ
Observations about B -trees
- Node ๊ฐ์ ์ฐ๊ฒฐ์ด ํฌ์ธํฐ๋ก ์ด๋ฃจ์ด์ง๊ธฐ ๋๋ฌธ์, "๋ ผ๋ฆฌ์ ์ผ๋ก" ๊ฐ๊น์ด blocks์ด "๋ฌผ๋ฆฌ์ ์ผ๋ก" ๊ฐ๊น์ธ ํ์๋ ์์.
- B -tree์ non-leaf levels์ hierarchy of sparse ์ธ๋ฑ์ค๋ฅผ ํ์ฑ
- B -tree๋ ์๋์ ์ผ๋ก ์์ ์์ ๊ณ์ธต์ ํฌํจ.
- Root ์๋ ๋ ๋ฒจ์ ์ต์ ์ ๊ฐ
- ๋ค์ ๋ ๋ฒจ์ ์ต์ ์ ๊ฐ
- ํ์ผ์ ๊ฐ์ search-key๊ฐ์ด ์๋ ๊ฒฝ์ฐ, tree ๋์ด๋ ๋ฅผ ์ด๊ณผํ์ง ์์.
- ๋ฐ๋ผ์ search๊ฐ ํจ์จ์ ์ผ๋ก ์ํ๋ ์ ์์.
- ์ธ๋ฑ์ค๊ฐ logarithmic time์ผ๋ก ์ฌ๊ตฌ์ฑ๋ ์ ์์ผ๋ฏ๋ก, main file์ ๋ํ ์ฝ์ /์ญ์ ๋ํ ํจ์จ์ ์ผ๋ก ์ฒ๋ฆฌ๋ ์ ์์.
Queries on B -Trees: Point Query

function find(v)
1. Set C = root node
2. while(C is not a leaf node) begin
Let i = smallest number s.t. v โค C.Ki
if there is no such number i then
/* v is larger than every key in C */
Set C = the node pointed by the last non-null ํฌ์ธํฐ in C
else if(v = C.Ki ) Set C = C.Pi +1
else set C = C.Pi /* v < C.Ki */
end
/* Now, C is a leaf node */
3. if for some i, Ki = v then return C.Pi
4. else return null /* no record with search-key๊ฐ v exists */

Queries on B -Trees: Range Query
- Range queries: ์ฃผ์ด์ง ๋ฒ์ ๋ด์ search key๊ฐ์ ๊ฐ์ง ๋ชจ๋ ๋ ์ฝ๋๋ฅผ ์ฐพ์.
function findRange(lb, ub)๋ ์ธ search key๊ฐ ๋ฅผ ๊ฐ์ง ๋ชจ๋ ๋ ์ฝ๋ ์งํฉ์ ๋ฐํ- $C=lb $๊ฐ ๋ํ๋ leaf node๋ฅผ ์ฐพ์(
find(v)์์ ๋ฅผ ์ฐพ๋ ๊ฒ๊ณผ ๋์ผ). - ์์ ์ธ ์ต์๊ฐ
while()
- ๋ฅผ results์ add
- (์ ๋ ์ฝ๋๊ฐ ๋ ์๋ค๋ฉด) ๋๋ ํ๋ฉฐ ๋ค์ leaf node๋ก ์ด๋
- $C=lb $๊ฐ ๋ํ๋ leaf node๋ฅผ ์ฐพ์(
- ์ค์ ๊ตฌํ์ ์ผ๋ฐ์ ์ผ๋ก
next()ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ผ์นํ๋ ๋ ์ฝ๋๋ฅผ ํ ๋ฒ์ ๊ฐ์ ธ์ค๋ iterator ์ธํฐํ์ด์ค๋ฅผ ์ ๊ณต
Queries on B -Trees: Cost Analysis
- ํ์ผ์ ๊ฐ์ search-key๊ฐ์ด ์๋ ๊ฒฝ์ฐ, ํธ๋ฆฌ์ ๋์ด๋ ๋ฅผ ์ด๊ณผํ์ง ์์.
- Node๋ ์ผ๋ฐ์ ์ผ๋ก disk block๊ณผ ๊ฐ์ ํฌ๊ธฐ, ์ผ๋ฐ์ ์ผ๋ก 4KB
- ์ ์ผ๋ฐ์ ์ผ๋ก ์ฝ 100
- Search-key size๊ฐ 12๋ฐ์ดํธ์ธ ๊ฒฝ์ฐ, ์ ์ฝ 200
- 100๋ง๊ฐ์ search key๊ฐ ๋ฐ ์ธ ๊ฒฝ์ฐ
- Root์์ leaf๊น์ง์ index lookup์ ๋ํด ์ต๋ nodes ์ ๊ทผ๋จ.
- 100๋ง๊ฐ์ search key๊ฐ์ ๊ฐ์ง balanced binary tree์ ๋น๊ต: ์กฐํ ์ ์ฝ 20 nodes ์ ๊ทผ๋จ.
- ๋ชจ๋ node access๋ disk I/O๋ฅผ ํ์๋ก ํ ์ ์์ผ๋ฉฐ, ์ฝ 20ms์ ๋น์ฉ์ด ๋ค๊ธฐ ๋๋ฌธ์ ์์ ์ฐจ์ด๋ ์ ์๋ฏธํจ.
- ์ธ๋ฑ์ค๋ฅผ traverseํ ํ, ์ผ์นํ๋ ๋ ์ฝ๋๋ฅผ fetchํ๊ธฐ ์ํด ํ ๋ฒ์ random I/O๊ฐ ๋ ํ์
Non-Unique Keys
- Search key ๊ฐ not unique, ๋์ uniqueํ composite key ์ ๋ํ ์ธ๋ฑ์ค๋ฅผ ์์ฑ
- ๋ primary key, record ID ๋๋ uniqueness๋ฅผ ๋ณด์ฅํ๋ ๊ธฐํ ์์ฑ์ผ ์ ์์.
- ์ ๋ํ search๋ composite key์ ๋ํ range search์ผ๋ก ๊ตฌํ ๊ฐ๋ฅ
- Range to
- ๊ทธ๋ฌ๋ ์ถ๊ฐ์ ์ธ I/O ์ฐ์ฐ์ด ์ค์ ๋ ์ฝ๋๋ฅผ fetchํ๋ ๋ฐ ํ์
- ์ธ๋ฑ์ค๊ฐ clustering์ธ ๊ฒฝ์ฐ, ๋ชจ๋ access๋ sequential
- ์ธ๋ฑ์ค๊ฐ non-clustering์ธ ๊ฒฝ์ฐ, ๊ฐ ๋ ์ฝ๋ access๋ I/O ์ฐ์ฐ์ ํ์๋ก ํ ์ ์์.
Updates on B -Trees: Insertion
- ๋ ์ฝ๋๊ฐ ๋ฐ์ดํฐ ํ์ผ์ ์ด๋ฏธ ์ถ๊ฐ๋์๋ค๊ณ ๊ฐ์
- ๋ฐ ๋ ๊ฐ๊ฐ record์ ๋ํ ํฌ์ธํฐ ๋ฐ search key๊ฐ
- Search-key๊ฐ์ด ๋ํ๋ leaf node ์ ํ์
- ์ room์ด ์๋ ๊ฒฝ์ฐ, ์์ ์ ์ฝ์
- ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ, node๋ฅผ split ์ํธ๋ฆฌ๋ฅผ ํฌํจํ์ฌ
- Splitting a leaf node
- ์ ๋ ฌ๋ ์์๋ก ๊ฐ์(search-key, pointer) ์์ ์ทจํจ. ์ฒซ ๋ฒ์งธ ๋ฅผ ๊ธฐ์กด์ node ์ ๋ฐฐ์นํ๊ณ , ๋๋จธ์ง๋ฅผ ์ node ์ ๋ฐฐ์น
- ๋ฅผ ์ least key๊ฐ์ด๋ผ๊ณ ํจ. ๋ฅผ split๋๋ node์ parent์ ์ฝ์
- Parent๊ฐ ๊ฐ๋ ์ฐผ๋ค๋ฉด, parent๋ฅผ ๋ถํ ํ๊ณ ๋ถํ ์ ๋ ์๋ก propagate
- Node ๋ถํ ์ full์ด ์๋ node๋ฅผ ์ฐพ์ ๋๊น์ง ์๋ก ์งํ
- ์ต์ ์ ๊ฒฝ์ฐ root node๊ฐ split๋์ด ํธ๋ฆฌ์ ๋์ด๊ฐ 1 ์ฆ๊ฐํ ์ ์์.
- Splitting a non-leaf node: ์ด๋ฏธ full์ธ internal node ์ ๋ฅผ ์ฝ์
ํ ๋
- ์ pointers์ keys๋ฅผ ์ํ ๊ณต๊ฐ์ด ์๋ in-memory area ์ผ๋ก Copy
- ๋ฅผ ์ ์ฝ์
- ์์ ๋ฅผ ๋ค์ node ์ผ๋ก Copy
- ์์ ๋ฅผ ์๋ก ํ ๋น๋ node ์ผ๋ก Copy
- ๋ฅผ ์ parent์ ์ฝ์
- ์ฐธ๊ณ : leaf node๋ฅผ ๋ถํ ํ๋ ๊ฒ๊ณผ๋ ๋ฌ๋ฆฌ, search-key๋ 'copied'๋์ง ์๊ณ parent node๋ก 'moved'๋จ(์ฆ, no duplication!)
Updates on B -Trees: Deletion
- ๋ ์ฝ๋๊ฐ file์์ ์ด๋ฏธ ์ญ์ ๋์๋ค๊ณ ๊ฐ์ . ๋ record์ search key๊ฐ์ด๊ณ , ์ record์ ๋ํ ํฌ์ธํฐ
- ๋ฅผ leaf node์์ ์ ๊ฑฐ
- Leaf node๊ฐ ์ ๊ฑฐ๋ก ์ธํด too few entries()๋ฅผ ๊ฐ์ง๊ณ , node์ ์ํธ๋ฆฌ์ sibling์ ์ํธ๋ฆฌ์ ๋จ์ผ node()์ fitํ๋ค๋ฉด siblings๋ฅผ ๋ณํฉ
- ๋ node์ ๋ชจ๋ ์ํธ๋ฆฌ๋ฅผ left node์ ์ฝ์ ํ๊ณ ๋ค๋ฅธ node๋ฅผ ์ญ์
- ์ญ์ ๋ node๋ฅผ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ๊ฐ ์ธ ๊ฒฝ์ฐ, ์ ๋ฅผ ๊ทธ parent๋ก๋ถํฐ ์ฌ๊ท์ ์ผ๋ก ์ญ์
- ๊ทธ๋ ์ง ์๋ค๋ฉด, node๊ฐ ์ ๊ฑฐ๋ก ์ธํด ๋๋ฌด ์ ์ ์ํธ๋ฆฌ๋ฅผ ๊ฐ์ง๊ณ , node์ ์ํธ๋ฆฌ์ sibling์ ์ํธ๋ฆฌ์ ๋จ์ผ node์ fitํ์ง ์๋ ๊ฒฝ์ฐ, ํฌ์ธํฐ๋ฅผ ์ฌ๋ถ๋ฐฐ
- Node์ sibling ์ฌ์ด์ ํฌ์ธํฐ๋ฅผ ์ฌ๋ถ๋ฐฐํ์ฌ ๋ ๋ค minimum number of entries()๋ณด๋ค ๋ ๊ฐ์ง๋๋ก ํจ.
- Node์ parent์์ ์ผ์นํ๋ search-key๊ฐ์ ์ ๋ฐ์ดํธ
- Node ์ญ์ ๋ ์ญ์ ํ ๊ฐ ์ด์์ ํฌ์ธํฐ๋ฅผ ๊ฐ์ง node๋ฅผ ์ฐพ์ ๋๊น์ง cascade upwards๋ ์ ์์.
- Root node๊ฐ ์ญ์ ํ ๋จ ํ๋์ ํฌ์ธํฐ๋ง ๊ฐ์ง๋ ๊ฒฝ์ฐ, ์ญ์ ๋๊ณ ์ ์ผํ child๊ฐ root๊ฐ ๋จ.
Complexity of B -Tree Updates
- ๋จ์ผ ์ํธ๋ฆฌ์ ์ฝ์ /์ญ์ ๋น์ฉ์ ํธ๋ฆฌ์ ๋์ด์ ๋น๋ก
- ๊ฐ์ ์ํธ๋ฆฌ์ ์ต๋ fanout ์ด ์๋ ๊ฒฝ์ฐ, ์ํธ๋ฆฌ์ ์ฝ์ /์ญ์ ์ worst-case ๋ณต์ก๋๋
- ์ค์ ๋ก I/O ์์
์ ์๋ ๋ ์ ์.
- Internal nodes๋ buffer์ ์๋ ๊ฒฝํฅ์ด ์์.
- Splits/merges๋ ๋๋ฌผ๊ณ , ๋๋ถ๋ถ์ ์ฝ์ /์ญ์ ์์ ์ leaf node์๋ง ์ํฅ์ ์ค.
- ํ๊ท ์ ์ธ node occupancy๋ ์ฝ์
์์์ ์์กด
- Random insertion ์
- Sorted ์์๋ก ์ฝ์ ์
B -Tree File Organization
- B -Tree 'File' Organization
- B -tree file organization์ Leaf nodes๋ ํฌ์ธํฐ ๋์ ๋ ์ฝ๋๋ฅผ ์ ์ฅ
- Insertion/deletion/updates๊ฐ ์์ ๋๋ ๋ฐ์ดํฐ ๋ ์ฝ๋๋ฅผ ํด๋ฌ์คํฐ๋ ์ํ๋ก ์ ์งํ๋ ๋ฐ ๋์ โ ๋ฐ์ดํฐ ํ์ผ degradation ๋ฌธ์ (overflow blocks) ํด๊ฒฐ
- Leaf nodes๋ ์ฌ์ ํ half full ์ํ๊ฐ ์๊ตฌ๋จ.
- ๋ ์ฝ๋๊ฐ ํฌ์ธํฐ๋ณด๋ค ํฌ๊ธฐ ๋๋ฌธ์, leaf node์ ์ ์ฅํ ์ ์๋ ๋ ์ฝ๋์ ์ต๋ ์๋ non-leaf node์ ํฌ์ธํฐ ์๋ณด๋ค ์ ์.
- ์ข์ ๊ณต๊ฐ utilization์ด ์ค์
- ํฉ๋ณ/๋ถํ ๋์ redistribution์ ์ถ๊ฐ์ ์ธ sibling nodes๋ฅผ ํฌํจ์ํด
- Redistribution์ 2 siblings๋ฅผ ํฌํจ์ํค๋ฉด, ๊ฐ node๋ ์ต์ ์ ์ํธ๋ฆฌ๋ฅผ ๊ฐ์ง๊ฒ ๋จ.
- ์ฝ์ /์ญ์ ๋ B -tree index์์ ์ํธ๋ฆฌ์ ์ฝ์ /์ญ์ ์ ๋์ผํ ๋ฐฉ์์ผ๋ก ์ฒ๋ฆฌ
B-Tree Index Files
- B -tree์ ์ ์ฌํ์ง๋ง, B-tree๋ search-key๊ฐ์ด ๋จ ํ ๋ฒ๋ง ๋ํ๋๋๋ก ํ์ฉ.
- Search keys์ redundant storage๋ฅผ ์ ๊ฑฐ
- Non-leaf nodes์ search keys๋ B-tree์ ์ด๋์๋ ๋ํ๋์ง ์์.
- Non-leaf node์ ๊ฐ search key์ ๋ํด ์ถ๊ฐ์ ์ธ ํฌ์ธํฐ field๊ฐ ํฌํจ๋์ด์ผ ํจ.
- Generalized B-tree leaf node

- Non-leaf node: ํฌ์ธํฐ ๋ bucket ๋๋ ํ์ผ ๋ ์ฝ๋ ํฌ์ธํฐ
- B-Tree ์ธ๋ฑ์ค์ ์ด์
- ์ผ์นํ๋ B -Tree๋ณด๋ค ๋ ์ ์ tree nodes๊ฐ ์ฌ์ฉ๋ ์ ์์.
- ๋๋๋ก leaf node์ ๋๋ฌํ๊ธฐ ์ ์ search-key๊ฐ์ ๋ฐ๊ฒฌ.
- B-Tree indices์ ๋จ์
- Small fraction์ search-key๊ฐ๋ง ์ผ์ฐ ๋ฐ๊ฒฌ๋จ.
- Non-leaf nodes๋ ์ฆ๊ฐ, fan-out์ด ๊ฐ์ โ B-Trees๋ ์ผ๋ฐ์ ์ผ๋ก ์ผ์นํ๋ B -Tree๋ณด๋ค ํฐ ๊น์ด๋ฅผ ๊ฐ์ง.
- ์ฝ์ /์ญ์ ๊ฐ B -Trees๋ณด๋ค ๋ ๋ณต์ก
- ๊ตฌํ์ด B -Trees๋ณด๋ค ์ด๋ ค์.
- ์ผ๋ฐ์ ์ผ๋ก, B-Trees์ ์ฅ์ ์ด ๋จ์ ์ ๋ฐ์ด๋์ง ๋ชปํจ.
Other Issues in Indexing
- Record relocation and 2์ฐจ ์ธ๋ฑ์ค
- ๋ ์ฝ๋๊ฐ ์ด๋ํ๋ฉด, ๋ ์ฝ๋ ํฌ์ธํฐ๋ฅผ ์ ์ฅํ๋ ๋ชจ๋ 2์ฐจ ์ธ๋ฑ์ค๊ฐ ์ ๋ฐ์ดํธ๋์ด์ผ ํจ.
- โ B -tree file organizations์์ leaf node splits๊ฐ ๋งค์ฐ expensiveํจ.
- ํด๊ฒฐ์ฑ
: 2์ฐจ ์ธ๋ฑ์ค์์ ๋ ์ฝ๋ ํฌ์ธํฐ ๋์ B -tree file organization์ search key๋ฅผ ์ฌ์ฉ
- ๋ ์ฝ๋๋ฅผ ์ฐพ๊ธฐ ์ํด file organization์ ์ถ๊ฐ์ ์ธ ํ์
- Queries์ ๋ํ ๋์ ๋น์ฉ, ๊ทธ๋ฌ๋ node ๋ถํ ์ ๋น์ฉ์ด ์ ๋ ด
- Indexing strings
- Variable length strings as keys
- Variable fanout
- Pointers์ ์๊ฐ ์๋ space utilization์ splitting์ ๊ธฐ์ค์ผ๋ก ์ฌ์ฉ
- Prefix ์์ถ
- Internal nodes์ key๊ฐ์ prefixes of full key์ผ ์ ์์ โ fanout ์ฆ๊ฐ
- Key๊ฐ์ผ๋ก ๋ถ๋ฆฌ๋ subtrees์ ์ํธ๋ฆฌ๋ฅผ ๊ตฌ๋ถํ๊ธฐ์ ์ถฉ๋ถํ ๋ฌธ์๋ฅผ ์ ์ง
- ์: "Silas"์ "Silberschatz"๋ "Silb"๋ก ๋ถ๋ฆฌ๋ ์ ์์.
- Variable length strings as keys
Other Issues in Indexing: Bulk Loading & Bottom-Up Build
- ์ํธ๋ฆฌ๋ฅผ ํ ๋ฒ์ B -tree์ ์ฝ์
ํ๋ฉด ์ํธ๋ฆฌ ๋น ์ I/O๊ฐ ํ์ํ ์ ์์.
- ์ต์ ์ ๊ฒฝ์ฐ, ํธ๋ฆฌ์ ๋์ด์ ๋น๋ก
- ๋ง์ ์์ ์ํธ๋ฆฌ๋ฅผ ํ ๋ฒ์ ์ฝ์
ํ๋ ๊ฒฝ์ฐ ๋งค์ฐ ๋นํจ์จ์
- B -tree ์ธ๋ฑ์ค๊ฐ ํฐ relation์ ๊ตฌ์ถ๋ ๋ bulk loading์ด ํ์
- ํจ๊ณผ์ ์ธ ๋์ 1
- ํจ์จ์ ์ธ external sorting ์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํ์ฌ ์ธ๋ฑ์ค ์ํธ๋ฆฌ๋ฅผ ์ ๋ ฌ
- ์ ๋ ฌ๋ ์์๋ก ์ฝ์
- ํน์ leaf node๋ก ๊ฐ๋ ๋ชจ๋ ์ํธ๋ฆฌ๋ ์ฐ์์ ์ผ๋ก ๋ํ๋จ โ leaf node๋ 1๋ฒ๋ง ์ถ๋ ฅ๋๋ฉด ๋จ.
- ๋ ํฅ์๋ I/O ์ฑ๋ฅ, ๊ทธ๋ฌ๋ ๋๋ถ๋ถ์ leaf nodes๊ฐ half full
- ํจ๊ณผ์ ์ธ ๋์ 2: Bottom-up B -tree ๊ตฌ์ฑ
- ์ด์ ์ฒ๋ผ ์ํธ๋ฆฌ๋ฅผ ์ ๋ ฌ
- ๊ทธ๋ฆฌ๊ณ leaf level๋ถํฐ ์์ํ์ฌ layer-by-layer tree๋ฅผ ์์ฑ
- ์ ๋ ฌ๋ ์ํธ๋ฆฌ๋ฅผ block์ fitํ ์ ์๋ ๋งํผ ๋ง์ ์ํธ๋ฆฌ๋ฅผ ์ ์งํ๋ฉด์ blocks๋ก Break up โ ๊ฒฐ๊ณผ block์ด leaf level์ ํ์ฑ
- ๊ฐ block์ ์ต์๊ฐ๊ณผ block์ ๋ํ ํฌ์ธํฐ๋ ๋ค์ level์ ์ํธ๋ฆฌ๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ
- ๋๋ถ๋ถ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์์คํ ์์ bulk-load utility์ ์ผ๋ถ๋ก ๊ตฌํ
Hash Indices
Static Hashing
- Bucket: ์ธ๋ฑ์ค ์ํธ๋ฆฌ๋ฅผ ํฌํจํ๋ ์ ์ฅ ๋จ์
- ์ํธ๋ฆฌ์ search-key๊ฐ์์ ํด์ ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ํธ๋ฆฌ์ bucket์ ํ๋
- ํด์ ํจ์ : ๋ชจ๋ search-key๊ฐ ์งํฉ ์์ ๋ชจ๋ bucket ์ฃผ์๋ค์ ์งํฉ ๋ก์ ํจ์
- ํด์ ํจ์๋ access, insertion, deletion์ ์ํ ์ํธ๋ฆฌ๋ฅผ locateํ๋ ๋ฐ ์ฌ์ฉ
- ๋ค๋ฅธ search-key๊ฐ์ ๊ฐ์ง ์ํธ๋ฆฌ๊ฐ ๊ฐ์ bucket์ ๋งคํ๋ ์ ์์. ๋ฐ๋ผ์ entry๋ฅผ ์ฐพ๊ธฐ ์ํด ์ ์ฒด bucket์ ์์ฐจ์ ์ผ๋ก ํ์ํด์ผ ํจ.
Static Hashing
- ํด์ ์ธ๋ฑ์ค์์, buckets์ ๋ ์ฝ๋์ ๋ํ ํฌ์ธํฐ๋ฅผ ๊ฐ์ง ์ํธ๋ฆฌ๋ฅผ ์ ์ฅ(์ฆ, buckets์ด index entries๋ฅผ ์ ์ฅ)
- In a hash file-organization, buckets์ ๋ ์ฝ๋๋ฅผ ์ ์ฅ
- Bucket overflow๋ ๋ค์์ผ๋ก ์ธํด ๋ฐ์ํ ์ ์์.
- ๋ถ์ถฉ๋ถํ buckets
- ๋ ์ฝ๋ ๋ถ๋ฐฐ์์์ Skew. ๋ ๊ฐ์ง ์ด์ ๋ก ๋ฐ์ ๊ฐ๋ฅ
- ๋ค์ค ๋ ์ฝ๋๊ฐ ๊ฐ์ search-key๊ฐ์ ๊ฐ์ง.
- ์ ํ๋ hash ํจ์๊ฐ key๊ฐ์ non-uniform ๋ถํฌ๋ฅผ ์์ฑ
- Bucket overflow์ ํ๋ฅ ์ ์ค์ผ ์ ์์ง๋ง, ์์ ํ ์ ๊ฑฐํ ์ ์์.
- Overflow buckets์ ์ฌ์ฉํ์ฌ ์ฒ๋ฆฌ
Hash Functions
- ํด์ ํจ์๋ uniform + random์ด ์๊ตฌ๋จ.
- Uniform(๊ท ์ผ): ๊ฐ bucket์ ๋ชจ๋ ์ด๋ก ์ ์ผ๋ก ๊ฐ๋ฅํ ๊ฐ๋ค์ ์งํฉ์์ ๊ฐ์ ์์ search-key๊ฐ์ด ํ ๋น๋จ.
- Random(๋ฌด์์): ๊ฐ bucket์ ํ์ผ ๋ด search-key๊ฐ์ ์ค์ ๋ถํฌ์ irrespective, ๊ฐ์ ์์ ์ํธ๋ฆฌ์ ํ ๋น๋จ.
- ์ ํ์ ์ธ ํด์ ํจ์๋ search-key์ internal binary ํํ์ ๋ํ ์ฐ์ฐ์ ์ํ
- ์: ๋ฌธ์์ด search-key์ ๊ฒฝ์ฐ, ๋ฌธ์์ด์ ๋ชจ๋ ๋ฌธ์๋ค์ ์ด์ง ํํ์ ์ถ๊ฐํ๊ณ , sum modulo the number of buckets๋ฅผ ๋ฐํ
Handling of Bucket Overflows
- Overflow chaining: ์ฃผ์ด์ง bucket์ overflow buckets์ linked list๋ก chained together
- Overflow chaining์ ์ฌ์ฉํ๋ ํด์ ์ธ๋ฑ์ฑ: closed addressing (๋๋ closed hasing)
- Overflow buckets์ ์ฌ์ฉํ์ง ์๋ ๋์์ ์ธ open addressing์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ํฉํ์ง ์์.
Deficiencies of Static Hashing
- Static hashing์์, ํจ์ ๋ search-key๊ฐ์ fixed set()์ bucket ์ฃผ์๋ก ๋งคํ. ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ ์๊ฐ์ด ์ง๋จ์ ๋ฐ๋ผ grow or shrink
- Initial number of buckets๊ฐ ๋๋ฌด ์ ๊ณ , ํ์ผ์ด ์ปค์ง์ ๋ฐ๋ผ ๋๋ฌด ๋ง์ overflows๋ก ์ธํด ์ฑ๋ฅ ๊ฐ์
- ์์ธก๋ ์ฆ๊ฐ๋ถ์ ์ํด ๊ณต๊ฐ์ด ํ ๋น๋๋ฉด, ์ด๊ธฐ์ ์๋นํ ์์ ๊ณต๊ฐ์ด ๋ญ๋น๋จ.)
- Database๊ฐ ์ถ์๋๋ฉด, ๋ค์ ๊ณต๊ฐ์ด ๋ญ๋น๋จ.
- One solution
- ์๋ก์ด ํด์ ํจ์๋ก ํ์ผ์ ์ฃผ๊ธฐ์ ์ผ๋ก reorganize
- Expensive, normal ์ฐ์ฐ์ ํผ๋์ํด.
- ๋ ๋์ ํด๊ฒฐ์ฑ
: Dynamic Hashing
- Buckets์ number๋ฅผ ๋์ ์ผ๋ก ์์ ํ ์ ์๋ ๊ธฐ๋ฒ
- ์ฌ์ด์ฆ๊ฐ ์ฑ์ฅํ๊ณ ์ถ์๋๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ํฉ
- ํด์ ํจ์๋ฅผ ๋์ ์ผ๋ก ์์ ํ ์ ์๋๋ก ํ์ฉ
- Extendable hashing: dynamic hashing์ ํ ํํ
Comparison of Ordered Indexing and Hashing
- ์ฃผ๊ธฐ์ re-organization์ ๋น์ฉ
- ์ฝ์ /์ญ์ ์ ์๋์ ๋น๋
- Is it desirable to optimize average access time at the expense of worst-case access time?
- Expected type of queries
- Hashing์ ์ผ๋ฐ์ ์ผ๋ก key์ ๊ตฌ์ฒด์ ์ธ ๊ฐ์ ๊ฐ์ง ๋ ์ฝ๋๋ฅผ retrievingํ๋ ๋ฐ ์ ํฉ
- Range queries๊ฐ common, ์ ๋ ฌ๋ ์ธ๋ฑ์ค๊ฐ ์ ํธ๋จ.
- ์ค์ ๋ก๋
PostgreSQL์ hash ์ธ๋ฑ์ค๋ฅผ ์ง์ํ์ง๋ง, ๋ฎ์ ์ฑ๋ฅ์ผ๋ก ์ธํด ์ ์ฌ์ฉ๋์ง ์์.Oracle์ static hash organization์ ์ง์ํ์ง๋ง, not hash indicesSQLServer๋ B -trees๋ง์ ์ง์

