Re: [RFC] speed up count(*)

2021-10-21 Thread Robert Haas
On Thu, Oct 21, 2021 at 4:29 PM Joe Conway wrote: > meh -- the people who expect this to be impossibly fast don't typically > need or expect it to be exactly correct, and there is no way to make it > "exactly correct" in someone's snapshot without doing all the work. I think it could actually be

Re: [RFC] speed up count(*)

2021-10-21 Thread Andrew Dunstan
On 10/21/21 4:29 PM, Joe Conway wrote: > On 10/21/21 4:23 PM, Robert Haas wrote: >> On Thu, Oct 21, 2021 at 4:19 PM Joe Conway wrote: >>> That is a grossly overstated position. When I have looked, it is often >>> not that terribly far off. And for many use cases that I have heard of >>> at least

Re: [RFC] speed up count(*)

2021-10-21 Thread Joe Conway
On 10/21/21 4:23 PM, Robert Haas wrote: On Thu, Oct 21, 2021 at 4:19 PM Joe Conway wrote: That is a grossly overstated position. When I have looked, it is often not that terribly far off. And for many use cases that I have heard of at least, quite adequate. I don't think it's grossly overstat

Re: [RFC] speed up count(*)

2021-10-21 Thread Robert Haas
On Thu, Oct 21, 2021 at 4:19 PM Joe Conway wrote: > That is a grossly overstated position. When I have looked, it is often > not that terribly far off. And for many use cases that I have heard of > at least, quite adequate. I don't think it's grossly overstated. If you need an approximation it ma

Re: [RFC] speed up count(*)

2021-10-21 Thread Joe Conway
On 10/21/21 4:06 PM, Robert Haas wrote: On Thu, Oct 21, 2021 at 9:09 AM Joe Conway wrote: I think you are exactly correct. People seem to understand that with a predicate it is harder, but they expect select count(*) from foo; to be nearly instantaneous, and they don't really need it to be

Re: [RFC] speed up count(*)

2021-10-21 Thread Robert Haas
On Thu, Oct 21, 2021 at 9:09 AM Joe Conway wrote: > I think you are exactly correct. People seem to understand that with a > predicate it is harder, but they expect > > select count(*) from foo; > > to be nearly instantaneous, and they don't really need it to be exact. > The stock answer for tha

Re: [RFC] speed up count(*)

2021-10-21 Thread Joe Conway
On 10/20/21 2:33 PM, John Naylor wrote: On Wed, Oct 20, 2021 at 2:23 PM Tomas Vondra mailto:tomas.von...@enterprisedb.com>> wrote: > > Couldn't we simply inspect the visibility map, use the index data only > for fully visible/summarized ranges, and inspect the heap for the > remaining pag

Re: [RFC] speed up count(*)

2021-10-20 Thread John Naylor
On Wed, Oct 20, 2021 at 2:41 PM Tomas Vondra wrote: > BTW you mentioned using BRIN indexes for min/max - I've been thinking > about using BRIN indexes for ordering/sorting, which seems related. And > I think it's actually doable, so I wonder why you concluded using BRIN > indexes for min/max is n

Re: [RFC] speed up count(*)

2021-10-20 Thread Tomas Vondra
On 10/20/21 20:33, John Naylor wrote: On Wed, Oct 20, 2021 at 2:23 PM Tomas Vondra mailto:tomas.von...@enterprisedb.com>> wrote: > > Couldn't we simply inspect the visibility map, use the index data only > for fully visible/summarized ranges, and inspect the heap for the > remaining pa

Re: [RFC] speed up count(*)

2021-10-20 Thread John Naylor
On Wed, Oct 20, 2021 at 2:23 PM Tomas Vondra wrote: > > Couldn't we simply inspect the visibility map, use the index data only > for fully visible/summarized ranges, and inspect the heap for the > remaining pages? That'd still be a huge improvement for tables with most > only a few pages modified

Re: [RFC] speed up count(*)

2021-10-20 Thread Tomas Vondra
On 10/20/21 19:57, Tom Lane wrote: John Naylor writes: Perennially our users have complaints about slow count(*) when coming from some other systems. Index-only scans help, but I think we can do better. I recently wondered if a BRIN index could be used to answer min/max aggregate queries over t

Re: [RFC] speed up count(*)

2021-10-20 Thread Andres Freund
Hi, On October 20, 2021 10:57:50 AM PDT, Tom Lane wrote: >John Naylor writes: >> Perennially our users have complaints about slow count(*) when coming from >> some other systems. Index-only scans help, but I think we can do better. I >> recently wondered if a BRIN index could be used to answer

Re: [RFC] speed up count(*)

2021-10-20 Thread Tom Lane
John Naylor writes: > Perennially our users have complaints about slow count(*) when coming from > some other systems. Index-only scans help, but I think we can do better. I > recently wondered if a BRIN index could be used to answer min/max aggregate > queries over the whole table, and it turns o

[RFC] speed up count(*)

2021-10-20 Thread John Naylor
Hi, Perennially our users have complaints about slow count(*) when coming from some other systems. Index-only scans help, but I think we can do better. I recently wondered if a BRIN index could be used to answer min/max aggregate queries over the whole table, and it turns out it doesn't. However,