forked from mtusi2026/mtusi2026lab2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Index sizes of every variant on the SAME 121 120-row dataset (no writes in between).
|
|
|
|
python bench/track2/index_sizes.py # ~2 min, writes evidence/track2/index-sizes.csv
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import csv
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
import plans # noqa: E402 (same image, limits, schema and deterministic seed)
|
|
|
|
|
|
def main() -> int:
|
|
plans.start_container("2", "2g")
|
|
try:
|
|
plans.psql("".join(p.read_text(encoding="utf-8") for p in sorted((plans.ROOT / "migrations").glob("*.sql"))))
|
|
plans.psql(plans.SEED)
|
|
rows = int(plans.psql("SELECT count(*) FROM messages;"))
|
|
out = []
|
|
for variant in plans.VARIANTS:
|
|
info = plans.use_variant(variant)
|
|
secondary = sum(int(b) for name, b in info["index_bytes"].items() if name != "messages_pkey")
|
|
out.append({"variant": variant, "rows": rows, "table_bytes": info["table_bytes"],
|
|
"pkey_bytes": int(info["index_bytes"]["messages_pkey"]), "secondary_index_bytes": secondary,
|
|
"secondary_bytes_per_row": round(secondary / rows, 1), "index_build_seconds": info["index_build_s"]})
|
|
print(out[-1], flush=True)
|
|
finally:
|
|
plans.sh(["docker", "rm", "-f", "-v", plans.CLIENT, plans.NAME], check=False)
|
|
path = plans.ROOT / "evidence/track2/index-sizes.csv"
|
|
with path.open("w", newline="", encoding="utf-8") as f:
|
|
writer = csv.DictWriter(f, fieldnames=list(out[0]))
|
|
writer.writeheader()
|
|
writer.writerows(out)
|
|
print("done:", path)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|