Re: Fwd: extend statistics help reduce index scan a lot of shared buffer hits.

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: James Pang <jamespang886(at)gmail(dot)com>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Fwd: extend statistics help reduce index scan a lot of shared buffer hits.
Date: 2024-02-28 14:53:55
Message-ID: 35513c9b-7dae-4c07-b114-f2771a1f3aca@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 2/27/24 14:58, James Pang wrote:
> Postgresql 14.8, Redhat8. looks like have to create extend statistics
> on indexed and joined columns to make join filters pushed down to secondary
> index scan in nestloop, and the shared buffer hits show big difference.
>
> is it expected ?
>

It's hard to say what exactly is happening in the example query (I'd
have to do some debugging, but that's impossible without a reproducer),
but I think it's mostly expected.

My guess is that without the stats the optimizer sees this:

-> Index Scan using idx_mtgattndlstext_mmmuuid_uid on mtgxxxxxxxext b
(cost=0.56..2.78 rows=1 width=133) (actual time=0.016..0.698 rows=2142
loops=2142)

and so decides there's no point in pushing down more conditions to the
index scan (because it already returns just 1 row). But there's some
sort of correlation / skew, and it returns 2142 rows.

With the extended stats it realizes pushing down more conditions makes
sense, because doing that in index scan is cheaper than having to read
the heap pages etc. So it does that.

So yeah, this seems exactly the improvement you'd expect from extended
stats. Why do you think this would not be expected?

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message James Pang 2024-02-29 14:27:42 generic plan generate poor performance
Previous Message James Pang 2024-02-27 13:58:59 Fwd: extend statistics help reduce index scan a lot of shared buffer hits.