Relational Algebra

์•„์ฃผ๋Œ€ํ•™๊ต ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์ˆ˜์—….

Posted by Bangjinhyuk on March 16, 2021 · 1 min read

Database

  • ํ—ท๊ฐˆ๋ฆฌ๋Š”๊ฑฐ ํ–‰ - Row- ๊ฐ€๋กœ / ์—ด - Column - ์„ธ๋กœ

Relational Algebra ์ฟผ๋ฆฌ๋“ค

  1. relation name => ์ˆœ์ˆ˜ ํ…Œ์ด๋ธ” ์ด๋ฆ„๋„ ์ฟผ๋ฆฌ์ด๋‹ค.

  2. Select operator
    • ํ•œํ…Œ์ด๋ธ” ๋‚ด์—์„œ ํŠœํ”Œ๋“ค์„ ์ฐพ๋Š” ์ฟผ๋ฆฌ
    • ์˜ˆ์‹œ =>
      • r ํ…Œ์ด๋ธ”์—์„œ A = B ์ด๊ณ  D > 5์ธ ํŠœํ”Œ์„ ์ฐพ์•„๋ผ
  3. Project operator
    • ์—ด์„ ์ฐพ๋Š” ์ฟผ๋ฆฌ
    • ์ค‘๋ณต๋œ ํ–‰์ด ์žˆ์œผ๋ฉด ์ œ๊ฑฐ <์ค‘์š” no="" duplicate="">
    • ์˜ˆ์‹œ =>
      • r ํ…Œ์ด๋ธ”์—์„œ A์™€ C์†์„ฑ์„ ์ถ”์ถœํ•ด๋ผ
  4. Select+Project ํ˜ผํ•ฉ ์—ฐ์‚ฐ
    • Select ๋จผ์ € ํ•œ๋’ค์— Project
    • ์˜ˆ์‹œ =>
      • Employee ํ…Œ์ด๋ธ”(relation)์•ˆ์— EmpNo = 2106 ์ธ Rows ์ค‘์—์„œ EmpName, Title Columns๋ฅผ ๋ณด์—ฌ์ค˜๋ผ
  5. Cross-product (cartesian product)
    • ๋‘ ํ…Œ์ด๋ธ”์„ ํ•ฉ์น˜๋Š”๊ฒƒ
    • ๋‘ ๋ฐ์ด๋ธ”์˜ tuple ๊ฐœ์ˆ˜์˜ ๊ณฑ๋งŒํผ tuple ์ด ์ƒ์„ฑ m*n
    • ์˜ˆ์‹œ =>
      • ๋ฆด๋ ˆ์ด์…˜ r๊ณผ s๋ฅผ ํฌ๋กœ์Šค ํ”„๋กœ๋•ํŠธํ•ด๋ผ.
    • ์˜ˆ์‹œ =>
      • ํฌ๋กœ์Šค ํ”„๋กœ๋•ํŠธํ•œ ๋ฆด๋ ˆ์ด์…˜์—์„œ ์†์„ฑ A์™€ C๊ฐ€ ๊ฐ™์€ ํŠœํ”Œ์„ ์„ ํƒํ•ด๋ผ.
  6. Natural Join
    • ๋‘๊ฐœ์˜ relations
    • ๊ฐ™์€ ์ด๋ฆ„์˜ attribute๊ฐ€ ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค.
    • ์ค‘๋ณต๋œ attributes๋Š” ์ œ๊ฑฐ
    • Cross-product์— ๊ฐ™์€ ์†์„ฑ์˜ ๊ฐ™์€ ๊ฐ’์„ ์ฐพ๋Š” ์กฐ๊ฑด์„ ์ถ”๊ฐ€ํ•œ๊ฒƒ๊ณผ ๊ฐ™์Œ(๋ฐ‘์— ์˜ˆ์‹œ ๋ณด๊ธฐ)
    • ์˜ˆ์‹œ =>
  7. Theta Join
    • cross product๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ณ , selection์„ ์ˆ˜ํ–‰ํ•œ๋‹ค.
    • Natural join์€ Theta join์˜ ํŠน๋ณ„ํ•œ ํ•œ ์˜ˆ์ด๋‹ค.
    • ์ˆ˜์‹ =>

์š”์•ฝ

  • ์ฟผ๋ฆฌ์˜ ๊ฒฐ๊ณผ๋Š” relation ์ด๋‹ค.
  • ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ์ฟผ๋ฆฌ=> relation name
  • filter => select
  • slice => project
  • combine => cross-product, natural join, theta join

์ฐธ๊ณ  ์ž๋ฃŒ

๋งจ์œ„๋กœ๐Ÿ‘†