Query Optimization is the process of improving the performance of a database query by making it execute faster, use fewer resources, and return accurate results efficiently.
🔍 Why is it needed?
To reduce query execution time
To minimize memory and CPU usage
To avoid unnecessary table scans or joins
To scale systems with heavy traffic or large data
⚙️ How Query Optimization Works
When you send a query, the DBMS query optimizer:
Parses the query
Generates multiple query execution plans
Chooses the most efficient plan based on cost estimation (CPU, I/O, memory)
✅ Best Practices for Query Optimization
Tip | Example |
|---|---|
Use indexes | Use an index on |
Avoid SELECT * | Use |
Use LIMIT | To return only needed rows |
Avoid subqueries if joins work better | Use |
Use EXPLAIN | To analyze query execution plan |
Avoid unnecessary joins | Remove joins that don’t contribute to output |
Filter early | Push filtering to WHERE before joining |
Partition large tables | So only a subset is scanned |
🔍 SQL Example
-- Poor query
SELECT * FROM orders WHERE YEAR(order_date) = 2023;
-- Optimized query (with indexed column)
SELECT * FROM orders WHERE order_date >= '2023-01-01' AND order_date < '2024-01-01';🧠 Database Connection Pooling
Database Connection Pooling is a technique where a pool (cache) of reusable database connections is maintained so that each query doesn’t have to create a new connection, which is expensive.
⚠️ Problem Without Pooling
Opening and closing DB connections repeatedly is slow and resource-intensive.
For high-traffic apps, this causes latency, timeouts, or exhausted DB resources.
✅ Benefits of Connection Pooling
Benefit | Description |
|---|---|
🚀 Speed | No need to repeatedly create new connections |
🔄 Reusability | Idle connections are reused |
📈 Scalability | Can handle more users with fewer resources |
🧠 Efficiency | Reduces overhead on both client and DB server |
⚙️ How It Works
Client Request → Pool Manager:
- If free connection exists → Reuse it
- Else → Wait or create new one (up to limit)
- After query → Return connection to pool🧪 Example (Node.js + MySQL)
const mysql = require('mysql');
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'root',
password: '',
database: 'mydb'
});
// Use a pooled connection
pool.query('SELECT * FROM users', function (error, results) {
if (error) throw error;
console.log(results);
});<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Query Optimization & Connection Pooling</title>
<style>
.infographic-queryopt {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--good: #16a34a;
--good-soft: #dcfce7;
--bad: #dc2626;
--bad-soft: #fee2e2;
--on-accent: #ffffff;
--display-font: Georgia, 'Iowan Old Style', serif;
--body-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
--mono-font: 'SF Mono', Consolas, monospace;
background: var(--paper);
color: var(--ink);
font-family: var(--body-font);
max-width: 840px;
margin: 0 auto;
box-sizing: border-box;
overflow-x: hidden;
}
.infographic-queryopt[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--good: #4ade80;
--good-soft: #123420;
--bad: #f87171;
--bad-soft: #3a1414;
--on-accent: #101418;
}
.infographic-queryopt * { box-sizing: border-box; }
.qo-head { text-align: center; margin-bottom: 0.25rem; }
.qo-head h2 { font-family: var(--display-font); font-size: 1.85rem; margin: 0 0 0.5rem; }
.qo-head p { color: var(--ink-soft); font-size: 0.95rem; margin: 0 auto; max-width: 600px; line-height: 1.55; }
.qo-tabs { display: flex; gap: 0.5rem; margin-top: 1.5rem; flex-wrap: wrap; justify-content: center; }
.qo-tab-btn {
font: inherit; font-size: 0.85rem; background: var(--paper-alt); color: var(--ink-soft);
border: 1px solid var(--line); border-radius: 999px; padding: 0.5rem 1rem; cursor: pointer;
}
.qo-tab-btn.is-active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.qo-panel { display: none; background: var(--paper-alt); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; margin-top: 1rem; }
.qo-panel.is-active { display: block; animation: qo-fade-in 0.35s ease; }
@keyframes qo-fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.qo-panel-title { font-family: var(--display-font); font-size: 1.15rem; margin: 0 0 0.4rem; }
.qo-panel-desc { font-size: 0.85rem; color: var(--ink-soft); line-height: 1.5; margin: 0 0 0.9rem; }
.qo-code-scroll { overflow-x: auto; margin-bottom: 1rem; }
.qo-code {
background: var(--ink); color: #d4e2ff; border-radius: 8px; padding: 0.75rem 0.95rem;
font-family: var(--mono-font); font-size: 0.76rem; line-height: 1.55; white-space: pre;
}
.infographic-queryopt[data-theme="dark"] .qo-code { background: #05070a; }
.qo-kw { color: #9cc5ff; } .qo-str { color: #f8d980; } .qo-num { color: #4ade80; } .qo-cm { color: #7c8aa8; } .qo-fn { color: #f472b6; }
.qo-diagram-scroll { overflow-x: auto; }
.qo-diagram-scroll svg { width: 100%; height: auto; display: block; min-width: 380px; }
.qo-row-rect { fill: var(--paper); stroke: var(--line); stroke-width: 1; transition: fill 0.3s, opacity 0.3s; }
.qo-row-rect.is-scanned { fill: var(--bad-soft); }
.qo-row-rect.is-matched { fill: var(--good-soft); }
.qo-row-rect.is-skipped { opacity: 0.3; }
.qo-cell-text { font-size: 10px; font-family: var(--mono-font); text-anchor: middle; fill: var(--ink); }
.qo-run-row { display: flex; justify-content: center; gap: 0.6rem; margin-top: 1.1rem; flex-wrap: wrap; }
.qo-run-btn {
font: inherit; font-size: 0.83rem; background: var(--accent); color: var(--on-accent);
border: none; border-radius: 7px; padding: 0.55rem 1rem; cursor: pointer;
}
.qo-run-btn:hover { opacity: 0.9; }
.qo-run-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.qo-run-btn.is-secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.qo-scoreboard { display: flex; justify-content: center; gap: 2rem; margin-top: 1rem; flex-wrap: wrap; }
.qo-score-item { text-align: center; }
.qo-score-label { font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.qo-score-value { font-size: 1.25rem; font-weight: 700; color: var(--accent); font-family: var(--mono-font); }
.qo-msg { margin-top: 0.9rem; padding: 0.6rem 0.85rem; border-radius: 8px; font-size: 0.83rem; line-height: 1.5; display: none; background: var(--good-soft); color: var(--good); }
.qo-msg.is-visible { display: block; }
/* connection pooling */
.qo-pool-scroll { overflow-x: auto; }
.qo-pool-scroll svg { width: 100%; height: auto; display: block; min-width: 420px; }
.qo-slot-rect { fill: var(--paper); stroke: var(--line); stroke-width: 1.5; transition: fill 0.35s, stroke 0.35s; }
.qo-slot-rect.is-busy { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.5; }
.qo-slot-text { font-size: 11px; font-weight: 700; font-family: var(--body-font); text-anchor: middle; fill: var(--ink); }
.qo-slot-sub { font-size: 9px; font-family: var(--mono-font); text-anchor: middle; fill: var(--ink-soft); }
.qo-slot-sub.is-busy-label { fill: var(--accent); font-weight: 700; }
.qo-bar-bg { fill: var(--line); }
.qo-bar-fill { fill: var(--accent); transform-origin: left center; transition: transform linear; }
.qo-client-box { fill: var(--paper); stroke: var(--ink-soft); stroke-width: 2; }
.qo-client-text { font-size: 11px; font-weight: 700; font-family: var(--body-font); text-anchor: middle; fill: var(--ink); }
.qo-queue-badge { fill: var(--bad-soft); stroke: var(--bad); stroke-width: 1.5; opacity: 0; transition: opacity 0.3s; }
.qo-queue-badge.is-visible { opacity: 1; }
.qo-queue-text { font-size: 10px; font-family: var(--mono-font); text-anchor: middle; fill: var(--bad); font-weight: 700; }
.qo-particle { fill: var(--accent); opacity: 0; }
.qo-particle.is-flying { opacity: 1; animation: qo-fly 0.55s ease-out forwards; }
.qo-particle.is-flying-queue { opacity: 1; animation: qo-fly-queue 0.55s ease-out forwards; }
.qo-legend { display: flex; justify-content: center; gap: 1.2rem; margin-top: 0.6rem; flex-wrap: wrap; font-size: 0.75rem; color: var(--ink-soft); }
.qo-legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 0.3rem; vertical-align: middle; }
@keyframes qo-fly {
0% { transform: translate(0, 0); opacity: 1; }
100% { transform: translate(var(--dx, 0px), var(--dy, 0px)); opacity: 0.9; }
}
@keyframes qo-fly-queue {
0% { transform: translate(0, 0); opacity: 1; }
100% { transform: translate(var(--dx, 0px), var(--dy, 0px)); opacity: 0.9; }
}
table.qo-table { width: 100%; border-collapse: collapse; background: var(--paper); border-radius: 8px; font-size: 0.83rem; margin-top: 1.5rem; }
table.qo-table th, table.qo-table td { border: 1px solid var(--line); padding: 0.5rem 0.65rem; text-align: left; }
table.qo-table th { background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 0.72rem; }
@media (prefers-reduced-motion: reduce) {
.infographic-queryopt *, .infographic-queryopt *::before, .infographic-queryopt *::after {
transition-duration: 0.001ms !important; animation-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<div class="infographic-queryopt" id="queryopt">
<div class="qo-head">
<h2>Query Optimization & Connection Pooling</h2>
<p>Two separate ways to make a database faster — one shapes the query, the other shapes the connection.</p>
</div>
<div class="qo-tabs">
<button class="qo-tab-btn is-active" data-tab="opt" type="button">⚙️ Query Optimization</button>
<button class="qo-tab-btn" data-tab="pool" type="button">🧠 Connection Pooling</button>
</div>
<!-- TAB 1: Query Optimization -->
<div class="qo-panel is-active" id="panel-opt">
<p class="qo-panel-title">Poor Query vs Optimized Query</p>
<p class="qo-panel-desc">Wrapping an indexed column in a function like YEAR() stops the database from using its index — even though the intent is identical.</p>
<div class="qo-code-scroll">
<div class="qo-code"><span class="qo-cm">-- Poor query</span>
<span class="qo-kw">SELECT</span> * <span class="qo-kw">FROM</span> orders <span class="qo-kw">WHERE</span> <span class="qo-fn">YEAR</span>(order_date) = <span class="qo-num">2023</span>;
<span class="qo-cm">-- Optimized query (index on order_date can be used)</span>
<span class="qo-kw">SELECT</span> * <span class="qo-kw">FROM</span> orders
<span class="qo-kw">WHERE</span> order_date >= <span class="qo-str">'2023-01-01'</span> <span class="qo-kw">AND</span> order_date < <span class="qo-str">'2024-01-01'</span>;</div>
</div>
<div class="qo-diagram-scroll">
<svg viewBox="0 0 400 220" id="optSvg"></svg>
</div>
<div class="qo-run-row">
<button class="qo-run-btn" id="poorBtn" type="button">▶ Run poor query</button>
<button class="qo-run-btn is-secondary" id="goodBtn" type="button">▶ Run optimized query</button>
<button class="qo-run-btn is-secondary" id="optReset" type="button">↺ Reset</button>
</div>
<div class="qo-scoreboard">
<div class="qo-score-item"><div class="qo-score-label">Poor query</div><div class="qo-score-value" id="poorScore">–</div></div>
<div class="qo-score-item"><div class="qo-score-label">Optimized query</div><div class="qo-score-value" id="goodScore">–</div></div>
</div>
<p class="qo-msg" id="optMsg"></p>
</div>
<!-- TAB 2: Connection Pooling -->
<div class="qo-panel" id="panel-pool">
<p class="qo-panel-title">Without Pooling vs With Pooling</p>
<p class="qo-panel-desc">Opening a fresh DB connection is expensive. A pool keeps a few open and hands them out, instead of paying that cost every time.</p>
<div class="qo-code-scroll">
<div class="qo-code"><span class="qo-kw">const</span> pool = mysql.createPool({
connectionLimit: <span class="qo-num">3</span>,
host: <span class="qo-str">'localhost'</span>, user: <span class="qo-str">'root'</span>, database: <span class="qo-str">'mydb'</span>
});
pool.query(<span class="qo-str">'SELECT * FROM users'</span>, callback);</div>
</div>
<div class="qo-pool-scroll">
<svg viewBox="0 0 460 170" id="poolSvg"></svg>
</div>
<div class="qo-legend">
<span><span class="qo-legend-dot" style="background:var(--paper); border:1.5px solid var(--line);"></span>Idle (ready to reuse)</span>
<span><span class="qo-legend-dot" style="background:var(--accent-soft); border:1.5px solid var(--accent);"></span>Busy (bar shows time left)</span>
<span><span class="qo-legend-dot" style="background:var(--bad-soft); border:1.5px solid var(--bad);"></span>Waiting in queue</span>
</div>
<div class="qo-run-row">
<button class="qo-run-btn" id="sendReqBtn" type="button">📨 Send a client request</button>
<button class="qo-run-btn is-secondary" id="poolReset" type="button">↺ Reset</button>
</div>
<div class="qo-scoreboard">
<div class="qo-score-item"><div class="qo-score-label">Requests handled</div><div class="qo-score-value" id="poolCount">0</div></div>
<div class="qo-score-item"><div class="qo-score-label">New connections opened</div><div class="qo-score-value" id="poolOpened">0</div></div>
</div>
<p class="qo-msg" id="poolMsg"></p>
</div>
</div>
<script>
(function () {
const wrapper = document.getElementById('queryopt');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
})();
/* tabs */
(function () {
document.querySelectorAll('.qo-tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.qo-tab-btn').forEach(b => b.classList.remove('is-active'));
document.querySelectorAll('.qo-panel').forEach(p => p.classList.remove('is-active'));
btn.classList.add('is-active');
document.getElementById('panel-' + btn.dataset.tab).classList.add('is-active');
});
});
})();
/* TAB 1: Query Optimization */
(function () {
const svg = document.getElementById('optSvg');
const rows = [
{ id: 1, date: '2022-04-02' }, { id: 2, date: '2023-01-20' }, { id: 3, date: '2022-09-15' },
{ id: 4, date: '2023-06-11' }, { id: 5, date: '2023-11-02' }, { id: 6, date: '2022-12-30' }
];
function render() {
let html = '';
rows.forEach((r, i) => {
const y = 10 + i * 34;
html += '<rect class="qo-row-rect" id="opt-row-' + r.id + '" x="10" y="' + y + '" width="380" height="26" rx="4"></rect>';
html += '<text class="qo-cell-text" x="200" y="' + (y + 17) + '">OrderID ' + r.id + ' | order_date = ' + r.date + '</text>';
});
svg.innerHTML = html;
}
render();
function clear() {
rows.forEach(r => document.getElementById('opt-row-' + r.id).classList.remove('is-scanned', 'is-matched', 'is-skipped'));
}
document.getElementById('poorBtn').addEventListener('click', async function () {
this.disabled = true;
clear();
document.getElementById('optMsg').classList.remove('is-visible');
let scanned = 0;
for (const r of rows) {
await new Promise(res => setTimeout(res, 180));
const el = document.getElementById('opt-row-' + r.id);
const matches = r.date.startsWith('2023');
el.classList.add(matches ? 'is-matched' : 'is-scanned');
scanned++;
}
document.getElementById('poorScore').textContent = scanned + ' rows scanned';
document.getElementById('optMsg').textContent = "⚠️ YEAR(order_date) hides the column inside a function, so the index on order_date can't be used — every single row has to be opened and checked.";
document.getElementById('optMsg').classList.add('is-visible');
this.disabled = false;
});
document.getElementById('goodBtn').addEventListener('click', async function () {
this.disabled = true;
clear();
document.getElementById('optMsg').classList.remove('is-visible');
const matching = rows.filter(r => r.date.startsWith('2023'));
let scanned = 0;
for (const r of matching) {
await new Promise(res => setTimeout(res, 180));
document.getElementById('opt-row-' + r.id).classList.add('is-matched');
scanned++;
}
document.getElementById('goodScore').textContent = scanned + ' rows scanned';
document.getElementById('optMsg').textContent = '✔️ The range comparison keeps order_date bare, so the index can seek straight to 2023\u2019s rows — the 2022 rows are never even opened.';
document.getElementById('optMsg').classList.add('is-visible');
this.disabled = false;
});
document.getElementById('optReset').addEventListener('click', () => {
clear();
document.getElementById('poorScore').textContent = '–';
document.getElementById('goodScore').textContent = '–';
document.getElementById('optMsg').classList.remove('is-visible');
});
})();
/* TAB 2: Connection Pooling */
(function () {
const svg = document.getElementById('poolSvg');
const limit = 3;
const DURATION = 2200; // ms a connection stays busy
const slotX = [120, 260, 400];
const slotY = 80;
const clientX = 25, clientY = 80;
let slots = [null, null, null]; // null = idle, else { start, timeoutId }
let queueCount = 0;
let handled = 0;
let opened = 0;
let particleId = 0;
function baseSvg() {
let html = '';
// client node
html += '<rect class="qo-client-box" x="' + (clientX - 20) + '" y="' + (clientY - 24) + '" width="40" height="48" rx="8"></rect>';
html += '<text class="qo-client-text" x="' + clientX + '" y="' + (clientY - 32) + '">Client</text>';
html += '<text class="qo-client-text" x="' + clientX + '" y="' + (clientY + 5) + '" font-size="16">👤</text>';
// queue badge above client
html += '<g id="queueBadge" class="qo-queue-badge"><rect x="' + (clientX - 26) + '" y="10" width="52" height="22" rx="11"></rect><text class="qo-queue-text" id="queueText" x="' + clientX + '" y="25">waiting</text></g>';
// slots
slotX.forEach((x, i) => {
html += '<rect class="qo-slot-rect" id="slot-' + i + '" x="' + (x - 45) + '" y="' + (slotY - 32) + '" width="90" height="64" rx="8"></rect>';
html += '<text class="qo-slot-text" x="' + x + '" y="' + (slotY - 12) + '">Conn ' + (i + 1) + '</text>';
html += '<text class="qo-slot-sub" id="slotsub-' + i + '" x="' + x + '" y="' + (slotY + 4) + '">idle</text>';
html += '<rect class="qo-bar-bg" x="' + (x - 32) + '" y="' + (slotY + 14) + '" width="64" height="6" rx="3"></rect>';
html += '<rect class="qo-bar-fill" id="bar-' + i + '" x="' + (x - 32) + '" y="' + (slotY + 14) + '" width="64" height="6" rx="3" transform="scaleX(0)"></rect>';
});
svg.innerHTML = html;
}
baseSvg();
function updateSlotVisual(i) {
const rect = document.getElementById('slot-' + i);
const sub = document.getElementById('slotsub-' + i);
if (slots[i]) {
rect.classList.add('is-busy');
sub.classList.add('is-busy-label');
sub.textContent = 'busy';
} else {
rect.classList.remove('is-busy');
sub.classList.remove('is-busy-label');
sub.textContent = 'idle';
const bar = document.getElementById('bar-' + i);
bar.style.transition = 'none';
bar.setAttribute('transform', 'scaleX(0)');
}
}
function animateBar(i) {
const bar = document.getElementById('bar-' + i);
bar.style.transition = 'none';
bar.setAttribute('transform', 'scaleX(1)');
// force reflow so the transition below actually animates from 1 -> 0
void bar.getBoundingClientRect();
bar.style.transition = 'transform ' + DURATION + 'ms linear';
bar.setAttribute('transform', 'scaleX(0)');
}
function flyParticle(toX, toY, isQueue) {
particleId++;
const id = 'particle-' + particleId;
const dx = toX - clientX;
const dy = toY - clientY;
const p = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
p.setAttribute('id', id);
p.setAttribute('cx', clientX);
p.setAttribute('cy', clientY);
p.setAttribute('r', '6');
p.setAttribute('class', 'qo-particle');
p.style.setProperty('--dx', dx + 'px');
p.style.setProperty('--dy', dy + 'px');
svg.appendChild(p);
requestAnimationFrame(() => p.classList.add(isQueue ? 'is-flying-queue' : 'is-flying'));
setTimeout(() => p.remove(), 600);
}
function showQueueBadge(show) {
const badge = document.getElementById('queueBadge');
const text = document.getElementById('queueText');
if (show) {
text.textContent = queueCount + ' waiting';
badge.classList.add('is-visible');
} else {
badge.classList.remove('is-visible');
}
}
document.getElementById('sendReqBtn').addEventListener('click', () => {
const freeIndex = slots.findIndex(s => !s);
handled++;
document.getElementById('poolCount').textContent = handled;
if (freeIndex === -1) {
queueCount++;
flyParticle(clientX, 21, true);
showQueueBadge(true);
document.getElementById('poolMsg').textContent = '⏳ All ' + limit + ' connections are busy — this request waits for one to free up instead of opening a new connection. Watch the bars: as soon as one empties, the wait clears.';
document.getElementById('poolMsg').classList.add('is-visible');
// try to admit this waiting request once a slot frees
const waitForFree = setInterval(() => {
const idx = slots.findIndex(s => !s);
if (idx !== -1) {
clearInterval(waitForFree);
queueCount = Math.max(0, queueCount - 1);
showQueueBadge(queueCount > 0);
assign(idx, true);
}
}, 150);
return;
}
assign(freeIndex, false);
});
function assign(i, wasQueued) {
opened++;
slots[i] = true;
updateSlotVisual(i);
animateBar(i);
flyParticle(slotX[i], slotY, false);
const wasFreshOpen = opened <= limit;
document.getElementById('poolOpened').textContent = Math.min(opened, limit);
document.getElementById('poolMsg').textContent = wasFreshOpen
? '🔧 No idle connection yet, so Conn ' + (i + 1) + ' opened fresh — the bar shows it counting down until it\u2019s free again (' + Math.min(opened, limit) + ' of ' + limit + ' ever opened).'
: '🚀 Reused Conn ' + (i + 1) + (wasQueued ? ' — this request had been waiting, and grabbed it the instant it freed up.' : ' — already open and idle, so the expensive setup was skipped entirely.');
document.getElementById('poolMsg').classList.add('is-visible');
setTimeout(() => {
slots[i] = null;
updateSlotVisual(i);
}, DURATION);
}
document.getElementById('poolReset').addEventListener('click', () => {
slots = [null, null, null];
queueCount = 0;
handled = 0;
opened = 0;
document.getElementById('poolCount').textContent = '0';
document.getElementById('poolOpened').textContent = '0';
document.getElementById('poolMsg').classList.remove('is-visible');
baseSvg();
});
})();
</script>
</body>
</html>.demo {
font-family: system-ui, sans-serif;
padding: 16px;
}
.demo h1 {
color: #2563eb;
margin: 0 0 8px;
}
.demo p {
color: #4b5563;
margin: 0;
}document.querySelector('.demo h1')?.addEventListener('click', () => {
alert('Hello from live preview!');
});🧩 Summary Table
Feature | Query Optimization | Connection Pooling |
|---|---|---|
Goal | Faster queries | Faster and more efficient DB connections |
Who does it? | DB engine + developer | Developer/framework |
Example Use | Indexing, using EXPLAIN, better joins | Keeping 10–20 live connections for reuse |
Result | Low query execution time | Low latency for client-server interaction |