WW warin.me

DATA SYSTEMS · INTERACTIVE LAB

วิเคราะห์ไฟล์ตรงที่ไฟล์อยู่ โดยไม่ต้องตั้ง database server เพิ่ม

คำถามที่มีประโยชน์ไม่ใช่ “ฐานข้อมูลใดชนะ” แต่คือระบบหลีกเลี่ยง เลื่อนเวลา จัดเก็บ หรือทำงานส่วนใดซ้ำ

Checking isolated teaching runtimes…
ROWS10K
100K
1M
one deterministic sales model

เริ่มจากคำถามเดียว

เราหลีกเลี่ยงงานได้มากเพียงใด ก่อน operator เชิงวิเคราะห์จะเริ่มทำงาน

ลำดับที่แนะนำ

  1. เลือก 100,000 แถว แล้วรัน CSV scan ใช้เป็น baseline ของไฟล์แบบแถว
  2. ไม่เปลี่ยนขนาดข้อมูล แล้วรัน Parquet scan ตรวจว่าคำตอบเท่ากัน พร้อมเทียบ observed latency และรูปแบบจัดเก็บ
  3. รัน Filter + projection pushdown แล้วดู plan ว่า filter และคอลัมน์ที่ต้องการถูกผลักไปใกล้ขั้น scan หรือไม่
  4. รัน Window calculation เพื่อเก็บรายละเอียดรายแถวพร้อมบริบทเชิงวิเคราะห์ แล้วรัน ROLLUP เพื่อสรุปหลายระดับ grain
  5. รัน Precomputed summary เป็นขั้นสุดท้าย แยกให้ออกระหว่างความเร็วจากการใช้ผลที่เตรียมไว้ซ้ำ กับความเร็วที่เกิดจาก file format
runtime นี้สาธิตอะไรจริง

เว็บไซต์สอนนี้เริ่ม DuckDB local process ใหม่ในแต่ละ request เวลาที่แสดงจึงรวมต้นทุนเริ่ม process ด้วย

อ่านค่าระยะเวลาอย่างระมัดระวัง

ค่าที่แสดงคือ observed lab latency ไม่ใช่ benchmark สากลของฐานข้อมูล PostgreSQL ใช้ connection ที่เปิดค้างผ่าน PDO, DuckDB ต้องเริ่ม subprocess ในแต่ละ request ส่วน ClickHouse ติดต่อผ่าน HTTP และรายงาน engine elapsed time ของตนเอง อีกทั้งข้อมูลเพียง 10K–1M แถวมักอยู่ใน cache ได้มาก จึงควรเทียบ query plan จำนวนแถวและ byte ที่อ่าน ความสดของข้อมูล และต้นทุนการดูแล ก่อนเปรียบเทียบ millisecond

CONCEPT

A database can be a library, not a server.

DuckDB runs inside the existing web container and opens a local database or Parquet file. Projection and filter pushdown move selection into the scan, so unused columns and irrelevant row groups can be avoided before higher operators run.

CSV / Parquetembedded vector engineresult / local table

BOUNDED EXPERIMENT

Whitelist only · 25 s timeout · 2 CPU / 2 GB ClickHouse ceiling · one operation at a time

execution time
rows scanned
bytes read
rows returned

SQL

Select a bounded experiment.

Result

No result yet.

Explain / query plan

The physical plan appears after execution.
What happened?

Run an experiment, then connect the measurement to physical work.

Why CSV and Parquet do different work

CSV

Portable and visible, but values arrive as text. The engine must parse delimiters, recognize records and establish types before analytical operators receive vectors.

Parquet

Column types, compressed pages, statistics and row groups travel with the file. DuckDB can project needed columns and push eligible filters into the scan. File layout still matters.

Embedded boundary

No database server is listening. The controlled PHP endpoint starts a local DuckDB process against fixed paths and fixed SQL. This lowers service count, but concurrency and file ownership must remain bounded.