The Backend Engineering Show with Hussein Nasser cover image

The Backend Engineering Show with Hussein Nasser

A Deep Dive in How Slow SELECT * is

May 2, 2023
39:23

Podcast summary created with Snipd AI

Quick takeaways

  • Selecting all columns in a table can significantly impact performance due to network costs and the deserialization and compression of large columns.
  • In a row-store database, selecting all columns can lead to additional IO operations and overhead when accessing external tables and handling large columns.

Deep dives

Select Star is Slow

Select Star is a universal SQL syntax that returns all columns in a table. Although it has been said to be slow and should be avoided, it is important to understand why. One reason is that returning multiple columns is slower than returning a single column. This is especially true when dealing with network aspects, programming logic, memory management, and how the OS works. Another reason is that when using Select Star, index-only scans are no longer feasible. Index-only scans allow the database to directly access the columns specified in the index, without going through the table data. However, when using Select Star, the database has to fetch all columns, including those that are not specified in any index. This leads to additional random reads and increased IO. Additionally, the deserialization cost of retrieving and parsing all columns can add up, especially when dealing with large text, blob, or JSON fields. Lastly, network costs must be considered, as the data needs to be serialized, transmitted across the network, and deserialized by the client app. Overall, Select Star can significantly impact performance and should be used with caution.

Remember Everything You Learn from Podcasts

Save insights instantly, chat with episodes, and build lasting knowledge - all powered by AI.
App store bannerPlay store banner