Re: Use of additional index columns in rows filtering

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>, James Coleman <jtc331(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Maxim Ivanov <hi(at)yamlcoder(dot)me>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Peter Geoghegan <pg(at)bowt(dot)ie>
Subject: Re: Use of additional index columns in rows filtering
Date: 2023-07-19 09:16:44
Message-ID: 041e9774-ea76-f878-883b-37b2b362f4de@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7/19/23 01:22, Jeff Davis wrote:
> On Wed, 2023-07-19 at 00:36 +0200, Tomas Vondra wrote:
>>> * I'm confused about the relationship of an IOS to an index filter.
>>> It
>>> seems like the index filter only works for an ordinary index scan?
>>> Why
>>> is that?
>>
>> What would it do for IOS?
>
> The way it's presented is slightly confusing. If you have table x with
> and index on column i, then:
>
> EXPLAIN (ANALYZE, BUFFERS)
> SELECT i, j FROM x WHERE i = 7 and (i % 1000 = 7);
>
> Index Scan using x_idx on x (cost=0.42..8.45 rows=1 width=8)
> (actual time=0.094..0.098 rows=1 loops=1)
> Index Cond: (i = 7)
> Index Filter: ((i % 1000) = 7)
>
> But if you remove "j" from the target list, you get:
>
> EXPLAIN (ANALYZE, BUFFERS)
> SELECT i FROM x WHERE i = 7 and (i % 1000 = 7);
>
> Index Only Scan using x_idx on x (cost=0.42..4.45 rows=1 width=4)
> (actual time=0.085..0.088 rows=1 loops=1)
> Index Cond: (i = 7)
> Filter: ((i % 1000) = 7)
>
> The confused me at first because the "Filter" in the second plan means
> the same thing as the "Index Filter" in the first plan. Should we call
> the filter in an IOS an "Index Filter" too? Or is that redundant?
>

I agree the naming in explain is a bit confusing.

I wonder if Andres was right (in the index prefetch thread) that
splitting regular index scans and index-only scans may not be ideal. In
a way, this patch moves those nodes closer, both in capability and code
(because now both use index_getnext_tid etc.).

regards

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2023-07-19 10:12:07 Re: A minor adjustment to get_cheapest_path_for_pathkeys
Previous Message Andres Freund 2023-07-19 08:52:36 Re: Avoid stack frame setup in performance critical routines using tail calls