← Lessons

quiz vs the machine

Platinum1740

Databases

Avoiding The SELECT Star Anti Pattern

Listing only the columns you need cuts IO, network, and brittleness.

4 min read · advanced · beat Platinum to climb

Why SELECT Star Hurts

SELECT star returns every column of every row. It is convenient when exploring, but in real queries and application code it quietly causes performance and correctness problems.

The Costs

  • The engine reads and ships columns you never use, increasing disk IO and network transfer.
  • Wide columns like large text or binary blobs get pulled along even when unneeded.
  • It can defeat a covering index that would otherwise answer the query from the index alone, forcing extra table lookups.

The Brittleness

  • Adding or reordering a table column can silently change results or break code that reads results by position.
  • Joins with star can produce duplicate column names that are ambiguous and confusing.

The Better Habit

  • Name exactly the columns you need so intent is explicit and stable.
  • A narrow column list lets the planner use covering indexes and skip wide payloads.
  • Reserve SELECT star for quick interactive exploration, not for stored queries or production code paths.

Key idea

SELECT star ships unneeded columns and breaks under schema changes, so naming exactly the columns you need cuts IO, enables covering indexes, and keeps queries stable.

Check yourself

Answer to earn rating on the learn ladder.

1. How can SELECT star defeat a covering index?

2. Why is SELECT star brittle in application code?