Files
progcode/web/public/assets/editorial/2019/sql-indexes-selectivity-2019.svg
T
huncode bbedf1ae87
Build and deploy / deploy (push) Successful in 14s
revise July 2019 SQL articles
2026-07-31 10:37:50 +03:00

48 lines
3.5 KiB
XML

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 760 620" role="img" aria-labelledby="title desc">
<title id="title">Селективность определяет ценность индекса</title>
<desc id="desc">Из миллиона заказов условие ready оставляет девятьсот девяносто тысяч строк, а waiting десять тысяч. Для обоих существует индекс, но для частого значения последовательное чтение может быть дешевле.</desc>
<defs>
<style>
.bg { fill: #f8fafc; }
.card { fill: #ffffff; stroke: #cbd5e1; stroke-width: 2; }
.source { fill: #e0f2fe; stroke: #0284c7; stroke-width: 2; }
.hot { fill: #fff7ed; stroke: #ea580c; stroke-width: 2; }
.cold { fill: #ecfdf5; stroke: #059669; stroke-width: 2; }
.note { fill: #eff6ff; stroke: #2563eb; stroke-width: 2; }
.title { font: 700 25px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #0f172a; }
.label { font: 700 18px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #0f172a; }
.text { font: 16px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #334155; }
.small { font: 14px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: #475569; }
.mono { font: 600 15px ui-monospace, SFMono-Regular, Menlo, monospace; fill: #0f172a; }
.line { stroke: #64748b; stroke-width: 3; fill: none; marker-end: url(#arrow); }
</style>
<marker id="arrow" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#64748b" />
</marker>
</defs>
<rect class="bg" width="760" height="620" rx="28" />
<text class="title" x="42" y="52">Индекс — кандидат; селективность решает цену</text>
<rect class="source" x="210" y="82" width="340" height="86" rx="14" />
<text class="label" x="290" y="119">work_orders</text>
<text class="text" x="272" y="148">1 000 000 строк после ANALYZE</text>
<path class="line" d="M300 170 L185 236" />
<path class="line" d="M460 170 L575 236" />
<rect class="hot" x="42" y="246" width="292" height="168" rx="14" />
<text class="mono" x="66" y="281">WHERE state = 'ready'</text>
<text class="label" x="66" y="320">990 000 строк</text>
<text class="text" x="66" y="350">почти вся таблица</text>
<text class="small" x="66" y="382">индекс + heap-обращения</text>
<text class="small" x="66" y="403">могут стоить дороже Seq Scan</text>
<rect class="cold" x="426" y="246" width="292" height="168" rx="14" />
<text class="mono" x="448" y="281">WHERE state = 'waiting'</text>
<text class="label" x="448" y="320">10 000 строк</text>
<text class="text" x="448" y="350">около 1% таблицы</text>
<text class="small" x="448" y="382">индекс может сузить путь</text>
<text class="small" x="448" y="403">проверяем фактическим планом</text>
<path class="line" d="M188 416 L285 482" />
<path class="line" d="M572 416 L475 482" />
<rect class="note" x="126" y="492" width="508" height="88" rx="14" />
<text class="label" x="164" y="527">EXPLAIN (ANALYZE, BUFFERS)</text>
<text class="text" x="164" y="555">сравнить rows, actual rows, loops и Buffers до нового CREATE INDEX</text>
</svg>