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

推荐订阅源

MyScale Blog
MyScale Blog
量子位
宝玉的分享
宝玉的分享
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
Apple Machine Learning Research
Apple Machine Learning Research
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
aimingoo的专栏
aimingoo的专栏
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
Latest news
Latest news
S
Security @ Cisco Blogs
Last Week in AI
Last Week in AI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
W
WeLiveSecurity
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
P
Proofpoint News Feed
P
Palo Alto Networks Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
The Blog of Author Tim Ferriss
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
美团技术团队
博客园 - 【当耐特】
D
DataBreaches.Net
I
InfoQ
G
GRAHAM CLULEY
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog

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
SQL Index Anatomy: The Logic of Choosing Right for Performance
Mustafa ERBA · 2026-05-18 · via DEV Community

The Fundamental Structure of SQL Indexes: Why Do They Matter?

In a production ERP system, there was an incredible slowness in order status queries. When users clicked "open order list," it sometimes took 5 minutes for the screen to populate. This situation was both decreasing operational efficiency and undermining overall system performance. My initial investigations showed that a simple SELECT query was scanning millions of rows. That was the moment I realized that managing a database without a proper INDEX strategy is like someone lost in a forest trying to find their way without a flashlight.

INDEXes are the backbone of performance in SQL databases. The basic logic is quite simple: like the index at the back of a book, they provide fast access to data in specific columns. Without an INDEX, we would have to scan the entire table for every query, which causes unacceptable slowness, especially in large datasets. However, creating an INDEX for every column isn't right either; this unnecessarily fills up the disk and slows down INSERT, UPDATE, and DELETE operations. Choosing the right INDEX is a mix of art and science.

B-tree Index: Our Default Hero

In most database systems (PostgreSQL, MySQL, SQL Server), the default and most frequently used INDEX type is the B-tree. B-trees keep data in a sorted manner, making them incredibly effective for searching, sorting, and range queries. Imagine you have a dictionary sorted alphabetically; instead of reading pages one by one to find a word, you can narrow down the search by going to the beginning or end of the word. B-trees do exactly that.

ℹ️ How B-tree Index Works

B-trees store data hierarchically using structures called nodes. Each node contains a certain number of keys and pointers to the data blocks corresponding to those keys. Queries move down this hierarchy to reach the searched data. This structure is also designed to work harmoniously with the physical layout of the database on the disk.

In the supply chain management system of a manufacturing firm, there was a SELECT query checking the stock status of products. When we created a B-tree INDEX on the product_id and warehouse_id columns, the query time dropped from 5 minutes to 50 milliseconds. This demonstrates the power of B-tree in equality (=) and range (>, <, >=, <=) queries. However, B-trees might not always be the best solution. We might need to look at other INDEX types, especially for text-based or complex data structures.

GIN Index: For Full-Text Search and Array Data

Sometimes we need to search not just for the data in a column, but for words or elements within that column. For example, searching by article content on a blog platform or finding specific keywords in product descriptions on an e-commerce site. This is where GIN (Generalized Inverted Index) comes into play. GIN is optimized specifically for full-text search and array data types.

A GIN index stores data as "value-key" instead of key-value pairs. That is, when you create a GIN index for article content, the index actually records every word in that article and which article that word appears in. This incredibly speeds up queries like "find all articles containing the word 'performance'." In the backend of my own financial calculators, which I mentioned in a previous post, I used a GIN index to analyze complex formula texts entered by users. This allowed me to list formulas containing specific parameters in seconds.

⚠️ The Cost of GIN Index

GIN indexes can occupy more disk space than B-trees and can make INSERT and UPDATE operations slower. This is because updating the index requires re-processing all the values it contains. Therefore, it makes sense to use GIN indexes only in cases where you truly need full-text search or complex array queries.

Using GIN indexes with tsvector and tsquery types in PostgreSQL offers powerful full-text search capabilities. This significantly increases query performance when working with large text data. Another use case for GIN is JSONB or ARRAY data types. When you want to search based on specific elements or keys within these data types, a GIN index works more efficiently than a B-tree.

BRIN Index: A Compact Solution for Large and Ordered Data

The INDEX types we've discussed so far generally have the potential to scan all or a large part of the dataset. But what if your data is already physically written to the disk in a sorted manner? For example, time-series data or very large log files. For these types of scenarios, BRIN (Block Range Index) comes into play. Instead of storing the data itself, BRIN indexes store the minimum and maximum values within a specific range of data blocks.

