F
F
Friend2017-08-31 02:54:51
Python
Friend, 2017-08-31 02:54:51

How to display 50 necessary records from the database to millions?

async with request.app['db'].acquire() as conn:
            result = await conn.execute(
                select([db.my, ]).where(db.my.c.date == date)
            )
            a = await result.fetchall()

Once asked the question "How to request 20 rows from the database?" and I heard the answer that you can use offset and limit, but the point is that if you have 50k records there, then it’s normal, but when there are more than a million there are strong delays. You won't be able to get it by id, since there is still sorting by different parameters.
How can you most efficiently get 50 necessary records [0:50] ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Astrohas, 2017-08-31
@Astrohas

In general, in terms of speed, Limit is no different (well, almost) from a full SELECT. In your case sorting brakes. Try to index the field by which sorting will be carried out.

C
chupasaurus, 2017-08-31
@chupasaurus

No way, if you immediately need data from the 100500th query line, there are cursors for the rest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question