large query by offset and limt

Поиск
Список
Период
Сортировка
От finecur
Тема large query by offset and limt
Дата
Msg-id 69019638-6acd-4e14-af1b-dea697a62620@p25g2000pri.googlegroups.com
обсуждение исходный текст
Ответы Re: large query by offset and limt  (Steve Atkins <steve@blighty.com>)
Re: large query by offset and limt  (Craig Ringer <craig@postnewspapers.com.au>)
Список pgsql-general
Hi, I am ruuning a database behind a webserver and there is a table
which is huge. I need to pull data from this table and send to user
through http. If I use

select * from huge_table where userid = 100

It will return millions of records which exhuasts my server's memory.
So I do this:

select * from huge_table where userid = 100 limit 1000 offset 0
and then send the results to user, then

select * from huge_table where userid = 100 limit 1000 offset 1000
and then send the results to user, then

select * from huge_table where userid = 100 limit 1000 offset 2000
and then send the results to user,

Continue this until there is no records available

It runs great but it is kind of slow. I think it is because even I
need only 1000 records, the query search the whole table every time.

Is there a better way to do this?

Thank you.

ff




В списке pgsql-general по дате отправления:

Предыдущее
От: tekwiz
Дата:
Сообщение: Executing dynamic procedure call
Следующее
От: Steve Atkins
Дата:
Сообщение: Re: large query by offset and limt