15. Query Processing
Basic Steps in Query Processing
- Parsing and translation
- Parser๊ฐ query (SQL) ๊ตฌ๋ฌธ ํ์ธ, relation ๊ฒ์ฆ
- Query๋ฅผ ๊ด๊ณ ๋์(relational algebra) ํํ์์ผ๋ก ๋ณํ
- ๋น์ ์ฐจ์ query โ ์ ์ฐจ์ query
- Optimization: ์ต์ ์ ํ๊ฐ ๊ณํ(evaluation plan) ์์ฑ
- Evaluation
- Query-execution engine์ด query-evaluation plan์ ๋ฐ์ ์คํํ๊ณ query์ ๋ํ ๋ต๋ณ ๋ฐํ
Basic Steps in Query Processing: Optimization
- ํ๋์ relational algebra ํํ์์ ์ฌ๋ฌ ๋๋ฑํ ํํ์์ ๊ฐ์ง ์ ์์
- ์: ๋ ์ ๋์ผ
- ๊ฐ relational algebra ์ฐ์ฐ์ ์ฌ๋ฌ ๋ค๋ฅธ algorithm ์ค ํ๋๋ฅผ ์ฌ์ฉํด ํ๊ฐ ๊ฐ๋ฅ
- ๋ฐ๋ผ์ relational algebra ํํ์์ ์ฌ๋ฌ ๋ฐฉ์์ผ๋ก ํ๊ฐ๋ ์ ์์
- ์)
- table scan ๋๋
- salary์ ๋ํ index scan (๋ง์ฝ salary์ -tree index๊ฐ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค๋ฉด)
- ์์ธํ ํ๊ฐ ์ ๋ต์ ๋ช ์ํ๋ ์ฃผ์์ด ๋ฌ๋ฆฐ ํํ์์ evaluation primitive๋ผ ํจ
- ์: : salary์ index ์ฌ์ฉ
- Query-execution plan (๋๋ query-evaluation plan)
- Query๋ฅผ ํ๊ฐํ๊ธฐ ์ํ primitive ์ฐ์ฐ๋ค์ ์ํ์ค
- Query Optimization
- ๋ชจ๋ ๋๋ฑํ evaluation plan ์ค์์ ๊ฐ์ฅ ๋น์ฉ์ด ๋ฎ์ ๊ฒ์ ์ ํ
- ๋น์ฉ์ database catalog์ ํต๊ณ ์ ๋ณด๋ฅผ ์ฌ์ฉํด ์ถ์
- ์: ๊ฐ relation์ tuple ์, tuple์ ํฌ๊ธฐ ๋ฑ
- ์ด ์ฅ์์ ๋ค๋ฃจ๋ ๋ด์ฉ
- Query ๋น์ฉ ์ธก์ ๋ฐฉ๋ฒ
- Relational algebra ์ฐ์ฐ ํ๊ฐ๋ฅผ ์ํ algorithm
- ์์ ํ ํํ์์ ํ๊ฐํ๊ธฐ ์ํด ๊ฐ๋ณ ์ฐ์ฐ algorithm์ ๊ฒฐํฉํ๋ ๋ฐฉ๋ฒ
- 16์ฅ ๊ด๋ จ
- Query ์ต์ ํ ๋ฐฉ๋ฒ, ์ฆ ๊ฐ์ฅ ๋ฎ์ ์ถ์ ๋น์ฉ์ ๊ฐ์ง evaluation plan์ ์ฐพ๋ ๋ฐฉ๋ฒ ์ฐ๊ตฌ
Measures of Query Cost
- ์๊ฐ ๋น์ฉ์ ๊ธฐ์ฌํ๋ ๋ง์ ์์ธ
- Disk access, CPU, network communication
- ๋น์ฉ ์ธก์ ๊ธฐ์ค
- ์๋ต ์๊ฐ(response time), ์ฆ query ์๋ต์ ๊ฑธ๋ฆฐ ์ด ๊ฒฝ๊ณผ ์๊ฐ
- ์ด ์์ ์๋น(total resource consumption)
- ์ด ์์ ์๋น๋ฅผ ๋น์ฉ metric์ผ๋ก ์ฌ์ฉ
- ์๋ต ์๊ฐ์ ์ถ์ ํ๊ธฐ ๋ ์ด๋ ต๊ณ , ๊ณต์ database์์๋ ์์ ์๋น ์ต์ํ๊ฐ ์ข์
- ๋จ์ํ๋ฅผ ์ํด CPU ๋น์ฉ์ ๋ฌด์
- ์ค์ ์์คํ ์ CPU ๋น์ฉ์ ๊ณ ๋ คํจ
- ๋ณ๋ ฌ ์์คํ ์์๋ network ๋น์ฉ ๊ณ ๋ ค ํ์
- ๊ฐ ์ฐ์ฐ์ ๋น์ฉ ์ถ์ ๋ฐฉ๋ฒ ์ค๋ช
- output์ disk์ ์ฐ๋ ๋น์ฉ์ ํฌํจํ์ง ์์ (์ฐ์ฐ์ output์ด disk์ ์ฐ์ด์ง ์๊ณ ๋ค์ ์ฐ์ฐ์ผ๋ก ์ ์ก๋ ์ ์์ผ๋ฏ๋ก)
- Disk ๋น์ฉ ์ถ์
- Number of seeks ร average-seek-cost
- Number of blocks read ร average-block-read-cost
- Number of blocks written ร average-block-write-cost
- ๋จ์ํ๋ฅผ ์ํด disk๋ก๋ถํฐ์ block ์ ์ก ํ์์ seek ํ์๋ง ๋น์ฉ ์ฒ๋๋ก ์ฌ์ฉ
- โ ํ๋์ block์ ์ ์กํ๋ ์๊ฐ
- ๋จ์ํ๋ฅผ ์ํด write ๋น์ฉ์ read ๋น์ฉ๊ณผ ๊ฐ๋ค๊ณ ๊ฐ์
- โ ํ ๋ฒ์ seek์ ๊ฑธ๋ฆฌ๋ ์๊ฐ
- block ์ ์ก๊ณผ seek์ ๋ํ ๋น์ฉ:
- ์ ๋ ๋ฐ์ดํฐ ์ ์ฅ ์์น์ ๋ฐ๋ผ ๋ค๋ฆ; 4 KB block ๊ธฐ์ค,
- High end magnetic disk: ์ด๊ณ
- SSD: ์ด๊ณ
- ํ์ํ ๋ฐ์ดํฐ๊ฐ ์ด๋ฏธ buffer resident์ผ ์ ์์ด disk I/O๋ฅผ ํผํ ์ ์์
- ๊ทธ๋ฌ๋ ๋น์ฉ ์ถ์ ์ ๊ณ ๋ คํ๊ธฐ ์ด๋ ค์
- ์ฌ๋ฌ algorithm์ ์ถ๊ฐ buffer ๊ณต๊ฐ์ ์ฌ์ฉํด disk IO๋ฅผ ์ค์ผ ์ ์์
- buffer์ ์ฌ์ฉ ๊ฐ๋ฅํ ์ค์ memory ์์ ๋ค๋ฅธ ๋์ query ๋ฐ OS process์ ๋ฐ๋ผ ๋ค๋ฅด๋ฉฐ, ์คํ ์ค์๋ง ์ ์ ์์
- ์ต์ ์ ๊ฒฝ์ฐ(Worst case) ์ถ์ ์ ์ด๊ธฐ์ buffer์ ๋ฐ์ดํฐ๊ฐ ์๊ณ ์ฐ์ฐ์ ํ์ํ ์ต์ memory๋ง ์ฌ์ฉ ๊ฐ๋ฅํ๋ค๊ณ ๊ฐ์
- ๊ทธ๋ฌ๋ ์ค์ ๋ก๋ ๋ ๋๊ด์ ์ธ ์ถ์ ์ด ์ฌ์ฉ๋จ
Selection Operation
- File scan (๋๋ table scan)
- ์ ํ ์กฐ๊ฑด์ ๋ง์กฑํ๋ record๋ฅผ ์ฐพ์ ๊ฒ์
- Full file scan: file (relation)์ ๋ชจ๋ record ๊ฒ์
- Algorithm A1 (linear search)
- ๊ฐ file block์ scanํ๊ณ ๋ชจ๋ record๊ฐ ์ ํ ์กฐ๊ฑด์ ๋ง์กฑํ๋์ง ํ ์คํธ
- ๋น์ฉ ์ถ์ = block ์ ์ก + 1 seek =
- ์ relation ์ record๋ฅผ ํฌํจํ๋ block ์
- ๋ง์ฝ key attribute์ ๋ํ ์ ํ์ด๊ณ ์ ํ ์กฐ๊ฑด์ด ๋๋ฑ ๋น๊ต(equality comparison)๋ผ๋ฉด
- record๋ฅผ ์ฐพ๋ ์ฆ์ ์ค๋จ ๊ฐ๋ฅ
- ๋น์ฉ = block ์ ์ก + 1 seek =
- Linear search๋ ๋ค์์ ๊ด๊ณ์์ด ์ ์ฉ ๊ฐ๋ฅ
- ์ ํ ์กฐ๊ฑด,
- file ๋ด record์ ์์, ๋๋
- index ๊ฐ์ฉ์ฑ
- ์ฐธ๊ณ : Binary search๋?
- ๋ฐ์ดํฐ๊ฐ ์ฐ์์ ์ผ๋ก ์ ์ฅ๋์ง ์์ผ๋ฏ๋ก ์ผ๋ฐ์ ์ผ๋ก ์๋ฏธ ์์
- ๋ํ, binary search๋ index search๋ณด๋ค ๋ ๋ง์ seek๋ฅผ ์๊ตฌ
- Index scan
- Index๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ algorithm
- ์ ํ ์กฐ๊ฑด์ index์ search-key์ ์์ด์ผ ํจ
- Algorithm A2 (clustering -tree index, equality on key)
- ํด๋น ๋๋ฑ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๋จ์ผ record ๊ฒ์
- ๋น์ฉ = , ์ฌ๊ธฐ์ ๋ index์ ๋์ด
- Algorithm A3 (clustering -tree index, equality on non-key)
- ํด๋น ๋๋ฑ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์ฌ๋ฌ record ๊ฒ์
- Record๋ค์ ์ฐ์์ ์ธ block์ ์์ ๊ฒ (์ฐธ๊ณ : clustering index)
- ๋น์ฉ = , ( = ์ผ์นํ๋ record๋ฅผ ํฌํจํ๋ block ์)
- Algorithm A4 (secondary -tree index, equality on key/non-key)
- Search-key๊ฐ candidate key์ธ ๊ฒฝ์ฐ ๋จ์ผ record ๊ฒ์
- ๋น์ฉ =
- Search-key๊ฐ candidate key๊ฐ ์๋ ๊ฒฝ์ฐ ์ฌ๋ฌ record ๊ฒ์
- ์ผ์นํ๋ ๊ฐ์ record ๊ฐ๊ฐ์ด ๋ค๋ฅธ block์ ์์ ์ ์์ (์ฐธ๊ณ : secondary index)
- ๋น์ฉ = : ๋งค์ฐ ๋น์ ์ ์์!
Selection Involving Comparisons
- ๋๋ ํํ์ selection ๊ตฌํ ๋ฐฉ๋ฒ
- linear file scan ์ฌ์ฉ,
- ๋๋ index๋ฅผ ๋ค์ ๋ฐฉ์์ผ๋ก ์ฌ์ฉ
- Algorithm A5 (clustering -tree index, comparison)
- Relation์ด ์ ๋ํด ์ ๋ ฌ๋จ
- ์ ๊ฒฝ์ฐ, index๋ฅผ ์ฌ์ฉํด ์ธ ์ฒซ tuple์ ์ฐพ๊ณ ๊ฑฐ๊ธฐ์๋ถํฐ relation์ ์์ฐจ์ scan
- ๋น์ฉ = (A3 ๊ฒฝ์ฐ์ ๋์ผ)
- ์ ๊ฒฝ์ฐ, ์ฒซ tuple ๋ฅผ ๋ง๋ ๋๊น์ง relation์ ์์ฐจ์ scan; index ๋ฏธ์ฌ์ฉ
- ๋น์ฉ =
- Algorithm A6 (secondary -tree index, comparison)
- ์ ๊ฒฝ์ฐ, index๋ฅผ ์ฌ์ฉํด ์ธ ์ฒซ index entry๋ฅผ ์ฐพ๊ณ ๊ฑฐ๊ธฐ์๋ถํฐ index๋ฅผ ์์ฐจ์ scanํ์ฌ record pointer ์ฐพ๊ธฐ
- ์ ๊ฒฝ์ฐ, ์ฒซ entry ๋ฅผ ๋ง๋ ๋๊น์ง index์ leaf page๋ฅผ scanํ๋ฉฐ record pointer ์ฐพ๊ธฐ
- ๋ ๊ฒฝ์ฐ ๋ชจ๋, pointer๊ฐ ๊ฐ๋ฆฌํค๋ record๋ฅผ ๊ฒ์
- record ๋น random I/O ํ์
- ๊ฐ์ ธ์ฌ record๊ฐ ๋ง๋ค๋ฉด Linear file scan์ด ๋ ์ ๋ ดํ ์ ์์!
- Algorithm A6์์,
- secondary index์ linear file scan ์ค ์ด๋ ๊ฒ์ ์ ํํ๋ , ์ผ์นํ๋ record ์๋ฅผ ๋ฏธ๋ฆฌ ์์ง ๋ชปํ๋ฉด ์ฑ๋ฅ์ด ์ ํ๋ ์ ์์
- PostgreSQL์ bitmap index scan algorithm
- ์ผ์นํ๋ record ์๋ฅผ ์คํ ์ ์ ์ ์ ์์ ๋ secondary index scan๊ณผ linear file scan ๊ฐ์ ๊ฒฉ์ฐจ๋ฅผ ํด์
- relation์ block ๋น 1 bit๋ฅผ ๊ฐ์ง bitmap ์์ฑ (๋ชจ๋ bit๋ 0์ผ๋ก ์ด๊ธฐํ)
- ๋จ๊ณ
- secondary index๋ฅผ ์ฌ์ฉํด ์ผ์นํ๋ record์ pointer ์ฐพ๊ธฐ
- record๋ฅผ ๊ฐ์ ธ์ค๋ ๋์ , bitmap์์ ํด๋น bit๋ฅผ 1๋ก ์ค์
- bit๊ฐ 1๋ก ์ค์ ๋์ง ์์ block์ ๊ฑด๋๋ฐ๋ฉด์ linear file scan ์ํ, ๊ฐ์ ธ์จ block ๋ด ๋ชจ๋ ์ผ์น record ๊ฒ์
- ์ฑ๋ฅ
- bit๊ฐ ๋ช ๊ฐ๋ง ์ค์ ๋ ๊ฒฝ์ฐ index scan๊ณผ ์ ์ฌ
- ๋๋ถ๋ถ์ bit๊ฐ ์ค์ ๋ ๊ฒฝ์ฐ linear file scan๊ณผ ์ ์ฌ
- ์ต์์ plan์ ๋นํด ๊ฒฐ์ฝ ๋งค์ฐ ๋์๊ฒ ๋์ํ์ง ์์
Implementation of Complex Selections
- Conjunction:
- Algorithm A7 (conjunctive selection using one index)
- ์ ๋ํด ์ต์ ๋น์ฉ์ ์ด๋ํ๋ 'ํ๋์ ()์ algorithm (A1 ~ A6)์ ์กฐํฉ'์ ์ ํ
- ๊ฒ์๋ ๊ฐ record๊ฐ ๋๋จธ์ง ์กฐ๊ฑด ()๋ฅผ ๋ง์กฑํ๋์ง memory buffer์์ ํ ์คํธํ์ฌ ์ฐ์ฐ ์๋ฃ
- ๋น์ฉ์ ์ ํ๋ algorithm์ ๋น์ฉ
- Algorithm A8 (conjunctive selection using composite index)
- ์ผ๋ถ conjunctive selection์ ๋ํด ์ฌ์ฉ ๊ฐ๋ฅํ ์ ์ ํ composite (multiple-key) index ์ฌ์ฉ
- Algorithm A9 (conjunctive selection by intersection of identifiers)
- record pointer๊ฐ ์๋ index ํ์
- ๊ฐ ์กฐ๊ฑด์ ๋ํด ํด๋นํ๋ index๋ฅผ ์ฌ์ฉํ๊ณ , ์ป์ด์ง ๋ชจ๋ record pointer ์งํฉ์ ๊ต์งํฉ(intersection)์ ๊ตฌํจ
- ๊ทธ ๋ค์ file์์ record๋ฅผ ๊ฐ์ ธ์ด
- ์ผ๋ถ ์กฐ๊ฑด์ ์ ์ ํ index๊ฐ ์๋ค๋ฉด, memory์์ ํ ์คํธ ์ ์ฉ
- Disjunction:
- Algorithm A10 (disjunctive selection by union of identifiers)
- ๋ชจ๋ ์กฐ๊ฑด์ ์ฌ์ฉ ๊ฐ๋ฅํ index๊ฐ ์๋ ๊ฒฝ์ฐ ์ ์ฉ ๊ฐ๋ฅ
- ๊ทธ๋ ์ง ์์ผ๋ฉด linear scan ์ฌ์ฉ
- ๊ฐ ์กฐ๊ฑด์ ํด๋นํ๋ index๋ฅผ ใด์ฌ์ฉํ๊ณ , ์ป์ด์ง ๋ชจ๋ record pointer ์งํฉ์ ํฉ์งํฉ(union)์ ๊ตฌํจ
- ๊ทธ ๋ค์ file์์ record๋ฅผ ๊ฐ์ ธ์ด
- Negation:
- Comparison์ ์ฐ์ง ์์ ๊ฒ. equality์ ์ฌ์ฉ
- file์ linear scan ์ฌ์ฉ
- ์ผ๋ฐ์ ์ผ๋ก record์ ์๋น ๋ถ๋ถ์ด ๋ฅผ ๋ง์กฑ (์ฆ, ๋ฅผ ๋ง์กฑํ์ง ์์)
- ๋ง์ฝ ๋ฅผ ๋ง์กฑํ๋ record๊ฐ ๋งค์ฐ ์ ๊ณ , ์ index ์ ์ฉ ๊ฐ๋ฅํ๋ค๋ฉด
- index๋ฅผ ์ฌ์ฉํด ๋ฅผ ๋ง์กฑํ๋ record๋ฅผ ์ฐพ๊ณ file์์ ๊ฐ์ ธ์ด
Sorting
- Sorting์ database ์์คํ ์์ ์ค์ํ ์ญํ ์ํ
- SQL query๋ output์ด ์ ๋ ฌ๋๋๋ก ์ง์ ํ ์ ์์
- Join๊ณผ ๊ฐ์ ์ฌ๋ฌ relational ์ฐ์ฐ์ ์ ๋ ฅ relation์ด ๋จผ์ ์ ๋ ฌ๋๋ฉด ํจ์จ์ ์ผ๋ก ๊ตฌํ ๊ฐ๋ฅ
- ๋จ์ index-๊ธฐ๋ฐ ์ ๋ ฌ
- relation์ index๋ฅผ ๊ตฌ์ถํ๊ณ , index๋ฅผ ์ฌ์ฉํด ์ ๋ ฌ๋ ์์๋ก relation ์ฝ๊ธฐ
- ๊ฐ tuple์ ๋ํด disk block access๊ฐ ๋ฐ์ํ ์ ์์ (๋ฌผ๋ฆฌ์ ์ด ์๋ index๋ฅผ ํตํด ๋
ผ๋ฆฌ์ ์ผ๋ก๋ง relation์ ์ ๋ ฌํ๊ธฐ ๋๋ฌธ)
- record๋ฅผ ๋ฌผ๋ฆฌ์ ์ผ๋ก ์ ๋ ฌํ๋ ํจ์จ์ ์ธ algorithm ํ์
- memory์ ๋ง๋ relation์ ๊ฒฝ์ฐ, quicksort ๊ฐ์ technique ์ฌ์ฉ ๊ฐ๋ฅ
- memory์ ๋ง์ง ์๋ relation ์ ๋ ฌ์ external sorting์ด๋ผ ํจ
- external sort-merge: ๊ฐ์ฅ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ๋๋ external sorting algorithm
External Sort-Merge
- ์ memory ํฌ๊ธฐ (block ๋จ์)๋ผ ๊ฐ์
- ์ ๋ ฌ๋ run ์์ฑ i = 0; Repeat relation์ block์ memory๋ก ์ฝ๊ธฐ; in-memory block ์ ๋ ฌ; ์ ๋ ฌ๋ ๋ฐ์ดํฐ๋ฅผ run file ์ ์ฐ๊ธฐ; i = i + 1; Until relation์ ๋๊น์งddddddddddddfsdvssssssssssssssssss ์ด run์ ์๋ฅผ ์ด๋ผ ํ๊ณ , (์ง๊ธ์) ์ด๋ผ ๊ฐ์
- Run ๋ณํฉ (N-way merge) /* ๊ฐ์ memory block์ ์ ๋ ฅ run buffer๋ก, 1 block์ output buffer๋ก ์ฌ์ฉ / ๊ฐ run์ ์ฒซ block์ ํด๋น buffer block์ผ๋ก ์ฝ๊ธฐ; repeat ๋ชจ๋ buffer block ์ค์์ ์ฒซ ๋ฒ์งธ record (์ ๋ ฌ ์์ ๊ธฐ์ค) ์ ํ; record๋ฅผ output buffer์ ์ฐ๊ธฐ; / output buffer๊ฐ ์ฐผ๋ค๋ฉด, disk์ ์ฐ๊ธฐ */ ํด๋น input buffer block์์ record ์ญ์ ; If buffer block์ด ๋น๊ฒ ๋๋ฉด then run์ ๋ค์ block (์๋ค๋ฉด)์ buffer๋ก ์ฝ๊ธฐ; until ๋ชจ๋ input buffer block์ด ๋น ๋๊น์ง
- ๋ง์ฝ ์ธ ๊ฒฝ์ฐ
- , ์ฆ ์ฌ์ฉ ๊ฐ๋ฅํ memory ํฌ๊ธฐ()๊ฐ ํ์ํ buffer ์(๊ฐ์ input buffer + 1๊ฐ์ output buffer)๋ณด๋ค ์์
- ์ฌ๋ฌ merge pass๊ฐ ํ์
- ๊ฐ pass์์, ๊ฐ run์ ์ฐ์ ๊ทธ๋ฃน์ด ๋ณํฉ๋จ
- ํ pass๋ run์ ์๋ฅผ factor๋ก ์ค์ด๊ณ , run ๊ธธ์ด๋ฅผ ๊ฐ์ factor๋งํผ ๋๋ฆผ
- ์: ์ด๊ณ 90๊ฐ์ run์ด ์๋ค๋ฉด, ํ pass๋ run ์๋ฅผ 9๊ฐ๋ก ์ค์ (). ๊ฐ run์ ํฌ๊ธฐ๋ ์ด๊ธฐ run์ 10๋ฐฐ()๊ฐ ๋จ
- ๋ชจ๋ run์ด ํ๋๋ก ๋ณํฉ๋ ๋๊น์ง pass ๋ฐ๋ณต ์ํ
- ๋น์ฉ ๋ถ์
- ์ relation ์ record๋ฅผ ํฌํจํ๋ block ์๋ผ ํจ
- ํ์ํ ์ด merge pass ์: ( : ์ด๊ธฐ run์ ์)
- ์ด๊ธฐ run ์์ฑ ๋๋ ๊ฐ pass์์์ block ์ ์ก ์
- ( read ๋ฐ write)
- ๋ง์ง๋ง pass์์๋ write ๋น์ฉ ๋ฏธํฌํจ
- ๋ฐ๋ผ์ external sorting์ ์ด block ์ ์ก ์
- merge pass ๋์, ๊ฐ run์ ํ ๋ฒ์ 1 block์ฉ ์ฝ์ผ๋ฉด ๋ง์ seek ๋ฐ์
- ๋์ , run ๋น buffer block ์ฌ์ฉ โ ํ ๋ฒ์ block read/write
- ํ pass์์ ๊ฐ์ run ๋ณํฉ ๊ฐ๋ฅ
- ํ์ํ ์ด merge pass ์:
- ๋ฐ๋ผ์ external sorting์ ์ด block ์ ์ก ์
- Seek ๋น์ฉ
- run ์์ฑ ๋์
- ์ ์ฒด relation read์ seek
- ๊ฐ run์ writeํ๊ธฐ ์ํด seek
- ์ด seek =
- merge ๋จ๊ณ ๋์
- ๊ฐ run file์์ block read: read์ ๋ํ ์ด seek
- output file์ writeํ๋ ๊ฒ์ ์์ฐจ์ ์ด์ง๋ง, write๊ฐ read๋ฅผ ๋ฐฉํดํ ์ ์์
- ๋ชจ๋ read ์ฐ์ฐ์ head๋ฅผ ์์ง์ด๋ฏ๋ก write ์ฐ์ฐ์ ๋ํ seek ๋ฐ์
- output write์ seek ์ถ๊ฐ ํ์
- ๋ฐ๋ผ์, write ๋น์ฉ์ ๋ฌด์ํ๋ ๋ง์ง๋ง pass๋ฅผ ์ ์ธํ๊ณ ๊ฐ merge pass๋ง๋ค seek ํ์
- ์ด seek ์
- run ์์ฑ ๋์
Join Operation
- Join์ ๊ตฌํํ๋ ์ฌ๋ฌ ๋ค๋ฅธ algorithm
- Nested-loop join
- Block nested-loop join
- Indexed nested-loop join
- Merge-join
- Hash-join
- ๋น์ฉ ์ถ์ ์ ๊ธฐ๋ฐํ ์ ํ
- ์์ ๋ ๋ค์ ์ ๋ณด ์ฌ์ฉ
- student record ์: 5,000 / takes record ์: 10,000
- student block ์: 100 / takes block ์: 400
Nested-Loop Join
- theta join ๊ณ์ฐ for ์ ๊ฐ tuple do begin for ์ ๊ฐ tuple do begin pair ๊ฐ join ์กฐ๊ฑด ๋ฅผ ๋ง์กฑํ๋์ง ํ ์คํธ if ๋ง์กฑํ๋ฉด, ๋ฅผ ๊ฒฐ๊ณผ์ ์ถ๊ฐ; end end
- ์ outer relation, ๋ฅผ inner relation์ด๋ผ ํจ
- ๋ ๋ tuple์ attribute ๊ฐ์ ์ฐ๊ฒฐ(concatenating)ํ์ฌ ๊ตฌ์ฑ๋ tuple
- index๊ฐ ํ์ ์์ผ๋ฉฐ ์ด๋ค ์ข ๋ฅ์ join ์กฐ๊ฑด๊ณผ๋ ์ฌ์ฉ ๊ฐ๋ฅ
- ๋ relation์ ๋ชจ๋ tuple pair๋ฅผ ๊ฒ์ฌํ๋ฏ๋ก ๋น์
- ๊ณผ ๋ฅผ ๊ฐ๊ฐ relation ๊ณผ ์ record ์๋ผ ํจ
- ๋น์ฉ ์ถ์
- ์ต์
์ ๊ฒฝ์ฐ(Worst case): ๊ฐ relation์ block ํ๋๋ง memory์ ์ ์ง ๊ฐ๋ฅ
- ์ถ์ ๋น์ฉ: block ์ ์ก ๋ฐ seek
- ์ต์์ ๊ฒฝ์ฐ(Best case): ๋ relation์ด ๋์์ memory์ ๋ง์ ๋งํผ ์ถฉ๋ถํ memory ๊ณต๊ฐ
- ์ถ์ ๋น์ฉ: block ์ ์ก ๋ฐ 2 seek
- ๋ ์์ relation๋ง memory์ ๋ง๋๋ค๋ฉด, ๊ทธ๊ฒ์ inner relation์ผ๋ก ์ฌ์ฉ
- ์ถ์ ๋น์ฉ: block ์ ์ก ๋ฐ 2 seek (์ต์์ ๊ฒฝ์ฐ์ ๋์ผ)
- ์ต์
์ ๊ฒฝ์ฐ(Worst case): ๊ฐ relation์ block ํ๋๋ง memory์ ์ ์ง ๊ฐ๋ฅ
- ์ต์
์ memory ๊ฐ์ฉ์ฑ์ ๊ฐ์ ํ ๋, ๋น์ฉ ์ถ์ ์
- student๋ฅผ outer relation์ผ๋ก
5000 * 400 + 100 = 2,000,100 block์ ์ก,5000 + 100 = 5100 seek
- takes๋ฅผ outer relation์ผ๋ก
10000 * 100 + 400 = 1,000,400 block์ ์ก ๋ฐ10,400 seek
- student๋ฅผ outer relation์ผ๋ก
- ๋ ์์ relation (student)์ด memory์ ์์ ํ ๋ง๋๋ค๋ฉด, ๋น์ฉ ์ถ์ ์ 500 block ์ ์ก
- Block nested-loops algorithm (๋ค์ slide)์ด ์ ํธ๋จ
Block Nested-Loop Join
- inner relation์ ๋ชจ๋ block์ด outer relation์ ๋ชจ๋ block๊ณผ pair๋ฅผ ์ด๋ฃจ๋ nested-loop join์ ๋ณํ
for $r$์ ๊ฐ block $B_r$ do begin
for $s$์ ๊ฐ block $B_s$ do begin
for $B_r$์ ๊ฐ tuple $t_r$ do begin
for $B_s$์ ๊ฐ tuple $t_s$ do begin
$(t_r, ~ t_s)$๊ฐ join ์กฐ๊ฑด์ ๋ง์กฑํ๋์ง ํ์ธ
if ๋ง์กฑํ๋ฉด, $t_r \cdot t_s$๋ฅผ ๊ฒฐ๊ณผ์ ์ถ๊ฐ;
end
end
end
end
- ๋น์ฉ ์ถ์
- ์ต์ ์ ๊ฒฝ์ฐ ์ถ์ : block ์ ์ก, seek
- inner relation ์ ๊ฐ block์ outer relation์ ๊ฐ block์ ๋ํด ํ ๋ฒ์ฉ ์ฝํ
- student takes์ ๊ฒฝ์ฐ, 40100 block ์ ์ก ๋ฐ 200 seek
- ์ต์์ ๊ฒฝ์ฐ: block ์ ์ก + 2 seek
- nested loop ๋ฐ block nested loop algorithm ๊ฐ์
- Block nested-loop์์,
- outer relation์ ์ํ blocking unit์ผ๋ก ( = memory ํฌ๊ธฐ block ์) ์ฌ์ฉ
- ๋๋จธ์ง ๋ block์ inner relation๊ณผ output์ bufferํ๋ ๋ฐ ์ฌ์ฉ
- ํ ๋ฒ์ outer relation์ block ์ฝ๊ธฐ
- ๊ฐ inner relation block์ ๋ํด, outer relation์ block ๋ชจ๋์ join
- ๋น์ฉ = block ์ ์ก + seek
- equi-join attribute๊ฐ inner relation์ key๋ฅผ ํ์ฑํ๋ฉด, ์ฒซ ๋ฒ์งธ ์ผ์น์์ inner loop ์ค๋จ
- buffer์ ๋จ์์๋ block์ ํ์ฉํ๊ธฐ ์ํด inner loop๋ฅผ ์๋ค๋ก ๋ฒ๊ฐ์ scan (LRU ๊ต์ฒด ๋ฐฉ์)
- ์ฌ์ฉ ๊ฐ๋ฅํ๋ค๋ฉด inner relation์ index ์ฌ์ฉ
Indexed Nested-Loop Join
- nested-loop join์์, ๋ค์ ์กฐ๊ฑด ๋ง์กฑ ์ index lookup์ด file scan์ ๋์ฒด ๊ฐ๋ฅ
- join์ด equi-join ๋๋ natural join์ด๊ณ ,
- inner relation์ join attribute์ index๊ฐ ์ฌ์ฉ ๊ฐ๋ฅํ ๊ฒฝ์ฐ
- join ๊ณ์ฐ๋ง์ ์ํด index ๊ตฌ์ถ ๊ฐ๋ฅ
- outer relation ์ ๊ฐ tuple ์ ๋ํด, index๋ฅผ ์ฌ์ฉํด tuple๊ณผ join ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์ tuple lookup
- ์ต์
์ ๊ฒฝ์ฐ
- Buffer๋ ์ block ํ๋ ๊ณต๊ฐ๋ง ์๊ณ , ์ ๊ฐ tuple์ ๋ํด ์์ index lookup ์ํ
- Join ๋น์ฉ:
- ๋ ์ ํ tuple์ ๋ํด index๋ฅผ ์ํํ๊ณ ๋ชจ๋ ์ผ์นํ๋ tuple์ ๊ฐ์ ธ์ค๋ ๋น์ฉ
- ๋ join ์กฐ๊ฑด์ ์ฌ์ฉํ ์ ๋ํ ๋จ์ผ selection ๋น์ฉ์ผ๋ก ์ถ์ ๊ฐ๋ฅ
- ๊ณผ ๋ชจ๋์ join attribute์ index๊ฐ ์๋ค๋ฉด, tuple์ด ๋ ์ ์ relation์ outer relation์ผ๋ก ์ฌ์ฉ
Example of Nested-Loop Join Costs
- student takes ๊ณ์ฐ, student๋ฅผ outer relation์ผ๋ก
- ๊ณตํต attribute: ID
- takes๊ฐ ID attribute์ primary -tree index๋ฅผ ๊ฐ์ง๋ค๊ณ ๊ฐ์ , ๊ฐ index node๋ 20๊ฐ entry ํฌํจ
- takes๋ 10,000๊ฐ tuple์ ๊ฐ์ง๋ฏ๋ก, tree ๋์ด๋ 4, ์ค์ ๋ฐ์ดํฐ ์ฐพ๋ ๋ฐ 1๋ฒ์ access ์ถ๊ฐ ํ์
- Block nested-loop join ๋น์ฉ
400 * 100 + 100 = 40,100 block์ ์ก + 2 * 100 = 200 seek- ์ต์ ์ memory ๊ฐ์
- memory๊ฐ ๋ ๋ง์ผ๋ฉด ํจ์ฌ ์ ์ ์ ์์
- Indexed nested loops join ๋น์ฉ
- 100 + 5000 * 5 = 25,100 block ์ ์ก + 25,100 seek
- (์ผ์นํ๋ ๋ชจ๋ takes tuple์ด ๋จ์ผ block์ ์ ์ฅ๋๋ค๊ณ ๊ฐ์ (takes relation์ ID๋ก ์ ๋ ฌ๋์ด ์๊ณ , ๊ฐ student tuple์ ๋ํด ํ๊ท 2๊ฐ์ ์ผ์นํ๋ takes tuple ์กด์ฌ))
- CPU ๋น์ฉ์ block nested loops join๋ณด๋ค ์ ์ ๊ฐ๋ฅ์ฑ ๋์
Merge Join
- merge-join (sort-merge-join์ด๋ผ๊ณ ๋ ํจ) algorithm์ natural join๊ณผ equi-join ๊ณ์ฐ์ ์ฌ์ฉ ๊ฐ๋ฅ
- (์ด๋ฏธ ์ ๋ ฌ๋์ง ์์๋ค๋ฉด) ๋ relation์ join attribute ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ
- ์ ๋ ฌ๋ relation์ ๋ณํฉํ์ฌ join 2-1 Join ๋จ๊ณ๋ sort-merge algorithm์ merge ๋จ๊ณ์ ์ ์ฌ 2-2 ์ฃผ์ ์ฐจ์ด์ ์ join attribute์ ์ค๋ณต ๊ฐ ์ฒ๋ฆฌ: join attribute์์ ๋์ผํ ๊ฐ์ ๊ฐ์ง ๋ชจ๋ pair๊ฐ ์ผ์นํด์ผ ํจ
- Join ๋จ๊ณ: ์ค์ merge-join algorithm
- join attribute์์ ๋์ผํ ๊ฐ์ ๊ฐ์ง ํ relation์ tuple ๊ทธ๋ฃน์ memory๋ก ์ฝ์
- ๊ทธ ๋ค์, ๋ค๋ฅธ relation์ ํด๋น tuple (์๋ค๋ฉด)์ ์ฝ์ด ๋ค์ด๊ณ , ์ฝ์ผ๋ฉด์ process
- ์์ธ algorithm์ ์ฑ (Figure 15.7) ์ฐธ์กฐ
- ๊ฐ block์ ํ ๋ฒ๋ง ์ฝ์ผ๋ฉด ๋จ (ํน์ join attribute ๊ฐ์ ๋ํ ๋ชจ๋ tuple์ด memory์ ๋ง๋๋ค๊ณ ๊ฐ์ )
- ๊ฐ relation์ buffer block์ด ํ ๋น๋๋ค๊ณ ๊ฐ์ ํ ๋, merge join ๋น์ฉ block ์ ์ก + seek
- relation์ด ์ ๋ ฌ๋์ง ์์ ๊ฒฝ์ฐ ์ ๋ ฌ ๋น์ฉ
- Hybrid merge-join
- ํ relation์ ์ ๋ ฌ๋์ด ์๊ณ , ๋ค๋ฅธ relation์ join attribute์ secondary -tree index๊ฐ ์์ ๋ ์ ์ฉ ๊ฐ๋ฅ
- ์ ๋ ฌ๋ relation์ -tree์ leaf entry (join attribute, pointer)์ ๋ณํฉ
- ๊ฒฐ๊ณผ file์ ์ ๋ ฌ๋ relation์ tuple๊ณผ ์ ๋ ฌ๋์ง ์์ relation์ tuple ์ฃผ์๋ฅผ ํฌํจ
- ์ ๋ ฌ๋์ง ์์ relation์ tuple ์ฃผ์ ๊ธฐ์ค์ผ๋ก ๊ฒฐ๊ณผ ์ ๋ ฌ
- ์ ๋ ฌ๋์ง ์์ relation์ ๋ฌผ๋ฆฌ์ ์ฃผ์ ์์๋ก scanํ๊ณ ์ด์ ๊ฒฐ๊ณผ์ ๋ณํฉํ์ฌ ์ฃผ์๋ฅผ ์ค์ tuple๋ก ๊ต์ฒด
- ์์ฐจ scan์ด random lookup๋ณด๋ค ํจ์จ์
Hash Join
- relation ๊ณผ ๊ฐ์ equi-join ๋ฐ natural join์ ์ ์ฉ ๊ฐ๋ฅ
- hash function ๊ฐ ๋ relation์ tuple์ partitionํ๋ ๋ฐ ์ฌ์ฉ๋จ
- ๋ JoinAttrs ( ๊ณผ ์ ๊ณตํต attribute) ๊ฐ์ ์ mapping
- ์ tuple์ partition์ ๋ํ๋
- ๊ฐ tuple ์ ์ธ partition ์ ๋ฐฐ์น๋จ
- ์ tuple์ partition์ ๋ํ๋
- ๊ฐ tuple ๋ ์ธ partition ์ ๋ฐฐ์น๋จ
- ์ฑ (Figure 15.10)์์ ์ ๋ ์ ๋ก, ์ ๋ก ํ๊ธฐ๋จ
- ๊ธฐ๋ณธ ์์ด๋์ด
- ๊ฐ relation์ tuple์ ๋์ผํ hash ๊ฐ์ ๊ฐ๋ ์งํฉ์ผ๋ก partition
- ๊ทธ๋ฌ๋ฉด ์ tuple์ ์ tuple๊ณผ๋ง ๋น๊ตํ๋ฉด ๋จ
- ์ tuple์ ()์ tuple๊ณผ ๋น๊ตํ ํ์๊ฐ ์์ผ๋ฉฐ, ๊ทธ ๋ฐ๋๋ ๋ง์ฐฌ๊ฐ์ง
Hash Join Algorithm
- ๊ณผ ์ hash-join์ ๋ค์๊ณผ ๊ฐ์ด ๊ณ์ฐ๋จ
- hashing function ๋ฅผ ์ฌ์ฉํด relation ๋ฅผ partition:
- ๋ ์ ์ฌํ๊ฒ partition:
- ๊ฐ ์ ๋ํด ์ ์ ๋ํด ๋ณ๋์ indexed nested-loop join ์ํ, ๋ฐฉ์์ ๋ค์๊ณผ ๊ฐ์ (a) ๋ฅผ memory์ loadํ๊ณ join attribute๋ฅผ ์ฌ์ฉํด in-memory hash index ๊ตฌ์ถ. ์ด hash index๋ ์ด์ ์ ์ ๋ค๋ฅธ hash function ์ฌ์ฉ (b) ์ tuple์ disk์์ ํ๋์ฉ ์ฝ์ (c) ๊ฐ tuple ์ ๋ํด, hash index๋ฅผ ์ฌ์ฉํด ์์ ์ผ์นํ๋ ๊ฐ tuple ๋ฅผ ์ฐพ์. attribute๋ค์ ์ฐ๊ฒฐ(concatenation)์ output
- Relation ๋ build input, ์ probe input์ด๋ผ ๋ถ๋ฆผ
- ๊ฐ์ ๊ฐ (์ ๊ทธ hash index)๊ฐ memory์ ๋ง๋๋ก ์ ํ๋จ
- ์ ๋ก ์ ํ๋๋ฉฐ, ๋ "fudge factor", (์ผ๋ฐ์ ์ผ๋ก ์ฝ 1.2)
Handling of Overflows
- Partitioning์ด skewed ๋์๋ค๋ ๊ฒ์ ์ผ๋ถ partition์ด ๋ค๋ฅธ ๊ฒ๋ณด๋ค ํจ์ฌ ๋ง์ tuple์ ๊ฐ๋ ๊ฒฝ์ฐ
- Hash-table overflow๋ ์ hash index๊ฐ memory์ ๋ง์ง ์์ ๋ partition์์ ๋ฐ์. ์์ธ
- join attribute์ ๋์ผํ ๊ฐ์ ๊ฐ์ง tuple์ด ๋ง์
- ๋์ hash function (๋ฌด์์์ฑ, ๊ท ์ผ์ฑ ์์ฑ ๋ถ์กฑ)
- Overflow resolution์ build ๋จ๊ณ์์ ์ํ ๊ฐ๋ฅ
- Partition ๋ฅผ ๋ค๋ฅธ hash function์ ์ฌ์ฉํด ์ถ๊ฐ partition
- Partition ๋ ์ ์ฌํ๊ฒ partition๋์ด์ผ ํจ
- Overflow avoidance๋ build ๋จ๊ณ ์ค overflow๋ฅผ ํผํ๊ธฐ ์ํด partitioning์ ์ ์คํ๊ฒ ์ํ
- ์: build relation์ ๋ง์ ์์ partition์ผ๋ก ๋๋ ๋ค์, ์ผ๋ถ partition์ ๊ฒฐํฉํ์ฌ ๊ฐ ๊ฒฐํฉ๋ partition์ด memory์ ๋ง๋๋ก ํจ
- ๋ ์ ๊ทผ ๋ฐฉ์ ๋ชจ๋ join attribute์ ์ค๋ณต์ด ๋ง์ผ๋ฉด ์คํจ
- Fallback option: overflow๊ฐ ๋ฐ์ํ partition์ (indexed nested-loop join ๋์ ) block nested-loop join ์ฌ์ฉ
Complex Joins
- Conjunctive condition์ ์ฌ์ฉํ Join:
- nested-loop / block nested-loop join ์ฌ์ฉ, ๋๋
- ๋ ํจ์จ์ ์ธ algorithm์ ์ฌ์ฉํด ๋ ๊ฐ๋จํ join ( ๋ฑ) ์ค ํ๋์ ๊ฒฐ๊ณผ ๊ณ์ฐ
- ์ต์ข ๊ฒฐ๊ณผ๋ ๋จ์ ์กฐ๊ฑด ์ ๋ง์กฑํ๋ ์ค๊ฐ ๊ฒฐ๊ณผ์ tuple๋ก ๊ตฌ์ฑ
- ์ ์กฐ๊ฑด๋ค์ ์ tuple์ด ์์ฑ๋ ๋ ํ ์คํธ ๊ฐ๋ฅ
- Disjunctive condition์ ์ฌ์ฉํ Join:
- nested-loop / block nested-loop join ์ฌ์ฉ, ๋๋
- ๊ฐ๋ณ join ์ record๋ค์ ํฉ์งํฉ(union)์ผ๋ก ๊ณ์ฐ
Evaluation of Expressions
- ์ง๊ธ๊น์ง: ๊ฐ๋ณ ์ฐ์ฐ์ ์ํ algorithm ํ์ต
- ์ ์ฒด expression tree ํ๊ฐ๋ฅผ ์ํ ๋์
- Materialization: ์ ๋ ฅ์ด relation์ด๊ฑฐ๋ ์ด๋ฏธ ๊ณ์ฐ๋ expression์ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํ๊ณ , disk์ materialize (์ ์ฅ). ๋ฐ๋ณต
- Pipelining: ์ฐ์ฐ์ด ์คํ๋๋ ์ค์๋ tuple์ ์์(parent) ์ฐ์ฐ์ผ๋ก ์ ๋ฌ
Materialization
- Materialized evaluation
- ๊ฐ์ฅ ๋ฎ์ ์์ค(lowest-level)์์ ์์ํ์ฌ ํ ๋ฒ์ ํ๋์ ์ฐ์ฐ ํ๊ฐ
- ์ค๊ฐ ๊ฒฐ๊ณผ๋ฅผ ์์ relation์ materializeํ์ฌ ๋ค์ ์์ค(next-level) ์ฐ์ฐ ํ๊ฐ์ ์ฌ์ฉ
- ์: ์๋ ๊ทธ๋ฆผ์์, ๋ฅผ ๊ณ์ฐ ๋ฐ ์ ์ฅ
- ๊ทธ ๋ค์ instructor์์ join์ ๊ณ์ฐ ๋ฐ ์ ์ฅ, ๋ง์ง๋ง์ผ๋ก name์ ๋ํ projection ๊ณ์ฐ
- Materialized evaluation์ ํญ์ ์ ์ฉ ๊ฐ๋ฅ
- ๊ฒฐ๊ณผ๋ฅผ disk์ ์ฐ๊ณ ๋ค์ ์ฝ๋ ๋น์ฉ์ ์๋นํ ๋์ ์ ์์
- ์ฐ์ฐ์ ๋ํ ๋น์ฉ ๊ณต์์ ๊ฒฐ๊ณผ๋ฅผ disk์ ์ฐ๋ ๋น์ฉ์ ๋ฌด์ํ๋ฏ๋ก,
- ์ ์ฒด ๋น์ฉ = ๊ฐ๋ณ ์ฐ์ฐ ๋น์ฉ์ ํฉ + ์ค๊ฐ ๊ฒฐ๊ณผ๋ฅผ disk์ ์ฐ๋ ๋น์ฉ
- Double buffering: ๊ฐ ์ฐ์ฐ์ ๋ ๊ฐ์ output buffer ์ฌ์ฉ, ํ๋๊ฐ ์ฐจ๋ฉด disk์ ์ฐ๋ ๋์ ๋ค๋ฅธ ํ๋ ์ฑ์ฐ๊ธฐ
- Disk write์ ๊ณ์ฐ์ overlap ํ์ฉ, ์คํ ์๊ฐ ๋จ์ถ
Pipelining
- Pipelined evaluation
- ์ฌ๋ฌ ์ฐ์ฐ์ ๋์์ ํ๊ฐ,
- ํ ์ฐ์ฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋ค์ ์ฐ์ฐ์ผ๋ก ์ ๋ฌ
- ์: ์ด์ expression tree์์, ์ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ์ง ์์
- ๋์ , tuple์ join์ผ๋ก ์ง์ ์ ๋ฌ
- ์ ์ฌํ๊ฒ, join์ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ์ง ์๊ณ , tuple์ projection์ผ๋ก ์ง์ ์ ๋ฌ
- Materialization๋ณด๋ค ํจ์ฌ ์ ๋ ด
- ์์ relation์ disk์ ์ ์ฅํ ํ์ ์์
- Pipelining์ด ํจ๊ณผ์ ์ด๋ ค๋ฉด, tuple์ด ์์(upper) ์ฐ์ฐ์ input๋ ๋ output tuple์ ์์ฑํ๋ ํ์(lower) ์ฐ์ฐ evaluation algorithm ์ฌ์ฉ
- Pipeline์ ๋ ๊ฐ์ง ๋ฐฉ์์ผ๋ก ์คํ ๊ฐ๋ฅ
- Demand driven pipeline
- Producer driven pipeline
- Demand driven pipeline (๋๋ lazy evaluation)
- System์ด ์ต์์(top level) ์ฐ์ฐ์ ๋ค์ tuple์ ๋ฐ๋ณต์ ์ผ๋ก ์์ฒญ
- ๊ฐ ์ฐ์ฐ์ ๋ค์ output tuple์ ์ถ๋ ฅํ๊ธฐ ์ํด ํ์์ ๋ฐ๋ผ ํ์(children) ์ฐ์ฐ์ ๋ค์ tuple ์์ฒญ
- ํธ์ถ ์ฌ์ด์, ์ฐ์ฐ์ ๋ค์์ ๋ฐํํ ๊ฒ์ ์ ์ ์๋๋ก "์ํ(state)" ์ ์ง ํ์
- Producer-driven pipeline (๋๋ eager pipelining)
- ์ฐ์ฐ์(Operator)๊ฐ tuple์ ์ ๊ทน์ ์ผ๋ก(eagerly) ์์ฑํ๊ณ ์์(parent)๋ก ์ ๋ฌ
- ์ฐ์ฐ์ ์ฌ์ด์ buffer ์ ์ง: ํ์ ์ฐ์ฐ์๋ buffer์ tuple์ ๋ฃ๊ณ , ์์ ์ฐ์ฐ์๋ buffer์์ tuple ์ ๊ฑฐ
- buffer๊ฐ ๊ฐ๋ ์ฐจ๋ฉด, ํ์ ์ฐ์ฐ์๋ buffer ๊ณต๊ฐ์ด ์๊ธธ ๋๊น์ง ๊ธฐ๋ค๋ ธ๋ค๊ฐ ๋ ๋ง์ tuple ์์ฑ
- System์ output buffer์ ๊ณต๊ฐ์ด ์์ด ๋ ๋ง์ input tuple์ processํ ์ ์๋ ์ฐ์ฐ๋ค์ schedule (์คํ)
- ๋์์ ๋ช ์นญ: pull ๋ฐ push model์ pipelining
- Demand-driven pipelining ๊ตฌํ
- ๊ฐ ์ฐ์ฐ์ ๋ค์ ์ฐ์ฐ์ ๊ตฌํํ๋ iterator๋ก ๊ตฌํ๋จ
open()- ์: file scan์ ๊ฒฝ์ฐ: file scan ์ด๊ธฐํ
- state: file ์์ pointer
- ์: merge join์ ๊ฒฝ์ฐ: relation ์ ๋ ฌ;
- state: ์ ๋ ฌ๋ relation ์์ pointer
next()- ์: file scan์ ๊ฒฝ์ฐ: ๋ค์ tuple output, file pointer ์ด๋ ๋ฐ ์ ์ฅ
- ์: merge join์ ๊ฒฝ์ฐ: ๋ค์ output tuple์ด ๋ฐ๊ฒฌ๋ ๋๊น์ง ์ด์ state์์ merge ๊ณ์. pointer๋ฅผ iterator state๋ก ์ ์ฅ
close()
Pipelining: Blocking Operations
- Blocking operation: ๋ชจ๋ input์ด ์๋น๋ ๋๊น์ง output์ ์์ฑํ ์ ์๋ ์ฐ์ฐ
- ์: sorting, aggregation, โฆ
- ๊ทธ๋ฌ๋ ์ข ์ข tuple์ด ์์ฑ๋ ๋ ์๋นํ ์ ์์ผ๋ฉฐ, tuple์ด ์์ฑ๋ ๋ consumer์๊ฒ outputํ ์ ์์
- ํต์ฌ ์์ด๋์ด
- Blocking operation์ ์ข ์ข ๋ ๊ฐ์ ํ์ ์ฐ์ฐ (๋จ๊ณ)์ ๊ฐ์ง, ์
- Sort-merge: run generation ๋ฐ merge
- Hash join: partitioning ๋ฐ build-probe
- Blocking์ ์ค์ ๋ก ๋ ๋จ๊ณ ์ฌ์ด์์ ๋ฐ์ โ ์ด๋ค์ ๋ณ๋ ์ฐ์ฐ์ผ๋ก ์ทจ๊ธ
- ํ ๋จ๊ณ(stage)์ ๋ชจ๋ ์ฐ์ฐ์ ๋์์ ์คํ
- ํ ๋จ๊ณ๋ ์ด์ ๋จ๊ณ(stage)๊ฐ ์คํ์ ์๋ฃํ ํ์๋ง ์์ ๊ฐ๋ฅ
