본문으로 건너뛰기

6.4 JIT와 planning overhead

JIT compilation은 expression evaluation과 tuple deformation을 빠르게 만들 수 있지만 compile overhead가 있습니다. 짧은 OLTP query에는 총 시간이 늘 수 있고 긴 analytical query에서는 이득이 날 수 있습니다.

EXPLAIN (ANALYZE, BUFFERS, SETTINGS)
SELECT customer_id, sum(amount * 1.1)
FROM orders
GROUP BY customer_id;

Plan의 JIT section과 planning, execution time을 봅니다. jit_above_cost 등 threshold는 planner cost를 기준으로 합니다.

SET LOCAL jit = off;

같은 query를 JIT on/off로 반복해 warm-up과 compile cache 조건을 기록합니다.

Planning time

Partition, index, join table이 매우 많거나 prepared statement를 충분히 재사용하지 않으면 planning 비중이 커질 수 있습니다. pg_stat_statements의 planning 통계를 활성화한 환경에서는 total과 mean plan time을 execution과 분리합니다.

PostgreSQL 18의 EXPLAIN (MEMORY)는 planning 단계 memory 정보를 제공합니다. 설치 version에서 option을 확인하고 schema 규모 변화와 비교합니다.

Planning 최적화와 execution 최적화는 병목이 다릅니다. 짧은 query가 초당 매우 많이 호출되면 작은 planning 비용도 총부하가 커집니다.