Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2023-08-11] Intro to Database Systems 8๊ฐ• - B+Tree Index #8

Open
jonyejin opened this issue Aug 7, 2023 · 3 comments
Open
Assignees
Labels
Database ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๐Ÿ“ ์Šคํ„ฐ๋”” ์ผ์ง€ ์Šคํ„ฐ๋”” ์ผ์ง€

Comments

@jonyejin
Copy link

jonyejin commented Aug 7, 2023

๐Ÿ“Œ ๊ฐœ์š”

  • ์‹œ๊ฐ„: 2023-08-11(๊ธˆ) 22:00
  • ์ž๋ฃŒ: 8๊ฐ• B+Tree Indexes
  • ์ฐธ์—ฌ์ž: ํŽญ๊ท„, ๊ทธ๋ฃจํŠธ, ๋ ‰์‚ฌ, ๋‚˜๊ฐ•

โœ๏ธ ์ค€๋น„

์•„๋ž˜ ์–‘์‹์„ ๋ณต์‚ฌํ•ด ์Šคํ„ฐ๋”” ์ค€๋น„๋ฅผ ์™„๋ฃŒํ•ด์ฃผ์„ธ์š”!

## ๐Ÿ’ฌ ์ƒ๊ฐ

<!--๊ฐ•์˜๋ฅผ ๋“ฃ๊ณ  ์ƒ๊ฐํ•œ ๋‚ด์šฉ์„ 3์ค„ ๋‚ด๋กœ ๊ฐ„๋‹จํžˆ ์ •๋ฆฌํ•ด์ฃผ์„ธ์š”!-->

- ...

## โ“ ์งˆ๋ฌธ

<!--๊ณต๋ถ€ํ•˜๋ฉด์„œ ๊ถ๊ธˆํ•œ ์ ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!-->

- ...

## ๐Ÿ“š ์ฐธ๊ณ  ์ž๋ฃŒ

<!--๊ณต๋ถ€ํ•˜๋ฉด์„œ ๊ฐ™์ด ๊ณต๋ถ€ํ•œ ์ž๋ฃŒ๋ฅผ ์ฒจ๋ถ€ ๋ฐ ๊ณต์œ ํ•ด์ฃผ์„ธ์š”!-->

- [...](...)
@jonyejin
Copy link
Author

jonyejin commented Aug 7, 2023

โœ”๏ธ ๋‚ด์šฉ ์ •๋ฆฌ

  • Table Index๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ Hash Table์ด ์•„๋‹ˆ๋ผ B+Tree๋ฅผ ์“ฐ๋Š” ์ด์œ ?

B+Tree

  • ํ•ญ์ƒ sort ๋˜์–ด์žˆ๋‹ค
  • BST์˜ ์ผ๋ฐ˜ํ™” (2๊ฐœ ์ด์ƒ์˜ child node ๊ฐ€๋Šฅ) -> ๋ฒ”์œ„๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•จ.
  • ์ง„์งœ ์ž˜๋งŒ๋“  ์ž๋ฃŒ๊ตฌ์กฐ ๊ฐ™์•„์š”. ๊ทผ๋ฐ ๋ฃจํŠธ ํฌ์ธํ„ฐ๊ฐ€ ๊ณ„์† ๋ฐ”๋€Œ๋‚˜์š”?
  • selectํ•˜๋Š” ๋ฐฉ์‹ ๋ฐฐ์šฐ๊ธฐ
  • ์ค‘๋ณตํ‚ค ์‚ฝ์ž…ํ•˜๋Š” ๋ฐฉ๋ฒ• ๋ฐฐ์šฐ๊ธฐ: leaf node๋ฅผ ํ•˜๋‚˜ ๋” ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ํ•œ๋‹ค๊ณ  ํ•จ.
  • clustered index: PK ์“ฐ๋Š”๊ฑฐ๊ตฌ๋‚˜

๐Ÿ’ฌ ์ƒ๊ฐ

  • ํ•ญ์ƒ tree๋ผ๋Š” ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์ปดํ“จํ„ฐ์—์„œ ๋งŽ์ด ์“ฐ๋Š” ์ด์œ ๋ฅผ, ๋ฉ”๋ชจ๋ฆฌ ํ™œ์šฉํ•˜๊ธฐ ์ข‹์€ ์ž๋ฃŒ๊ตฌ์กฐ๋ผ์„œ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ ์ด๊ฒŒ ๋งž๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค

โ“ ์งˆ๋ฌธ

  • pointer swizzling..? DB์ฃผ์†Œ(๋ฌผ๋ฆฌ์ ) -> ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ(๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ์ฃผ์†Œ)???

Nodes use page ids to reference other nodes in the index. The DBMS must get the memory location from the page table during traversal.
If a page is pinned in the buffer pool, then we can store raw pointers instead of page ids. This avoids address lookups from the page table.

๐Ÿ“š ์ฐธ๊ณ  ์ž๋ฃŒ

