Re: [HACKERS] Much Ado About COUNT(*)

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: [HACKERS] Much Ado About COUNT(*)
Дата
Msg-id 20050114183835.GB1724@svana.org
обсуждение исходный текст
Ответ на Re: [HACKERS] Much Ado About COUNT(*)  ("Frank D. Engel, Jr." <fde101@fjrhome.net>)
Ответы Re: [HACKERS] Much Ado About COUNT(*)  ("Frank D. Engel, Jr." <fde101@fjrhome.net>)
Список pgsql-general
On Fri, Jan 14, 2005 at 12:39:04PM -0500, Frank D. Engel, Jr. wrote:
> This is probably stupid for some reason, but why not use a 64-bit
> integer to track the number of records in the table? Increment when
> adding records, decrement when deleting them... then COUNT(*) could
> just return that in cases where a query is known to be looking at all
> of the records?

Because there is no single value for count(*), if you're in a
transaction that has added records it will be bigger than in a
transaction that hasn't. How does your integer deal with this?

The usual solutions this involve locking, which is precisely what MVCC
is designed to avoid.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения

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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: [HACKERS] Much Ado About COUNT(*)
Следующее
От: Bo Lorentsen
Дата:
Сообщение: Re: OID Usage