Re: Yet Another COUNT(*)...WHERE...question - Mailing list pgsql-general

From Phoenix Kiula
Subject Re: Yet Another COUNT(*)...WHERE...question
Date
Msg-id e373d31e0708150836s1115447aw4944c133f1b247b4@mail.gmail.com
Whole thread Raw
In response to Re: Yet Another COUNT(*)...WHERE...question  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Responses Re: Yet Another COUNT(*)...WHERE...question  (Bill Moran <wmoran@potentialtech.com>)
List pgsql-general
> Yes, optimization. :)  You don't need an exact count to tell someone
> that there's more data and they can go to it.


In general, I agree. But my example of Amazon was only to illustrate
the point about two queries and why they may be needed. I seem to see
many more pages than you do, but in any case, Google and Amazon can
afford to be less precise.

Thanks for the suggestion of using EXPLAIN and parsing an
approximation, but when you need to show a trader how many trades he
has made, for instance, then approximation is not a possibility at
all. Especially not if the numbers sway so wildly --


FIRSTDB=# explain select * from trades where t_id = 'kXjha';
                                    QUERY PLAN
-----------------------------------------------------------------------------------
 Bitmap Heap Scan on trades (cost=15.77..1447.12 rows=374 width=224)
   Recheck Cond: ((t_id)::text = 'kXjha'::text)
   ->  Bitmap Index Scan on trades_tid_date  (cost=0.00..15.67 rows=374 width=0)
         Index Cond: ((t_id)::text = 'kXjha'::text)
(4 rows)

FIRSTDB=# select count(*) from trades where t_id = 'kXjha';
 count
-------
  3891
(1 row)



Could I do something so that the EXPLAIN showed up with slightly more
close-to-accurate stats? The above query is just after a "vacuum
analyze"!

Much appreciate the suggestions.

pgsql-general by date:

Previous
From: Richard Broersma Jr
Date:
Subject: Re: Customizing psql console to show execution times
Next
From: "Leif B. Kristensen"
Date:
Subject: Re: Customizing psql console to show execution times