Hello, I have more than a million rows in the database ( MS SQL ), I would like to know how you can optimize queries in this case, the sample from the database. And does anyone know if there is any sense in square brackets when requesting, for example:

 SELECT [id_mark] FROM [dbo].[GET_SPR_BY_NAME] WHERE [mark]= 127 

Or confused to write them!

  • one
    You can speed up a query only by knowing the SQL and the structure of the tables participating in the query, otherwise it is a fortune telling on the coffee grounds. The presence of indexes speeds up the sampling, but slows down the insertion / update of data, so you should use indexes carefully. In addition, the query can be significantly accelerated not by indices, but by changing the query. But for this you need to know the final goal of the query and see the query itself - maybe instead of LEFT JOIN, a simple INNER JOIN will do. - BOPOH

2 answers 2

Square brackets are an exclusive feature of MS SQL, they will not add speed to your query, and are not intended for this at all. Why are they still needed, it says here

  • I read all thanks! - chambo

Square brackets are unlikely to make requests faster (if you strongly carp, then the longer the request, the longer it will be sent over the network, the more it will require memory, the longer it will be parsed ... yes, this slowdown will be a fraction of a percent, but millions of requests can be but who saw the code :) so I don’t even know, maybe the MS is just the opposite).

But more acceleration can be obtained if you arrange the indexes correctly. Especially indexes are good if there are few inserts and many samples. In the above case, the index is needed by the mark field.