惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
GRAHAM CLULEY
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
aimingoo的专栏
aimingoo的专栏
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
N
News and Events Feed by Topic
O
OpenAI News
博客园 - Franky
M
MIT News - Artificial intelligence
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 热门话题
Know Your Adversary
Know Your Adversary
S
Security @ Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hacker News: Front Page
TaoSecurity Blog
TaoSecurity Blog
The Cloudflare Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
罗磊的独立博客
博客园 - 【当耐特】
C
Cisco Blogs
K
Kaspersky official blog
Cisco Talos Blog
Cisco Talos Blog
IT之家
IT之家
Recent Announcements
Recent Announcements
Cyberwarzone
Cyberwarzone
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
Y
Y Combinator Blog
AI
AI
爱范儿
爱范儿
S
Schneier on Security
Google DeepMind News
Google DeepMind News

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
1.4.7 Parallel Cost: When to Go Parallel and How Many Workers
JoongHyuk Shin · 2026-06-21 · via DEV Community

The planner weighs how to read a table, how to join, and how to aggregate by cost, and picks the cheapest candidate. Parallel query is one more decision layered on top of those candidates: whether one process handles a given scan or join alone, or several processes split the work, and if they split it, among how many. This decision is also made by the planner, not the executor. The planner costs a parallel candidate separately, puts it on the same scale as the serial one, and keeps whichever is cheaper.

So understanding parallelism comes down to three numbers. When does the planner consider parallel at all. If it does, how many workers does it assign. And how much does the cost drop once the work is split. These three numbers map directly onto the questions you hit in practice: "this table is huge, why isn't it going parallel," and "I added cores, why didn't it get that much faster." How the worker processes actually divide the pages and cooperate is the executor's job, covered in 1.5. Here we look at the numbers the planner uses to decide whether to go parallel in the first place.

Small tables are never even candidates

Parallelism is not free. Launching worker processes, setting up shared memory, and having the leader gather their results all carry a fixed cost. When a table is small, that fixed cost outweighs the gain from splitting the work, so reading it alone is actually faster. That is why the planner only considers parallelism once a table crosses a certain size.

That threshold is min_parallel_table_scan_size. The default is 8MB, which works out to 1024 pages (PG 18). The planner estimates how many pages a scan will read, and if that estimate falls below this value, it does not build a parallel path at all. This is usually the first reason you stare at an EXPLAIN plan and never see a Parallel Seq Scan. Index scans have their own threshold, min_parallel_index_scan_size (default 512KB, 64 pages). When a scan reads both the heap and an index, each threshold is checked on its own.

Write queries drop out of parallel consideration regardless of size. The SELECT inside an INSERT ... SELECT or an UPDATE never goes parallel, no matter how heavy that SELECT is. The parallel portion has to be strictly read-only, and the reason for that restriction is tangled up with how workers share state, which 1.5 covers. Here we just note the fact: a SELECT that comes with a write is not a candidate.

Worker count is set by table size

Once the planner decides to go parallel, how many workers does it launch? PostgreSQL sets this from the logarithm of the table size, with base 3 specifically. It starts at one worker and adds one more each time the page count reaches three times the threshold. Since the threshold itself starts at min_parallel_table_scan_size (8MB), the steps come out like this (PG 18 defaults).

  • 8MB or more: 1 worker
  • 24MB or more: 2 workers
  • 72MB or more: 3 workers
  • 216MB or more: 4 workers

Each time the table triples in size, the worker count goes up by one. It does not double as the size doubles; it grows much more slowly. A 1GB table does not get dozens of workers. The marginal gain from adding workers shrinks on larger tables, so the formula is conservative from the start.

There is one more cap on top of this: max_parallel_workers_per_gather, which defaults to 2. Even if the log formula yields 4, this cap of 2 trims the worker count to 2. So with no special configuration, scanning a large table normally gets at most two workers, and together with the leader, which pitches in directly, three processes split the same scan. To use more cores, you have to raise this value. Setting it to 0 turns parallelism off entirely.

Workers are not a per-query resource. The total number of parallel workers the whole server can run at once is bounded by another cap, max_parallel_workers (default 8), so when several queries go parallel at the same time, they share this pool. If the pool runs short, the planner may have planned for 2 workers but only 1 actually launches, or none do.

Parallelism divides only the CPU cost

Once you have decided to add workers and settled on a count, how is the parallel path's cost computed? The heart of it fits in one sentence. Parallelism divides only the CPU cost by the worker count; it does not divide the disk cost.

A scan cost breaks into two chunks: the cost of reading pages off disk, and the CPU cost of evaluating the WHERE conditions and processing each row that comes back. When going parallel, PostgreSQL divides only the CPU cost by the worker count. The disk cost stays at its full value.

There are two reasons the disk cost is not divided. First, no matter how many workers you attach, the total number of pages that must be read does not shrink. If a table is 10,000 pages, all 10,000 still have to come off disk no matter who reads them. Parallelism just lets several workers split those pages among themselves; it does not reduce the page count.

So would splitting the reads make the disk deliver pages faster? Counter to intuition, it does not. The disk is a single device the workers share, and there is a ceiling on how fast that device hands out pages. On top of that, when one process reads pages in order, the OS prefetches the next ones (read-ahead), so even a single reader already gets close to that device ceiling. Adding readers therefore does not make the disk deliver data N times faster. If anything, workers jumping between different regions can look like scattered access to the disk and cost a little.

PostgreSQL's cost model takes the conservative view here: it treats the disk cost as having nothing to amortize across workers and leaves it untouched. On fast SSDs parallel reads can give some benefit, but the model assumes that benefit is zero so as not to overvalue parallelism. So what parallelism actually cuts is the CPU side alone.

