{
  "id": 18058846,
  "title": "Not Every Slow Query Needs a New Index",
  "url": "https://urgent.news/2026/11/04/not-every-slow-query-needs-a-new-index",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-04T02:53:03.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/pranay_raavi/not-every-slow-query-needs-a-new-index-5cn8"
  },
  "original_language": "en",
  "account": "A SQL review taught the reporter several lessons about performance tuning. In a development team's SQL review before moving a change-data publishing job from daily to hourly runs, the same run took under 30 seconds after the review. Most of the performance improvement came from reading the queries, understanding the job's needs, and checking assumptions against real data, rather than adding indexes. The key points include:\n\n1. Avoid functions on indexed columns, as they can render the index useless. In the example, a WHERE clause using COALESCE on the updated_at or created_at columns caused a sequential scan of the entire table instead of using the B-tree index.\n\n2. What works in a QA environment may not work in production. Defensive habits, such as using TRIM on a column, can slow down queries in a production database with large amounts of data. The reporter suggests checking the real data shape, such as null counts and value distributions, before implementing changes.\n\n3. Carry every known filter into subqueries. The partner-count query initially had conditions that stopped index usage on the account_type column, leading to slower performance. By carrying the filter into the subquery, the query could utilize the index and improve performance.",
  "summary": "What a SQL review taught me about assumptions, AI-written queries, and common-sense tuning A development team asked me to review the SQL behind a change-data publishing job before they moved it from once a day to once an hour. In QA, one full run took 10 to 12 minutes. After the review, the same run took under 30 seconds. In production, most of its queries now finish in under a millisecond.…",
  "key_points": [],
  "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."
}