pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: pgsql-general@lists.postgresql.org
Subject: Mysteriously varying index scan costs
Date: Mon, 24 Sep 2018 10:50:15 +0200
Message-ID: <0979b9133184be5bdec8a99324854bf95656942f.camel@cybertec.at> (raw)

Last week I encountered the following at a customer site on PostgreSQL 9.6,
and I cannot explain it.

The first run gave me this:

 Index Scan using device_outbound_messages_status on device_outbound_messages  (cost=0.43..20.46 rows=97 width=128) (actual time=34.021..35.545 rows=133 loops=1)
   Index Cond: ((status)::text = ANY ('{WAITING_FOR_TX,WAITING_FOR_IMMEDIATE_TX}'::text[]))
   Buffers: shared hit=74917 dirtied=707

Subsequent runs of the same query gave me:

 Index Scan using device_outbound_messages_status on device_outbound_messages  (cost=0.43..20.46 rows=97 width=128) (actual time=2.129..3.907 rows=133 loops=1)
   Index Cond: ((status)::text = ANY ('{WAITING_FOR_TX,WAITING_FOR_IMMEDIATE_TX}'::text[]))
   Buffers: shared hit=1185

There were no concurrent changes to the data (test environment).
This was part of a bigger statement.

I understand that some pages can be dirtied because table fetches that
cause hint bits to be set.

But how can it be that the first run has to touch 74917 blocks,
while whe second run only needs to touch 1185?

Thanks for any ideas!

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





view thread (3+ messages)  latest in thread

Message-ID: <0979b9133184be5bdec8a99324854bf95656942f.camel@cybertec.at>
Permalink:  ../0979b9133184be5bdec8a99324854bf95656942f.camel@cybertec.at/
Also on:    postgresql.org/message-id/0979b9133184be5bdec8a99324854bf95656942f.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
  Subject: Re: Mysteriously varying index scan costs
  In-Reply-To: <0979b9133184be5bdec8a99324854bf95656942f.camel@cybertec.at>
  References: <0979b9133184be5bdec8a99324854bf95656942f.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