Approximate count(*)
Folks,
Please find enclosed a patch that shows how to get a quick
approximation of count(*) on a table.
Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778
Remember to vote!
Attachments:
approx_count.difftext/plain; charset=us-asciiDownload+15-14
David Fetter <david@fetter.org> writes:
Please find enclosed a patch that shows how to get a quick
approximation of count(*) on a table.
I'm not sure we should be encouraging people to look at reltuples...
for one thing, it's deliberately a moving average under 8.0.
regards, tom lane
On Thu, Mar 24, 2005 at 12:34:51PM -0500, Tom Lane wrote:
David Fetter <david@fetter.org> writes:
Please find enclosed a patch that shows how to get a quick
approximation of count(*) on a table.I'm not sure we should be encouraging people to look at reltuples...
for one thing, it's deliberately a moving average under 8.0.
Should there be more caveats?
Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778
Remember to vote!
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David Fetter wrote:
Please find enclosed a patch that shows how to get a quick
approximation of count(*) on a table.
You should mention that ANALYZE will also populate reltuples.
To be real anal, you should say pg_catalog.pg_class too. :)
Tom Lane asked:
I'm not sure we should be encouraging people to look at reltuples...
for one thing, it's deliberately a moving average under 8.0.
Should there be more caveats?
Well, it already says "approximate", the value-laden word is "good".
Perhaps if that went away...
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200503242126
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
iD8DBQFCQ3iivJuQZxSWSsgRAm+PAKCNJPUl7Xns0kLKvbDjOiuNN2g4agCfbmg+
hX8RHO4R2Ad2fQyCPl+Ha3I=
=2Gal
-----END PGP SIGNATURE-----
David,
If Jim and I finish our work for 8.1, then you'll be able to do:
SELECT approx_records FROM pg_sysviews.pg_tables WHERE schema_name = 'schema'
AND table_name = 'table'
But the same caveats will apply.
--
Josh Berkus
Aglio Database Solutions
San Francisco
Josh, David-
Do you think it's worth adding a function that would do the select for
you? IE: tuplecount('schema', 'tablename')?
On Thu, Mar 24, 2005 at 07:19:00PM -0800, Josh Berkus wrote:
David,
If Jim and I finish our work for 8.1, then you'll be able to do:
SELECT approx_records FROM pg_sysviews.pg_tables WHERE schema_name = 'schema'
AND table_name = 'table'But the same caveats will apply.
--
Josh Berkus
Aglio Database Solutions
San Francisco---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
--
Jim C. Nasby, Database Consultant decibel@decibel.org
Give your computer some brain candy! www.distributed.net Team #1828
Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"