It is said that senior programmers know 6 SQL optimization skills

Gejiufelix
Javarevisited
Published in
5 min readMar 16, 2023

--

Photo by Matthias Götzke on Unsplash

In our work, SQL optimization is often encountered, and everyone is familiar with it, but everyone has their own way of optimizing techniques. In the project, if there is a performance problem in the interface of our production environment, what should we do?

For experienced friends, the first thing that comes to mind is to optimize the sql statement, because if the optimization is done well, the cost is much smaller than changing the code.
Next, let’s learn the following tips together:

1. Try not to use select *

For many friends, due to habit problems, when writing SQL statements, for the convenience of a moment, they like to directly use select * to find out the data of all columns in the table at once

But in fact, in actual business use, in many cases, only one or two columns are used. This will bring out a problem, waste of resources, check a lot of data, but not to be used, then a waste of resources such as memory or cpu. Of course, it’s not just about these, because there are more data to be checked, the time of data transmission will also be increased during the process of IO transmission through the network.

--

--