@CoodingPenguin CoodingPenguin added ๐Ÿ“ ์Šคํ„ฐ๋”” ์ผ์ง€ ์Šคํ„ฐ๋”” ์ผ์ง€ Database ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค labels Aug 7, 2023
@CoodingPenguin CoodingPenguin changed the title [2023-08-11] Intro to Database Systems 7๊ฐ• - Tree Index [2023-08-11] Intro to Database Systems 8๊ฐ• - Tree Index Aug 7, 2023
@CoodingPenguin CoodingPenguin changed the title [2023-08-11] Intro to Database Systems 8๊ฐ• - Tree Index [2023-08-11] Intro to Database Systems 8๊ฐ• - B+Tree Index Aug 8, 2023
@CoodingPenguin
Copy link
Member

CoodingPenguin commented Aug 8, 2023

๐Ÿ’ฌ ์ƒ๊ฐ

  • ์ด๋ฒˆ ๊ฐ•์˜ ๋‚ด์šฉ์€ B+ Tree์— ๊ด€ํ•œ ๋‚ด์šฉ์ด ์ „๋ถ€์˜€๋˜ ๊ฒƒ ๊ฐ™๋‹ค.
  • ์ „์— ํ•œ ๋ฒˆ ๊ณต๋ถ€ํ•œ ์ ์ด ์žˆ์–ด์„œ ๋‚ด์šฉ์„ ์ดํ•ดํ•˜๋Š”๋ฐ ์–ด๋ ต์ง€๋Š” ์•Š์•˜์ง€๋งŒ, ์ƒ๊ฐ๋ณด๋‹ค ์„ค๋ช…ํ•˜๋Š” ๊นŠ์ด๊ฐ€ ์–•์•˜๋˜ ๊ฒƒ ๊ฐ™๋‹ค.

โ“ ์งˆ๋ฌธ

  • Leaf Node Value๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์ด 2๊ฐ€์ง€ ์žˆ์—ˆ๋Š”๋ฐ ๊ทธ ์ค‘ "Tuple Data" ๋ฐฉ์‹์ด ์ž˜ ์ดํ•ด๊ฐ€ ์•ˆ ๊ฐ„๋‹ค.

๐Ÿ“š ์ฐธ๊ณ  ์ž๋ฃŒ

@Nagunt
Copy link
Contributor

Nagunt commented Aug 10, 2023

๐Ÿ’ฌ ์ƒ๊ฐ

  • B+Tree์— ๋Œ€ํ•œ ๊ฐ•์˜
  • B์˜ ๋œป์€ ๋ชจ๋ฅด์ง€๋งŒ ์•„๋งˆ๋„ Balanced? (๊ต์ˆ˜ ํ”ผ์…œ)
    • ํ•ญ์ƒ ์ •๋ ฌ๋˜์–ด ์žˆ๋Š” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ. ๋ชจ๋“  Action์˜ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ O(log N)์ด๋‹ค. ์ฆ‰ ๋น ๋ฅด๊ณ  ํšจ์œจ์ ์ด๋‹ค.
    • ์‹ค์งˆ์ ์ธ ๋ฐ์ดํ„ฐ๋Š” ๋งจ ๋๋‹จ (leaf node)์—๋งŒ ์ €์žฅ๋˜๋ฉฐ, ์ค‘๊ฐ„ ๋…ธ๋“œ๋Š” ์˜ค์ง ํƒ์ƒ‰์„ ์œ„ํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ. ์ด์ œ๊นŒ์ง€ ์•Œ๊ณ  ์žˆ๋˜ tree ๊ตฌ์กฐ์™€๋Š” ๋‹ค๋ฅธ ์ ์ด ์‹ ๊ธฐํ–ˆ๋‹ค.
    • ์‚ฝ์ž… ์‹œ ๋นˆ ๊ณต๊ฐ„์ด ์—†๋‹ค๋ฉด : append or overflow
      • append : ๊ธฐ์กด ๊ณต๊ฐ„์„ ํ™•์žฅ, ๋ถ„ํ• ํ•ด์„œ ์‚ฝ์ž…. leaf node ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ค‘๊ฐ„ ๋…ธ๋“œ๋„ ์ˆ˜์ •ํ•ด ์ค˜์•ผ ํ•จ.
      • overflow : ๊ธฐ์กด ๊ณต๊ฐ„์„ ํ™•์žฅํ•˜๋Š” ๊ฒƒ์€ ๋™์ผํ•˜์ง€๋งŒ ์˜ค์ง leaf node๋งŒ ํ™•์žฅํ•ด์„œ ์‚ฌ์šฉํ•œ๋‹ค. ๋‹ค๋ฅธ leaf node์™€ ํฌ๊ธฐ๊ฐ€ ๋‹ฌ๋ผ์ง€๋Š” ๋ฌธ์ œ (๋ณต์žกํ•ด์ง)
    • Cluster, Index Scan

๐Ÿ“š ์ฐธ๊ณ  ์ž๋ฃŒ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Database ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๐Ÿ“ ์Šคํ„ฐ๋”” ์ผ์ง€ ์Šคํ„ฐ๋”” ์ผ์ง€
Projects
None yet
Development

No branches or pull requests

4 participants