Re: [SQL] Make COUNT(*) Faster?

2005-07-10 Thread Harald Fuchs
In article <[EMAIL PROTECTED]>,
Dawid Kuroczko <[EMAIL PROTECTED]> writes:

> Use
> EXPLAIN SELECT * FROM yourcountedtable;

> Planner seems to track estimated statistics on-the-fly. :)

> You can even wrap EXPLAIN SELECT in a pgsql function if you
> need it.

Do you know how to do that?  A function "approx_count(tablename)"
would be really handy, but

  FOR row IN EXECUTE 'EXPLAIN SELECT * FROM ' || tbl LOOP

fails with the following message:

  ERROR:  cannot open non-SELECT query as cursor

> PS: And be aware that these are 'statistics'.  And the statement that there
> are lies, big lies and statistics is sometimes true even for PostgreSQL. ;-)

Does this mean that PostgreSQL believes only in statistics it has
faked itself?  ;-)


---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] Make COUNT(*) Faster?

2005-07-10 Thread Tom Lane
Harald Fuchs <[EMAIL PROTECTED]> writes:
>   FOR row IN EXECUTE 'EXPLAIN SELECT * FROM ' || tbl LOOP
> fails with the following message:
>   ERROR:  cannot open non-SELECT query as cursor

[ checks CVS history... ]  Use 8.0.2 or later.

regards, tom lane

---(end of broadcast)---
TIP 6: explain analyze is your friend