Re: Spped of max

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
Cc: Neil Conway <nconway(at)klamath(dot)dyndns(dot)org>, Doug Fields <dfields-pg-general(at)pexicom(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Spped of max
Date: 2002-05-15 15:06:12
Message-ID: 20020516010612.A14367@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, May 15, 2002 at 10:24:55AM -0400, Jean-Luc Lachance wrote:
> The real question is:
>
> Why is reltuples only an approximation?

It's only an approximation because it is updated by VACUUM. It's used to
estimate the cost of queries.

Secondly, remember that there is not really a canonical
number-of-tuples-in-a-table. If you start a transaction and insert a row,
you'll see one more row than any other transaction running at the time. If
you're using a trigger to keep a count of the total, you'll get different
answers depending on whether your trigger is deferred or not. I have no idea
what happens if the trigger is not deferred but a transaction aborts.
Deadlock?

I wish people would remember this before declaring the total number of
tuples in a table a trivial problem.

HTH,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Canada, Mexico, and Australia form the Axis of Nations That
> Are Actually Quite Nice But Secretly Have Nasty Thoughts About America

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2002-05-15 15:11:37 Re: (security) Rules of thumb for escaping user input?
Previous Message Joel Burton 2002-05-15 15:06:04 Re: Using COPY