Answer the question
In order to leave comments, you need to log in
SQL: which selection is faster - with * or names of all table fields?
What code is faster if we have a table with fields `id`, `name`, `city`? SELECT * FROM `table`
or SELECT `id`, `name`, `city` FROM `table`
?
Answer the question
In order to leave comments, you need to log in
In the example above, there is not much difference. The difference is big and thick when you start using JOIN. You will have a handful of id and who the hell knows where. Or get the same field several times.
It's all about transferring data after processing the request,
in the case of * - all fields will be included in the selection;
if you explicitly list the fields, thereby limiting the fields that will be returned from the request - the amount of data to transfer may be less, therefore the processing will be faster
recalculation of all the required fields is considered good practice + saves the amount of data transferred;)
In terms of speed - works the same, but the second option is preferable
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question