Back to Writing
Growth status: Growing GrowingUpdated: Jan 27, 20262 min read

Learning to Think in Sets, Not Loops

Indexes are another area where intuition often fails. Indexes do not speed up queries universally; they optimize specific access path

SQL is often treated as an implementation detail something to hide behind an ORM or repository layer. That attitude usually survives until the first serious performance incident. At that point, SQL becomes unavoidable.

SQL is not just a query language. It is a way of thinking about data that forces clarity.

The hardest part of SQL is not syntax, but mindset. SQL requires a shift from imperative thinking to declarative thinking. When developers think in loops, they tend to write inefficient queries. SQL rewards those who describe sets, relationships, and constraints precisely.

A useful rule of thumb:

If you find yourself thinking “for each row…”, you are probably about to write a bad query.

Good SQL starts with good schema design. When tables reflect real-world relationships clearly, queries become simpler and faster. This is why SQL is inseparable from [[Database]] design.

Indexes are often misunderstood. They are not universal speed boosts. They are promises to the query planner about access paths. Adding indexes without understanding query patterns leads to bloated storage, slower writes, and false confidence.

Some hard-earned SQL heuristics:

  • Avoid SELECT * in production code
  • Read execution plans before optimizing
  • Optimize queries before adding caches
  • If a query is fast and you don’t know why, you don’t understand it yet
  • Aggregations hide bugs as easily as they hide rows

SQL is also a truth serum for business logic. Vague requirements collapse when forced into queries. Terms like “latest”, “active”, or “valid” demand precision. This is why SQL pairs naturally with [[API Design]] and reporting work.

Concurrency exposes the cost of misunderstanding SQL. Isolation levels, locking, and transactions are not academic topics. Many data corruption bugs are simply misunderstood transactional behavior.

Avoiding SQL does not simplify systems. It moves complexity into places where it is harder to see, harder to measure, and harder to fix.

SQL teaches humility. Data has gravity.

Share this writing