EXPLAIN 비용 추정치와 행 수 읽기
EXPLAIN이 각 계획 노드에 지정하는 비용 수치, 예상 행 수, 너비 값을 해석하고 플래너의 추정이 잘못된 경우를 찾아내는 방법을 배워 보세요.
EXPLAIN 비용 추정치와 행 수 읽기은(는) CoddyKit의 무료 PostgreSQL Performance & Query Optimization 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 PostgreSQL Performance & Query Optimization 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. PostgreSQL Performance & Query Optimization 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
What the Cost Numbers Mean
Every node in an EXPLAIN plan shows a cost=startup..total pair. These are arbitrary planner units, not milliseconds. The planner uses them only to compare alternative plans and pick the cheapest one.
Startup vs Total Cost
The two numbers tell different stories:
- Startup cost: work before the first row is returned (e.g. building a hash table)
- Total cost: work to return all rows
A node that must sort or aggregate everything has a high startup cost.
A Sample Plan
Run EXPLAIN on a simple query and read the cost on each line.
EXPLAIN SELECT * FROM orders WHERE total > 100;The rows Estimate
Each node shows rows=N, the planner's estimated number of rows it will emit. The planner derives this from table statistics gathered by ANALYZE.
Bad estimates lead to bad plans, so this number matters a lot.
The width Value
The width=N field is the estimated average row size in bytes. Multiplied by rows it estimates memory and I/O needs, which influences whether sorts or hashes spill to disk.
Estimated vs Actual
EXPLAIN alone shows only estimates. Add ANALYZE to also run the query and see real timings and real row counts side by side.
EXPLAIN ANALYZE SELECT * FROM orders WHERE total > 100;Spotting Estimate Errors
Compare rows (estimate) with actual rows in EXPLAIN ANALYZE output. A large gap — say estimate 10 but actual 100000 — signals stale or insufficient statistics.
Why Estimates Drift
Estimates go stale when:
- Data changed a lot since the last
ANALYZE - Columns are correlated and the planner assumes independence
- The default statistics target is too low for skewed data
Refreshing Statistics
Run ANALYZE to recompute statistics for a table. Better stats produce better row estimates and therefore better plans.
ANALYZE orders;Raising the Statistics Target
For columns with skewed distributions, increase how many distinct values are sampled. A higher target means more accurate estimates at the cost of slightly slower ANALYZE.
ALTER TABLE orders ALTER COLUMN total SET STATISTICS 500;
ANALYZE orders;Cost Multipliers in postgresql.conf
Constants like seq_page_cost, random_page_cost, and cpu_tuple_cost scale how the planner weighs disk vs CPU. On SSDs, lowering random_page_cost makes index scans look cheaper.
Quick Check
Test your understanding of cost estimates.
Recap
You learned to read EXPLAIN's numbers:
- Cost is in arbitrary units; startup vs total cost differ
rowsandwidthare estimates from statistics- Compare estimated vs actual rows to spot bad stats
- Fix drift with
ANALYZEand a higher statistics target - Cost constants tune disk-vs-CPU weighting
AI 튜터와 함께 SQL을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 22
- 레슨
- 88
자주 묻는 질문
“EXPLAIN 비용 추정치와 행 수 읽기” 강의는 무료인가요?
네 — “EXPLAIN 비용 추정치와 행 수 읽기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 PostgreSQL Performance & Query Optimization 강의 전체를 잠금 해제할 수 있습니다. PostgreSQL Performance & Query Optimization 강의에는 총 4개의 강의가 포함되어 있습니다.
“EXPLAIN 비용 추정치와 행 수 읽기”에서 뭘 배우나요?
EXPLAIN이 각 계획 노드에 지정하는 비용 수치, 예상 행 수, 너비 값을 해석하고 플래너의 추정이 잘못된 경우를 찾아내는 방법을 배워 보세요. 브라우저에서 직접 실행하는 실습 코드로 PostgreSQL Performance & Query Optimization을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
PostgreSQL Performance & Query Optimization을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 PostgreSQL Performance & Query Optimization은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“EXPLAIN 비용 추정치와 행 수 읽기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 PostgreSQL Performance & Query Optimization 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 PostgreSQL Performance & Query Optimization 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- EXPLAIN 및 ANALYZE 소개
- 실행 계획 노드 해석
- 성능 병목 식별
- EXPLAIN 비용 추정치와 행 수 읽기