pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Mielke <mark@mark.mielke.cc>
To: Shoaib Mir <shoaibmir@gmail.com>
Cc: A. Kretschmer <andreas.kretschmer@schollglas.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: count * performance issue
Date: Thu, 06 Mar 2008 01:26:46 -0500
Message-ID: <47CF8EA6.8070503@mark.mielke.cc> (raw)
In-Reply-To: <bf54be870803052215y5bb56235k5ea05ada1d701022@mail.gmail.com>
References: <f966c2ee0803052142l6a105678jfe2da92a0d9371@mail.gmail.com>
	<f966c2ee0803052143k4570d771o6c300647d3b987d@mail.gmail.com>
	<20080306060829.GA21084@a-kretschmer.de>
	<bf54be870803052215y5bb56235k5ea05ada1d701022@mail.gmail.com>

 
>
>     There aren't a general solution. If you realy need the exact count of
>     tuples than you can play with a TRIGGER and increase/decrease the
>     tuple-count for this table in an extra table.
>

Of course, this means accepting the cost of obtaining update locks on 
the count table.

The original poster should understand that they can either get a fast 
estimated count, or they can get a slow accurate count (either slow in 
terms of select using count(*) or slow in terms of updates using 
triggers and locking).

Other systems have their own issues. An index scan may be faster than a 
table scan for databases that can accurately determine counts using only 
the index, but it's still a relatively slow operation, and people don't 
normally need an accurate count for records in the range of 100,000+? :-)

Cheers,
mark

-- 
Mark Mielke <mark@mielke.cc>

view thread (62+ messages)  latest in thread

Message-ID: <47CF8EA6.8070503@mark.mielke.cc>
Permalink:  ../47CF8EA6.8070503@mark.mielke.cc/
Also on:    postgresql.org/message-id/47CF8EA6.8070503@mark.mielke.cc

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: mark@mark.mielke.cc, shoaibmir@gmail.com, andreas.kretschmer@schollglas.com
  Subject: Re: count * performance issue
  In-Reply-To: <47CF8EA6.8070503@mark.mielke.cc>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox