Re: Returning the total number of rows as a separate column when using limit

Поиск
Список
Период
Сортировка
От Gregory Stark
Тема Re: Returning the total number of rows as a separate column when using limit
Дата
Msg-id 87fxzkwmir.fsf@oxford.xeocode.com
обсуждение исходный текст
Ответ на Re: Returning the total number of rows as a separate column when using limit  (Andreas Joseph Krogh <andreak@officenet.no>)
Ответы Re: Returning the total number of rows as a separate column when using limit
Список pgsql-sql
"Andreas Joseph Krogh" <andreak@officenet.no> writes:

> That's what I'm doing now. I run the query with "limit+1" as limit and if it 
> results in more than limit, I know there is more data and I run count(*) to 
> count them all. But count(*) cannot use indices in PG so it's limited in 
> speed anyway AFAICS.

Well count(*) can use indexes the same as the query can.

> I really hoped there was an "Oracle over()" equivalent way in PG. I understand 
> that Oracle's LIMIT-hack with "3 subselects and rownum between 1 AND 20" is 
> rather expensive compared to PG's implementation of LIMIT. Oralce keeps 
> snapshot-info in the index, so counting only involves the index AFAIK.

Well that's only going to be true if the index satisfies the whole query which
is not going to be true for the simplest cases.

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com Ask me about EnterpriseDB's PostGIS support!


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

Предыдущее
От: Andreas Joseph Krogh
Дата:
Сообщение: Re: Returning the total number of rows as a separate column when using limit
Следующее
От: Gregory Stark
Дата:
Сообщение: Re: Returning the total number of rows as a separate column when using limit