K
K
Korolenkz2016-08-19 09:50:55
MySQL
Korolenkz, 2016-08-19 09:50:55

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

4 answer(s)
D
Dmitry Kovalsky, 2016-08-19
@Korolenkz

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.

K
Kirill Netesin, 2016-08-19
@knetesin

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;)

M
Max, 2016-08-19
@AloneCoder

In terms of speed - works the same, but the second option is preferable

M
My joy, 2016-08-19
@t-alexashka

If there are 10 fields in the table and they are all needed when querying - write *
And if you need only 5 fields, for example, then it is better to list them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question