G
G
gomerIT2020-10-04 23:19:27
SQL
gomerIT, 2020-10-04 23:19:27

What is the best way to query the database at once or several times to get data?

I need to display the data of users in the admin panel that are registered in the system. If, for example, there are 100k users in total. The output is in the form of a table of the first 15 users, followed by padding with toggle buttons. How to do better in terms of optimizations? Run 1 request to get all the data or multiple requests?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
nokimaro, 2020-10-04
@gomerIT

Request as much data as you want to display.
LIMIT + OFFSET to the rescue.

P
Pandorex, 2020-10-05
@Pandorex

LIMIT + OFFSET on values ​​far from the beginning - they will be slower
assuming that you have a sort by some field, it would be best to pass the last value by which the sort is specified as an offset and add it to the request as "email > 'LAST_EMAIL' "
as a rule, output far from the beginning is not required and it is easier to implement the usual LIMIT + OFFSET

C
cicatrix, 2020-10-07
@cicatrix

I'll throw in my thoughts. 10K users divided into pages of 15 will represent 6667 pages.
Yes, of course, you can make a similar breakdown, as it has already been written here, but this is the same as doing "fuck off!"
It is quite obvious that not a single person in their right mind and sober memory will flip through 6K pages.
Naturally, having learned this, it is necessary to return to the beginning and understand which users and by what criteria the operator will search in this interface. Apparently, he does not need all users without exception, he needs some special ones that differ in some way. Accordingly, the interface should be provided in such a way as to facilitate this search.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question