That said, the value the CPU cost is divided by is not exactly the worker count. The leader does not just launch workers and sit idle; it runs the same scan itself and produces rows, so the number of actual hands at work is the worker count plus the leader's share. The planner estimates that share as "the leader spends 30% of its time servicing each worker." So the divisor that actually scales the CPU cost comes out like this.

  • 1 worker: 1 + (1 − 0.3) = 1.7
  • 2 workers: 2 + (1 − 0.6) = 2.4
  • 3 workers: 3 + (1 − 0.9) = 3.1
  • 4 workers: 4 + 0 = 4.0

As workers pile up, the leader spends more time collecting their results and doing the post-processing on top, and less time on the scan itself. So the leader's share shrinks as workers grow, and by 4 workers it is treated as zero. This leader participation is toggled by parallel_leader_participation, which defaults to on.

So for parallelism to cut cost meaningfully, the CPU chunk of the scan has to be large. A scan that evaluates a heavy WHERE condition on every row, or runs a large aggregate, has a big CPU chunk, so splitting it pays off. A scan that just reads a lot of pages with light per-row work has most of its cost on the disk side, so attaching workers cuts little.

The fixed cost Gather adds

A parallel path does not only have costs that shrink; it also has costs that get added. The Gather node that collects the workers' results piles on two costs. One is the setup cost of launching workers and preparing shared memory; the other is the communication cost of handing each row a worker produces over to the leader.

The setup cost is parallel_setup_cost, which defaults to 1000. Recall that the cost of reading one page in earlier chapters was around 1, which makes 1000 a hefty fixed cost, on par with reading 1000 pages. The communication cost is parallel_tuple_cost, defaulting to 0.1 per row.

This setup cost is the decisive reason parallelism loses out on small queries. The fixed 1000 is laid down the same whether the table is small or large, but the CPU cost that gets cut is tiny when the table is small. On a small table the added 1000 outweighs the amount saved, so the parallel path ends up costing more than the serial one. The planner compares their total costs and keeps the cheaper one, so on a small query, even if a parallel candidate is built, it falls behind in the cost comparison. If the size threshold is the first gate, this cost comparison is the second gate above it.

When result order has to be preserved, GatherMerge is used instead of Gather. This happens when an ORDER BY means each worker's already-sorted output has to be merged without breaking the order. That merge carries the burden of continually comparing the front rows from each worker, so the planner charges GatherMerge 5% more for communication than Gather, plus the comparison cost of the merge sort itself. The price of keeping order is reflected directly in the cost.

Comparing serial and parallel cost in numbers

Let us put the rules so far onto actual numbers. A sequential scan cost is the sum of a disk term and a CPU term. The disk term multiplies the cost of reading one sequential page (seq_page_cost, default 1.0) by the page count, and the CPU term multiplies the cost of processing one tuple by the tuple count.

Take an accounts table with 1 million rows in 10,000 pages (about 80MB), scanned with WHERE balance > 9000. Since it is a simple comparison qual, the CPU cost per tuple is cpu_tuple_cost (0.01) plus the comparison cost cpu_operator_cost (0.0025), for 0.0125. The cost of the serial sequential scan comes out as:

disk_run_cost = 1.0 × 10000       = 10000
cpu_run_cost  = 0.0125 × 1000000  = 12500
total         ≈ 22500

Now attach 2 workers. 80MB clears the size threshold (8MB), so parallelism becomes a candidate; the log formula yields 3 workers but the default cap of 2 trims it. The divisor for 2 workers is 2.4. The disk term stays put and only the CPU term is divided by 2.4. On top of that, the Gather that collects the results adds setup of 1000 and a per-row communication cost. If 1000 rows pass the WHERE, the communication cost is parallel_tuple_cost 0.1 × 1000 = 100.

disk_run_cost = 1.0 × 10000       = 10000   (unchanged)
cpu_run_cost  = 12500 ÷ 2.4       ≈ 5208    (divided by workers)
Gather setup  = 1000
Gather comm   = 0.1 × 1000         = 100
total         ≈ 16308

22500 dropped to 16308, so the planner picks parallel. The roughly 6000 saved comes almost entirely from the CPU term being cut from 12500 to 5208. The disk term of 10000 holds equally on both sides, and the setup of 1000 is added only on the parallel side.

The numbers flip the other way when a table barely clears the size threshold. With small page and tuple counts, the CPU term is small too, so splitting it among workers only cuts a few hundred, while the setup of 1000 is still laid down in full. The parallel total then ends up larger, so the path clears the size gate but falls behind in the cost comparison. This is the setup cost acting as that second gate, expressed in numbers.

What this means in practice

First, when a large table won't go parallel, check the size threshold and the worker caps first. The check order is threefold. First, min_parallel_table_scan_size (default 8MB). If the table is smaller than this, the planner never even raises parallelism as a candidate. Next, max_parallel_workers_per_gather (default 2). If this is 0, parallelism is fully off, and to use more cores on an analytical query you raise it per session. Last, the overall pool, max_parallel_workers (default 8). In a high-concurrency environment where this pool runs short, the query runs with fewer workers than planned. When Workers Planned (the number the planner intended to launch) and Workers Launched (the number that actually started) differ in EXPLAIN ANALYZE, this pool shortage is exactly what happened.

Second, doubling the workers does not double the speed. Parallelism does not speed up in direct proportion to core count. As workers grow, the leader's share of collecting results and post-processing grows, so the effect of each additional worker tapers off, and on top of that there is the fixed setup cost. The planner's cost model itself reflects this diminishing return by shaving the leader's contribution as workers grow. So do not expect raising max_parallel_workers_per_gather to speed things up by that same ratio; it is better to vary the worker count and actually measure, finding the point where the effect flattens out.