Could certainly do that - a scalar function that returns reltuples from
pg_class. I was hoping to do 2 additional things:
i) provide better accuracy than the last ANALYZE
ii) make it behave like an aggregate
So I wanted to be able to use estimated_count as you would use count, i.e:
SELECT estimated_count() FROM rel
returns 1 row, whereas the scalar function :
SELECT estimated_count(rel) FROM rel
returns the result as many times as there are rows in rel - of course
you would use
SELECT estimated_count(rel)
but hopefully you see what I mean!
BTW, the scalar function is pretty simple to achieve - here is a basic
example that ignores schema qualifiers:
CREATE FUNCTION estimated_count(text) RETURNS real AS '
SELECT reltuples FROM pg_class WHERE relname = $1;
' LANGUAGE SQL;
cheers
Mark
Simon Riggs wrote:
>
>Why not implement estimated_count as a dictionary lookup, directly using
>the value recorded there by the analyze? That would be the easiest way
>to reuse existing code and give you access to many previously calculated
>values.
>
>
>