pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Daniel Westermann <daniel.westermann@dbi-services.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: index only scan question
Date: Fri, 09 Nov 2018 14:12:02 +0100
Message-ID: <96183def4b971c718367fdbc6021f6b9706f03ea.camel@cybertec.at> (raw)
In-Reply-To: <AM4PR0901MB1346BBF200903002F6E74539D2C60@AM4PR0901MB1346.eurprd09.prod.outlook.com>
References: <AM4PR0901MB1346BBF200903002F6E74539D2C60@AM4PR0901MB1346.eurprd09.prod.outlook.com>

Daniel Westermann wrote:
> question: Given these steps:
> 
> 
> postgres=# explain (analyze,buffers,costs off) select a from t1 where b = 5;
>                                 QUERY PLAN                                
> --------------------------------------------------------------------------
>  Index Only Scan using i2 on t1 (actual time=0.056..0.058 rows=1 loops=1)
>    Index Cond: (b = 5)
>    Heap Fetches: 0
>    Buffers: shared hit=4
>  Planning time: 0.421 ms
>  Execution time: 0.111 ms
> (6 rows)
> 
> postgres=# update t1 set a = 30 where b = 5;
> UPDATE 1
> postgres=# explain (analyze,buffers,costs off) select a from t1 where b = 5;
>                                 QUERY PLAN                                
> --------------------------------------------------------------------------
>  Index Only Scan using i2 on t1 (actual time=0.039..0.042 rows=1 loops=1)
>    Index Cond: (b = 5)
>    Heap Fetches: 2
>    Buffers: shared hit=5
>  Planning time: 0.176 ms
>  Execution time: 0.082 ms
> 
> The 2 heap fetches for the second run are clear to me, because of the pointer from the old version of the row to the new one. But why does the next execution only need one heap fetch?
> 
> 
> postgres=# explain (analyze,buffers,costs off) select a from t1 where b = 5;
>                                 QUERY PLAN                                
> --------------------------------------------------------------------------
>  Index Only Scan using i2 on t1 (actual time=0.046..0.049 rows=1 loops=1)
>    Index Cond: (b = 5)
>    Heap Fetches: 1
>    Buffers: shared hit=5
>  Planning time: 0.194 ms
>  Execution time: 0.097 ms
> 
> Is that because of some sort of caching?

I'd say the old index tuple was killed during the first scan:
https://www.cybertec-postgresql.com/en/killed-index-tuples/

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com





view thread (8+ messages)  latest in thread

Message-ID: <96183def4b971c718367fdbc6021f6b9706f03ea.camel@cybertec.at>
Permalink:  ../96183def4b971c718367fdbc6021f6b9706f03ea.camel@cybertec.at/
Also on:    postgresql.org/message-id/96183def4b971c718367fdbc6021f6b9706f03ea.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, daniel.westermann@dbi-services.com
  Subject: Re: index only scan question
  In-Reply-To: <96183def4b971c718367fdbc6021f6b9706f03ea.camel@cybertec.at>
  References: <AM4PR0901MB1346BBF200903002F6E74539D2C60@AM4PR0901MB1346.eurprd09.prod.outlook.com> <96183def4b971c718367fdbc6021f6b9706f03ea.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox