Fundamentals of Database Engineering
สรุปจาก Udemy course “Fundamentals of Database Engineering” โดย Hussein Nasser (~6 ชั่วโมง, ระดับ intermediate-advanced)
Overview
Course นี้สอน fundamentals และ first principles ของ database engineering — ไม่ใช่สอนใช้ Postgres/MySQL แต่สอนว่าทำไมเทคโนโลยีเหล่านี้ถึงมีอยู่ เพื่อให้เลือก database ได้ถูก, design schema ได้ดี, และเข้าใจว่าทำไม query ช้า/เร็ว
เนื้อหาทั้ง 18 Sections
Part 1 — Foundation Core (Section 1-7)
- Section 1: Course intro — mindset ของ database engineer
- Section 2: ACID — Atomicity, Consistency, Isolation, Durability + Transaction Isolation
- Section 3: Database Internals — Pages, Heap, IO, Row ID
- Section 4: Database Indexing — ทำไมต้อง index, EXPLAIN ANALYZE, scan types, pitfalls
- Section 5: Database Indexing — B-Tree vs B+Tree, MySQL vs Postgres storage cost
- Section 6: Database Partitioning — horizontal/vertical, range/list/hash, pros/cons
- Section 7: Database Sharding — vs partitioning, consistent hashing, pros/cons
Part 2 — Production Concerns (Section 8-12)
- Section 8: Concurrency Control — Shared/Exclusive locks, Deadlock, 2PL, Double Booking
- Section 9: Database Replication — Master/Backup, Multi-Master, Sync/Async, Eventual Consistency
- Section 10: Database System Design — ระบบจองที่นั่ง (booking system) จริง
- Section 11: Database Engines — InnoDB, MyISAM, RocksDB, LevelDB, B-Tree vs LSM-Tree
- Section 12: Database Cursors — Server/Client-side, Keyset Pagination
Part 3 — Advanced & Modern Topics (Section 13-18)
- Section 13: NoSQL — 4 ประเภท, MongoDB internals, SQL vs NoSQL
- Section 14: Database Security — TLS, SQL Injection, Password Hashing
- Section 15: Homomorphic Encryption — FHE concept, IBM toolkit
- Section 16: Q&A — NULL behavior, EXPLAIN cost unit, Bitmap vs Index Only Scan
- Section 17: Discussions — WAL, HOT Update, Bloom Filter, Connection Pooling, Redis vs Memcached
- Section 18: Archived Lectures — CAP Theorem, BASE, fsync deep dive
Key Takeaways 15 ข้อ (จาก course)
- Database อ่านทีละ page ไม่ใช่ทีละ row (Postgres 8KB, MySQL 16KB)
- ACID = หัวใจของ relational DB
- 4 Read Phenomena: Dirty Read, Non-repeatable Read, Phantom Read, Lost Update
- B+Tree เป็นมาตรฐาน — leaf nodes linked ทำให้ range query เร็ว
- EXPLAIN ANALYZE = เครื่องมือเทพสำหรับ tune query
- MySQL ใช้ clustered index, Postgres ใช้ heap-organized
- Partitioning = แบ่งใน DB เดียว / Sharding = แบ่งคนละ server
- Pessimistic Locking vs Optimistic — เลือกตาม contention
- Sync vs Async Replication — trade-off ระหว่างความปลอดภัยกับความเร็ว
- B-Tree DBs เก่ง read vs LSM-Tree DBs เก่ง write
- Row store (OLTP) vs Column store (OLAP) — ใช้ผิดช้าได้ 100x
- Connection Pooling สำคัญ — TCP+TLS handshake = 10-100ms
- NULL = unknown — ใช้
IS NULLไม่ใช่= NULL - อย่า SELECT * — ระบุ column ที่ใช้เสมอ
- Default ปี 2024+ → Postgres ก่อน แล้วค่อยเพิ่ม specialized DB ตามต้องการ
Pitfalls สำคัญ
| Pitfall | ทางแก้ |
|---|---|
WHERE LOWER(col) = 'x' | Functional index หรือ store lowercase |
LIKE '%text%' | Trigram index หรือ full-text search |
| Partition ผิด column | วิเคราะห์ query patterns ก่อน |
| Shard ก่อนวัด | Vertical scale + replicas ก่อน |
OFFSET 1000000 | Keyset pagination |
| String concatenation สร้าง SQL | Parameterized queries เสมอ |
Related
- PostgreSQL — DB หลักที่ course แนะนำเป็น default
- MySQL — เปรียบเทียบกับ Postgres ตลอด course
- MongoDB — ตัวอย่าง NoSQL ที่วิเคราะห์ลึก
- Redis — in-memory store ที่วิเคราะห์ architecture
- Memcached — เปรียบเทียบกับ Redis