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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Palo Alto Networks Blog
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
The GitHub Blog
The GitHub Blog
C
Cisco Blogs
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
T
Tenable Blog
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threat Research - Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
I
InfoQ
D
Darknet – Hacking Tools, Hacker News & Cyber Security
W
WeLiveSecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
U
Unit 42
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
T
The Exploit Database - CXSecurity.com
I
Intezer
GbyAI
GbyAI
Jina AI
Jina AI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Google Online Security Blog
Google Online Security Blog
Engineering at Meta
Engineering at Meta
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
小众软件
小众软件
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
Project Zero
Project Zero

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.1.3 Optimizable vs Utility
JoongHyuk Sh · 2026-05-05 · via DEV Community

Inside the five-stage pipeline from 1.1.1, there is another fork right after the parser. PostgreSQL classifies every SQL command into one of two camps. One side holds the optimizable queries, the other holds the utility commands. The classification is decided by a single field on the Query node, commandType, and from that point on the two camps travel completely different paths. One goes through the rewriter, the planner, and the executor. The other bypasses all three.

This fork was a single line in the 1.1.1 picture, but it shapes the entire internal structure of PostgreSQL, so it earns its own section.

Five optimizables, and everything else

PostgreSQL defines its command types as a single enum.

typedef enum CmdType
{
    CMD_UNKNOWN,
    CMD_SELECT,
    CMD_UPDATE,
    CMD_INSERT,
    CMD_DELETE,
    CMD_MERGE,
    CMD_UTILITY,
    CMD_NOTHING,
} CmdType;

Enter fullscreen mode Exit fullscreen mode

Of these, CMD_SELECT, CMD_INSERT, CMD_UPDATE, CMD_DELETE, and CMD_MERGE are the optimizable ones. As the name suggests, these are queries the planner can do meaningful work on. It rearranges join order using a cost model, picks indexes, and chooses scan methods.

CMD_UTILITY is the catch-all for everything else: CREATE TABLE, ALTER TABLE, DROP, VACUUM, BEGIN/COMMIT/ROLLBACK, COPY, NOTIFY, LISTEN, CLUSTER, REINDEX, GRANT, SET, SHOW, TRUNCATE, LOCK, FETCH, CHECKPOINT, PREPARE TRANSACTION, CREATE INDEX, CREATE FUNCTION, and many more. What they share is a single property: the planner has no room to produce a better plan via cost comparison.

A command like CREATE TABLE foo (id int) cannot have two different paths. It just inserts a few rows into the system catalog and asks the storage manager to allocate a new relfilenode. BEGIN similarly nudges the transaction state by one step; there is no choice in "how to BEGIN." VACUUM walks a target table page by page and cleans up dead tuples through a fixed procedure. The point is that cost comparison is meaningless here.

The two camps are wired through different code paths. The first split happens in the analyzer, right after the parser hands over a raw parse tree.

The fork lives in transformStmt's switch

When the raw parse tree arrives, transformStmt() runs a large switch on the node tag (src/backend/parser/analyze.c).

switch (nodeTag(parseTree))
{
    /* Optimizable statements */
    case T_InsertStmt:
        result = transformInsertStmt(...);
        break;
    case T_SelectStmt:
        result = transformSelectStmt(...);
        break;
    /* ... UPDATE, DELETE, MERGE ... */

    /* Special cases (utility wrappers around an optimizable inside) */
    case T_DeclareCursorStmt:
    case T_ExplainStmt:
    case T_CreateTableAsStmt:
    case T_CallStmt:
        /* transform the inner query separately */
        ...

    default:
        /* every other utility */
        result = makeNode(Query);
        result->commandType = CMD_UTILITY;
        result->utilityStmt = parseTree;
        break;
}

Enter fullscreen mode Exit fullscreen mode

PostgreSQL does meaningful semantic analysis on the five optimizable statement types and a handful of special cases. Everything else falls through to the default branch, gets stamped commandType = CMD_UTILITY, and the raw parse tree is stored verbatim in the utilityStmt field. Nothing was actually analyzed; a Query shell was wrapped around the raw tree with a "this is utility" sticker.

The next stage, the rewriter, also reads that sticker (src/backend/tcop/postgres.c).

if (query->commandType == CMD_UTILITY)
    querytree_list = list_make1(query);   /* don't rewrite utilities */
else
    querytree_list = QueryRewrite(query);

Enter fullscreen mode Exit fullscreen mode

If the query is utility, the rewriter does not touch it. The rule system, view expansion, and RLS policy application all live on the optimizable side and have no meaning for utility commands.

The planner is the same.

if (query->commandType == CMD_UTILITY)
{
    /* Utility commands require no planning. */
    stmt = makeNode(PlannedStmt);
    stmt->commandType = CMD_UTILITY;
    stmt->utilityStmt = query->utilityStmt;
    ...
}
else
{
    stmt = pg_plan_query(query, ...);   /* invoke the planner */
}

Enter fullscreen mode Exit fullscreen mode

