索引結構練習題 (Practice - Database Indexing)


Part 1:Database Indexing 概論

Q1(Recall):沒有索引的情況下資料庫如何查詢?建立索引後呢?


Q2(Recall):索引能加速哪些操作?


Q3(Recall):索引有哪三個主要缺點?


Q4(Application):在什麼欄位上建索引通常最划算?什麼欄位不該建?


Part 2:B-Tree Index

Q5(Recall):B-Tree 的三個核心特性是什麼?


Q6(Recall):B-Tree 和 B+Tree 的主要差異是什麼?MySQL InnoDB 使用哪一種?


Q7(Recall):B-Tree 索引支援哪些查詢操作?


Q8(Application):PostgreSQL 在建立 PRIMARY KEYUNIQUE 約束時,會自動建立什麼類型的索引?


Part 3:LSM Tree

Q9(Recall):B-Tree 和 LSM Tree 各自最適合什麼工作負載?為什麼?


Q10(Recall):LSM Tree 的寫入流程是什麼?(三個關鍵步驟)


Q11(Recall):什麼是 Write Amplification?Bloom Filter 在 LSM Tree 中扮演什麼角色?


Q12(Application):你在設計一個「使用者行為 log 收集系統」,每秒有 10 萬條 event 寫入,讀取相對少。B-Tree 或 LSM Tree 比較適合?為什麼?


Q13(Analysis):LSM Tree 的 Compaction 為什麼必要?會帶來什麼代價?


Part 4:Hash Index

Q14(Recall):是非題 — Hash Index 支援範圍查詢(如 WHERE age > 25)。


Q15(Recall):Hash Index 碰撞(collision)的兩種常見處理方式是什麼?


Q16(Application):Hash Index 和 B-Tree Index 各自在什麼場景更有優勢?


Q17(Analysis):為什麼 MySQL InnoDB 預設用 B+Tree 而不是 Hash Index?


Part 5:Geospatial Index

Q18(Recall):為什麼一般 B-Tree 索引(分別建在 latitudelongitude 上)不適合鄰近搜尋?


Q19(Recall):以下哪種地理空間索引是將 2D 座標轉成 1D 字串,使得鄰近的點共享相同前綴?
(A) R-Tree (B) Quadtree (C) Geohash (D) Hash Index


Q20(Recall):R-Tree 和 Quadtree 的核心差異是什麼?哪個是現代生產環境的標準選擇?


Q21(Application):你要幫 Uber 設計叫車系統,需要頻繁查詢「附近 3km 的司機」和計算區域內司機密度。應該選哪種地理索引?為什麼?


Part 6:Inverted Index

Q22(Recall):Forward Index 和 Inverted Index 的核心差異是什麼?


Q23(Recall):查詢 "apple AND dog" 時,Inverted Index 如何運作?


Q24(Application):列舉一個使用 Inverted Index 的知名系統,以及它屬於哪類應用。


Q25(Analysis):Phrase Query "apple pie" 需要 posting list 包含什麼資訊?請說明比對過程。