<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Optimization on Dat Luong blog</title><link>https://datluongductuan.github.io/tags/optimization/</link><description>Recent content in Optimization on Dat Luong blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 11 Jan 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://datluongductuan.github.io/tags/optimization/index.xml" rel="self" type="application/rss+xml"/><item><title>[Case study] Tôi đã tối ưu 1 query PostgreSQL từ ~60s xuống còn ~2s như thế nào</title><link>https://datluongductuan.github.io/post/toi-uu-query-postgresql-60s-xuong-2s/</link><pubDate>Sat, 11 Jan 2025 00:00:00 +0000</pubDate><guid>https://datluongductuan.github.io/post/toi-uu-query-postgresql-60s-xuong-2s/</guid><description>TLDR;
Đánh index với WHERE mà WHERE chỉ filter được 50% rows thì planner PostgreSQL chọn seq scan (full table scan) vì hiệu quả hơn. PostgreSQL để cấu hình mặc định shared_buffer 128MB, mà tài nguyên RAM máy chủ đang có nhiều hơn → cần tăng lên để tận dụng hết tài nguyên. Dữ liệu query theo nghiệp vụ quá nhiều, từ 500MB đến 1GB cho 1 bảng xong câu lệnh SQL lại UNION ALL ghép lại → cần áp dụng một số cơ chế sử dụng bộ nhớ đệm như mview, cache superset hoặc thêm filter timestamp.</description></item></channel></rss>