Skip the Asterisk: Why SELECT * is Slowing Down Your SQL Queries

Steve Sohcot
2 min readAug 11, 2024
Image created by author using AI; trying to capture the concept of SQL’s speed

TLDR; Don’t do SELECT * FROM myTable in your query . Explicitly ask for the fields.

I’ve heard the advice before: specify only the fields you need in a SQL query: don’t do SELECT *

I was working with a large dataset in MS SQL Server. The code I inherited had a SELECT * . The query was terribly slow. Just by listing the fields (there were a lot; around 50), that significantly cut down on the time it took to load.

While indexes aren’t technically ignored with SELECT * , the indexes may not be used efficiently. Think of an index like a shortcut to your data. When you do SELECT * the database may skip the shortcut and go directly to the table, which may be slower.

By the way, asking for only the fields you need will speed up the processing time, too. Here, I only needed ~20 of the ~50 fields, which also helped.

Other reasons to not to a SELECT *:

  • Security: incase a sensitive field is in the table (or gets added after creation)
  • Ambiguous JOINs: if the table you’re linking to has a field with the same name, you may get an error
  • Readability: you’ll know which columns are really needed, which helps understand what the query is doing

--

--