PostgreSQL 실행 계획 조언

PostgreSQL plan advice

PostgreSQL 19 베타의 pg_plan_advice 확장은 플래너 선택을 안정화하거나 제어합니다.

···
html
<div class="demo"><div class="head"><b>PLAN ADVICE</b><span>same query</span></div><div class="stage advice"><div class="plan"><strong>planner</strong><div class="cell" id="plain">Seq Scan</div><small>orders</small></div><div class="switch">→</div><div class="plan"><strong>with advice</strong><div class="cell on" id="advised">Index Scan</div><small>orders_idx</small></div></div><div class="foot"><span id="advstatus">compare candidate plans</span><span>PG 19 beta</span></div></div>
css
*{box-sizing:border-box}.demo{width:min(96vw,820px);height:min(94vh,350px);padding:clamp(8px,2vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--fg);display:flex;flex-direction:column;gap:clamp(5px,1.5vmin,12px);font:600 clamp(12px,3.5vmin,15px)/1.25 var(--font-sans),sans-serif;overflow:hidden}.head,.foot,.row{display:flex;justify-content:space-between;align-items:center;gap:8px}.head b{color:var(--accent)}.head span,.foot,.muted{color:var(--muted)}.stage{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;gap:8px}.cell,.pill{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(4px,1.2vmin,9px);text-align:center}.pill{border-radius:999px}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 17%,var(--surface))!important;color:var(--fg)!important}.bad{border-color:#e16a5d!important;background:color-mix(in srgb,#e16a5d 18%,var(--surface))!important}.foot{font-size:clamp(12px,3vmin,14px)}.advice{justify-content:space-around}.plan{min-width:37%;display:grid;gap:4px;text-align:center}.plan strong{color:var(--muted)}.plan small{font:600 clamp(11px,2.8vmin,13px) ui-monospace,monospace;color:var(--muted)}.switch{font-size:clamp(19px,5vmin,28px);color:var(--accent)}.plan .cell{transition:.3s}
js
let n=0;function tick(){document.getElementById('plain').classList.toggle('on',!n);document.getElementById('advised').classList.toggle('on',!!n);document.getElementById('advstatus').textContent=n?'advice selects Index Scan':'planner selects Seq Scan';n=1-n}tick();const t=setInterval(tick,1100);document.querySelector('.demo').onclick=()=>{clearInterval(t);tick()}

PostgreSQL 19 베타에는 쿼리 플래너의 결정을 조정하는 pg_plan_advice 확장이 추가됐습니다. pg_stash_advice 확장은 쿼리 식별자별로 조언을 자동 적용할 수 있습니다.

데모는 같은 질의의 후보 실행 계획과 조언을 적용한 계획을 나란히 보여줍니다. 조언을 고정하면 데이터 분포가 바뀌어도 예전 선택이 남을 수 있으므로 실제 실행 시간과 계획을 다시 측정해야 합니다. 두 확장 모두 베타 기능입니다.

언제 쓰나

실행 계획 변동이 실제 병목을 만들 때 근거를 측정하고 제한적으로 평가합니다.

페이지로 열기 ↗