Re: Win2K Questions

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, "Charles H(dot) Woloszynski" <chw(at)clearmetrix(dot)com>, Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Win2K Questions
Date: 2002-11-08 23:06:27
Message-ID: 3DCC4373.AA51BBB@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Scott,

unless id is indexed there is nothing that can be done with
select count(*) from table where id >10000;
Otherwise, the index should be scanned, not the table.

And, scanning a large table to get count(*) will always be worst than
maintaining your own count.

JLL

"scott.marlowe" wrote:
>[...]
>
> select count(*) from table where id >10000;

>[...]

> But the performance of updating that secondary table may be worse than
> just running a count(*).

>
> I doubt the black (gray??? :-) magic needed to do this will be put into
> the backend of postgresql any time soon. But the userland solution is
> something that could be quite useful.
>
> On Fri, 8 Nov 2002, Jean-Luc Lachance wrote:
>
> > Scott,
> >
> > You answered the question yourself. The operative keyword her is
> > *before* the transaction started.
> > You store the global count before the transaction. While in a
> > transaction, you save the number of inserted and deleted records. When
> > *all* parallel transactions are commited, you update the global count
> > with the total of of updated and deleted records. If a connection start
> > a new transaction before the other transactions have been
> > commited you take the global count plus the adjustment from the previous
> > transaction.
> >
> > JLL
> >
> > "scott.marlowe" wrote:
> > >
> > > but how do you handle the case where two people have two different
> > > connections, and one starts a serializable transaction and adds n rows to
> > > the table. For that transaction, there are x+n rows in the table, while
> > > for the transaction started before his, there are only x rows. which is
> > > the "right" answer?
> > >
> > > On Fri, 8 Nov 2002, Jean-Luc Lachance wrote:
> > >
> > > > Here is a suggestion.
> > > >
> > > > When a count(*) is computed (for all records) store that value and
> > > > unvalidate it if there is a later insert or delete on the table. Next
> > > > improvement would be to maintain a count per active transaction.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2002-11-08 23:25:29 Re: Win2K Questions
Previous Message Benjamin Scherrey 2002-11-08 22:54:58 Re: Configuring postgresql build to handle long names