{
  "id": 5842767,
  "title": "What actually happens in a database index (and why half of them do nothing)",
  "url": "https://urgent.news/2026/09/05/what-actually-happens-in-a-database-index-and-why-half-of-them-do",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-05T21:25:42.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/vladut02/what-actually-happens-in-a-database-index-and-why-half-of-them-do-nothing-3mh6"
  },
  "original_language": "en",
  "account": "A database index is a data structure that speeds up searching for data in a database table. However, it's a common misconception that adding an index always makes queries faster. In reality, about half of the indexes people add do nothing to improve query performance.\n\nWhen a query runs without an index, the database performs a full table scan, which means it reads every single row in the table to find the matching data. This process becomes increasingly slow as the table grows. For example, searching for a user by email in a table with a million rows can take up to four seconds.\n\nIn contrast, an index is a sorted map that functions like a phone book, where each entry corresponds to a row in the table. The index is sorted based on the column(s) used in the query, allowing the database to quickly locate the desired data without scanning the entire table. For instance, if the index is created on the 'email' column, the database can find the matching email in just a few hops, rather than going through all million rows.\n\nHowever, there are several ways in which an index can be ineffective or even harmful to query performance:\n1. Leading wildcard: Queries that start with a wildcard (e.g., LIKE '%dev') cannot use the index efficiently, as the database has to scan the entire index.\n2. Function on the column: Applying a function to the indexed column (e.g., lower(email)) prevents the index from being used, as the function changes the value.\n3. Low selectivity: Indexing a column with low selectivity (e.g., a column that contains mostly true or false values) doesn't provide significant performance benefits, as the database has to read most of the index entries.\n\nTo determine whether an index will be useful, it's essential to consider the order of the indexed columns, as this determines how the data is sorted within the index. For example, indexing 'last_name' before 'first_name' allows the database to quickly locate rows with a specific last name, but indexing 'first_name' alone would not provide any benefit.\n\nIn summary, a database index is a valuable tool for improving query performance, but it's not a one-size-fits-all solution. Adding an index can significantly speed up queries, but it also comes with the cost of slower writes and increased storage. Understanding how indexes work and when to use them is crucial for optimizing database performance.",
  "summary": "Same query. Same table. Same million rows. One day it takes 4 seconds . The next day, 4 milliseconds . Nothing changed in the data. The only thing that changed was one line — you added an index . Four seconds to four milliseconds is a thousand times faster, from one line of SQL. But here's the part nobody tells you: half the indexes people add do nothing. The query stays slow, the writes get…",
  "key_points": [
    "A database index speeds up searching in a table but half of added indexes do nothing",
    "Index is a sorted map functioning like a phone book, enabling quick data lookup",
    "Indexes ineffective when using leading wildcard, column function, or low selectivity"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}