P
P
polupanov_ai2017-09-23 12:56:08
MySQL
polupanov_ai, 2017-09-23 12:56:08

SQL. A selection or all records. What's faster?

Let's say the table has 1000 records. Which is faster, fetching all records or fetching by condition?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
f22, 2017-09-23
@f22

A selection of 1000 in a row without a condition or a selection of the same 1000 with a condition? Of course, without conditions faster.
If the selection is 1000 in a row or 1 by condition - of course, 1 is faster.

T
ThunderCat, 2017-09-23
@ThunderCat

The question is either incomplete/inaccurate or meaningless.
per 1000 records table - selections for such tables with any parameters take 0.0001-0.001, depends on the hardware.
It is logical to assume that fetching 2 fields will not take longer than fetching all fields.
2 fields will be selected faster (the database "knows" where these values ​​​​are from the index, and 1000 fields in a row will shove stupidly longer into the result).
The issue of speed arises when transferring data from the database to the application, and here again it is obvious that the difference in size - a couple of tens of bytes versus a couple of kilobytes (not critical, but there is a difference) speaks in favor of sampling by condition.
In general, under the conditions presented, the difference in sampling rate over the entire existence of this table will not exceed the time spent writing this answer.

S
Sergey, 2017-09-23
@UDAV99

Conditionally, of course. Although if the condition also selects 1000, then there is no difference.

P
polupanov_ai, 2017-09-23
@polupanov_ai

Let's say there is a table with fields id and number. The table has 1000 entries. Out of 1000 records, there are 998 records with number = 1 and 2 records with number = 2. Is it faster to select all records or a query to select records with number = 2? Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question