MongoDB Sorting with Indexes

λ°±μ—”λ“œΒ·2023λ…„ 6μ›” 14일
0

MongoDB

λͺ©λ‘ 보기
3/9

πŸ“Œ Method For Sortings

  1. In memory
  2. Using an Index

πŸ”Ž 1. In memory

  • collection에 μžˆλŠ” λ¬Έμ„œλŠ” λ¬΄μž‘μœ„λ‘œ λ””μŠ€ν¬μ— μ €μž₯λ˜λ―€λ‘œ 쿼리할 λ•Œ λ¬Έμ„œλŠ” μ„œλ²„κ°€ μ°ΎλŠ” μˆœμ„œμ™€ λ™μΌν•˜κ²Œ λ°˜ν™˜λœλ‹€.
  • μ„œλ²„κ°€ μ°ΎλŠ” μˆœμ„œμ™€ λ™μΌν•˜κ²Œ μ €μž₯되있으면 μ’‹κ² μ§€λ§Œ, 그럴 κ°€λŠ₯성은 거의 μ—†λ‹€.
    => 이것은 정렬을 μœ„ν•΄μ„œ Diskμ—μ„œ RAM으둜 λ¬Έμ„œλ₯Ό 읽어야 ν•œλ‹€λŠ” 것을 μ˜λ―Έν•œλ‹€
  • 그런 λ‹€μŒ RAMμ—μ„œ μΌμ’…μ˜ μ•Œκ³ λ¦¬μ¦˜μ„ μˆ˜ν–‰ν•˜μ—¬ μ •λ ¬ μž‘μ—…μ„ μ§„ν–‰ν•˜κ³ , λ¬Έμ„œ μˆ˜μ— 따라 μ‹œκ°„μ΄ 였래 걸릴 μˆ˜λ„ μžˆλ‹€.

2. Using an Index

  • 쿼리가 인덱슀 μŠ€μΊ”μ„ μ‚¬μš© ν•  경우, λ°˜ν™˜λœ λ¬Έμ„œμ˜ μˆœμ„œλŠ” 인덱슀 ν‚€λ‘œ μ •λ ¬λœλ‹€.
    => μ΄λŠ” μ„œλ²„μ—μ„œ λ¬Έμ„œλ₯Ό μ •λ ¬λœ μˆœμ„œλ‘œ κ°€μ Έμ˜€κΈ° λ•Œλ¬Έμ—, μ •λ ¬ μž‘μ—…μ„ λ”°λ‘œ μˆ˜ν–‰ ν•  ν•„μš”κ°€ μ—†μŒμ„ μ˜λ―Έν•œλ‹€

ref: https://learn.mongodb.com/learn/course/m201-mongodb-performance/lesson-2-mongodb-indexes/learn?client=customer&page=8

profile
λ°±μ—”λ“œ 개발자

0개의 λŒ“κΈ€