In a system where I collected crash reports for one of my mobile apps, there were millions of rows of log data. These logs were ordered by the time they were created. By using a BRIN index, when I queried crashes within a certain time range, the index only checked the boundaries of the data blocks corresponding to that time range. If an entire data block was outside the queried range, it didn't bother scanning any rows in that block. This allows the BRIN index to save disk space and increase performance in very large, ordered datasets.

💡 BRIN vs B-tree

BRIN indexes take up much less space than B-tree indexes and are faster to create. However, if your data is not ordered or if you frequently perform random data access, BRIN indexes remain ineffective. The biggest advantage of BRIN is that in cases where data is physically ordered, it speeds up the query by checking only the relevant data blocks.

For example, if you are recording sensor data from an IoT device into a PostgreSQL table hourly and index this data with a BRIN index on the timestamp column, querying data within a specific hour range will be much faster. Because the index can quickly determine which data blocks fall into the relevant time range. This makes a huge difference in terms of disk space and query time, especially when dealing with petabytes of data.

Choosing the Right Index: Understanding the Trade-offs

Choosing an INDEX in a database architecture is a continuous chain of trade-offs. Each INDEX type has its own advantages and disadvantages. B-tree is great for general-purpose queries but isn't as effective as GIN for text searches. GIN is powerful for text and array data but takes up more disk space and slows down write operations. BRIN is great for ordered data but useless if your data isn't ordered.

In one project, in a table where we stored users' favorite products, we were frequently querying by both product ID and user ID. Initially, we created two separate B-tree INDEXes: one on product_id and another on user_id. However, this was slowing down INSERT operations. Then, we tried a composite INDEX like (user_id, product_id), which PostgreSQL supports. This increased performance both when filtering by user_id and when searching for specific products for a specific user.

🔥 Common Mistakes in Index Selection

One of the most common mistakes is adding random INDEXes to every column. This wastes disk space and reduces write performance. Another mistake is making INDEX decisions without analytically examining your queries. Using tools like EXPLAIN ANALYZE to understand how your queries work is the key to determining the right INDEX strategy.

It shouldn't be forgotten that INDEXes not only increase query speed but also affect the overall stability of the system. Excessive INDEX usage can lead to I/O bottlenecks by causing the disk to constantly read and write INDEX files. Therefore, when determining your INDEX strategy, you need to carefully analyze the balance of read and write operations, data volume, and query patterns.

Index Optimization and Management

The work doesn't end after creating the INDEXes. Monitoring and optimizing them regularly is at least as important as the selection itself. System catalogs like pg_stat_user_indexes in PostgreSQL show which INDEXes are used how much and how many seq_scans (full table scans) have been performed. If an INDEX is never used or used very little, removing it can save disk space and improve write performance.

In one project, I noticed an old INDEX that had been used for years but was no longer being queried. When we removed it, INSERT operations on the relevant table became about 15% faster. Small optimizations like this can make a significant difference in large systems over time. Additionally, VACUUM operations are important for maintaining the health of INDEXes. VACUUM reclaims space occupied by deleted or updated data and ensures INDEXes work more efficiently.

ℹ️ Things to Consider in Index Maintenance

The ANALYZE command updates statistics so that the database PLANNER can make correct decisions. VACUUM cleans up old data rows, keeping both the table and the INDEXes organized. In PostgreSQL, these operations are usually done automatically, but they may need to be run manually in heavy write operations or special cases.

Finally, when determining your INDEXes, consider the features offered by your database version. New versions usually offer more advanced INDEX types, better PLANNER algorithms, and better INDEX management tools. For example, improvements to BRIN indexes that came with PostgreSQL 11 or the deduplication feature for B-tree INDEXes in PostgreSQL 15 can have significant impacts on performance.

Conclusion: Smart Choices, Fast Results

SQL INDEXes are the cornerstone of database performance. Knowing when and how to use different INDEX types like B-tree, GIN, and BRIN can make the difference between your queries running in seconds or making you wait for minutes. Remember that every INDEX has a cost; therefore, you should carefully evaluate whether every INDEX you create is truly necessary and if it's the right type. My experience shows that the right INDEX strategy is not just a technical optimization, but a strategic step that directly affects the efficiency of business processes.