Utility commands never call into the planner. An empty PlannedStmt wrapper is built, and the raw parse tree is dropped into it. A PlannedStmt with no plan tree.

The executor stage is split too. Optimizable statements feed their plan tree into the executor proper, which produces rows. Utility statements get handed off to ProcessUtility(), which dispatches to a per-statement handler. The dispatch logic and the individual handlers belong to later chapters (DDL in 1.6, transaction commands in chapter 4).

When you lay out the four stages side by side, the asymmetry is sharp.

Stage Optimizable (5 types) Utility (everything else)
Parse analysis Dedicated transform function Wrapped in a Query shell
Rewriter Rule system applied Skipped (passes through)
Planner Plan tree generated Skipped (empty PlannedStmt holding the raw tree)
Executor ExecutorRun() (walks the plan tree) ProcessUtility() (per-statement handler)

The whole sophistication of the planner exists for those five types; utility bypasses it entirely. This is not an efficiency choice. It is a structural asymmetry, because utility commands have no alternative paths to compare.

Two species sharing one system

Once you see how this asymmetry is wired, the two camps look almost like two species inside the same engine.

Hooks live on different paths. A hook in PostgreSQL is a function pointer exposed at a key point in the execution path so that external code (typically an extension) can plug in. An extension installs its own function address into the hook, and PostgreSQL calls it whenever the hook is non-null at the appropriate moment. Which camp the hook applies to depends on where it sits. planner_hook is invoked just before the planner runs, so it only affects optimizable queries. Utility never enters the planner, so planner_hook never fires for utility. On the other side, ProcessUtility_hook is invoked just before ProcessUtility() runs, so it only applies to utility commands. That is how an audit logging extension like pgaudit intercepts DDL and DCL. You need both hooks together to cover every SQL execution path. If you write extensions, you have to know up front which camp your hook is intercepting.

Statistics are split too. PostgreSQL accumulates usage patterns about which SQL ran how often and for how long, and DBAs use that data to find slow queries and pick tuning targets. The recording channels, however, are split between the two camps. pg_stat_statements records SELECT/INSERT/UPDATE/DELETE/MERGE executions along with plan-level information. Some utility commands (especially DDL) need a separate channel like log_statement = ddl. A monitoring tool that wants to draw "what is happening in this system" has to read both channels.

Prepared statements mean different things in each camp. The prepared statements from 1.1.2 cache plans for optimizable queries. Utility commands can be wrapped with PREPARE too, but since there is no plan, there is nothing to cache. The server just keeps the raw tree around and routes each EXECUTE through ProcessUtility again. Same name, different semantics.

EXPLAIN's reach is asymmetric. EXPLAIN SELECT ... draws a plan tree. EXPLAIN ALTER TABLE ... does not work; there is no plan tree to draw. The exception is the special-case group from the switch above (T_DeclareCursorStmt, T_ExplainStmt, T_CreateTableAsStmt, T_CallStmt). They are classified as utility on the outside but contain an optimizable query that goes through the regular pipeline. That hybrid path is why EXPLAIN ANALYZE INSERT INTO ... SELECT ... works. The outer wrapper is utility; the SELECT and INSERT inside are optimizable.

I once tried to debug "why is this long ALTER TABLE so slow" by analyzing the plan. The plan had no answer. The bulk of the cost lived outside the plan tree: lock waits, catalog updates, full-table rewrites, and WAL volume. That was when I learned why utility needs its own dedicated path. Some costs are invisible to the plan-level cost model, and to see them you need a different stage of tools.

What this means in practice

First, planner-related tuning and monitoring tools have no meaning for utility. EXPLAIN, plan-level metrics in pg_stat_statements, auto_explain, plan_cache_mode, all of these are optimizable-side tools. Looking at the plan to debug a slow DDL or DCL is pointless because there is no plan. By the same logic, an ORM or migration tool that wraps ALTER TABLE in a prepared statement assuming "the plan will be cached anyway" has the wrong mental model. Utility commands have no plan; every call grabs and releases catalog locks while running directly. Slow utility is almost always lock contention or I/O cost, not a plan choice issue, so the diagnostic path is to set log_min_duration_statement to capture timings, watch lock waits in pg_stat_activity, and look at wait_events to see where the command is stuck.

Second, audit and security requirements split into two camps and attach to different mechanisms. Tracking "who changed which schema and when" lives on the utility side. pgaudit captures ALTER/CREATE/DROP/GRANT into an audit log because it sits on ProcessUtility_hook. Row-level access control like "this user can only see a subset of rows in this table" lives on the optimizable side. RLS (Row-Level Security) runs in the rewriter, automatically attaching extra WHERE conditions to SELECT/UPDATE/DELETE. The two requirements get bundled under the same security umbrella, but they hook into completely different stages of the pipeline. RLS cannot stop a schema change, and ProcessUtility_hook cannot filter rows. When a compliance requirement comes in, the first task is to classify it as schema-level tracking versus row-level access control. Only then do the candidate tools fall into place, and you almost always need both mechanisms together to leave no gaps.