{"product_id":"b0h8vy5hx1","title":"Refactoring SQL: A Pattern-Oriented Guide to Database Design, Query Optimization, and Schema Refactoring","description":"\u003cp\u003eMost SQL books teach you syntax. This one teaches you how to think like a query optimizer.\u003c\/p\u003e\n\n\u003cp\u003eIf you've ever stared at an execution plan wondering why a query that runs fine in development takes 30 seconds in production, this book is for you. If you've inherited a database where every table is named t_data and every column is VARCHAR(255), this book is for you. If you've been told just add an index without understanding which index, why it works, or when it makes things worse, this book is for you.\u003cbr\u003e\nRefactoring SQL  is not a syntax reference. It's a pattern-oriented field manual for making relational databases faster, cleaner, and more maintainable — without taking them offline.\u003c\/p\u003e\n\n\u003cp\u003eWhat's inside\u003c\/p\u003e\n\n\u003cp\u003ePart I — Foundations.  Why database refactoring is fundamentally harder than code refactoring. How the query planner works, how it estimates cost, and how to read execution plans. Seven universal performance principles that every other chapter builds on: read fewer rows, read fewer columns, do less work, reuse work, minimize writes, think in sets, and measure before optimizing.\u003c\/p\u003e\n\n\u003cp\u003ePart II — Query Refactoring . Predicate pushdown, EXISTS vs IN, converting correlated subqueries to JOINs, window functions as a replacement for self-joins, eliminating unnecessary DISTINCT, and why SELECT * is a liability. A full chapter on keyset pagination and why OFFSET 100000 destroys performance. A chapter on set-based thinking that will change how you write SQL.\u003c\/p\u003e\n\n\u003cp\u003ePart III — Index Refactoring . B-trees, hash indexes, GiST, GIN, BRIN. Covering indexes, composite indexes, column ordering, partial indexes, functional indexes. An entire chapter on sargability — the most important indexing concept that most books barely mention — covering why WHERE UPPER(name) = 'SMITH' can't use your index, and exactly how to fix it.\u003c\/p\u003e\n\n\u003cp\u003ePart IV — Schema Refactoring . Renaming tables safely. Splitting and merging tables. Strategic denormalization: when to duplicate data, materialize aggregates, cache counts, and build read models — and how to manage the consistency trade-offs. Partitioning from 100M rows to monthly partitions to archive tables, with real migration scripts.\u003c\/p\u003e\n\n\u003cp\u003ePart V — Refactoring for Scale . Materialized views, read replicas, caching strategies. Batch writes, event sourcing, async processing. Transactions, isolation levels, MVCC internals, deadlock prevention, optimistic and pessimistic locking — covered in more depth than the typical use transactions advice.\u003c\/p\u003e\n\n\u003cp\u003ePart VI — Database Smells.  39 smells you can detect and fix today: SELECT *, N+1 queries, huge OFFSETs, DISTINCT addiction, OR abuse, cartesian joins, correlated subqueries, EAV tables, comma-separated values, missing foreign keys, over-indexing, VARCHAR for everything, duplicate indexes, wrong column orders, and more. Each smell includes detection queries and a concrete fix.\u003c\/p\u003e\n\n\u003cp\u003ePart VII — Practical Refactoring Catalog . The heart of the book. 80 concrete refactorings, each with: the problem SQL, the solution SQL, ASCII execution plans before and after, when to use it, and when not to.\u003cbr\u003e\nPart VIII — Database Engineering. Monitoring with pg_stat_statements and the Performance Schema. Benchmarking with EXPLAIN ANALYZE done properly. Zero-downtime migrations using the expand-contract pattern for production schema changes.\u003c\/p\u003e\n\n\u003cp\u003eParts IX–X — Reference . A complete SQL reference covering data types, constraints, joins, window functions, CTEs, MERGE\/UPSERT, materialized views, transactions, isolation levels, JSOrrays, and a comprehensive SQL functions reference with vendor-to-vendor mapping tables. Appended with an SQL:86 to SQL:2023 evolution guide.\u003cbr\u003e\nWhat makes this book different\u003c\/p\u003e","brand":"ANT","offers":[{"title":"Ebook","offer_id":67902056825077,"sku":"YSL49424","price":5.0,"currency_code":"USD","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0817\/8774\/8597\/files\/71D8Adyt-SL._SY1500.jpg?v=1793436802","url":"https:\/\/www.newbooks.store\/products\/b0h8vy5hx1","provider":"NewBooks","version":"1.0","type":"link"}