pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedMysteriously varying index scan costs
3+ messages / 2 participants
[nested] [flat]
* Mysteriously varying index scan costs
@ 2018-09-24 08:50 Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 3+ messages in thread
From: Laurenz Albe @ 2018-09-24 08:50 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Mysteriously varying index scan costs
@ 2018-09-24 08:56 Pavan Deolasee <pavan.deolasee@gmail.com>
parent: Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 3+ messages in thread
From: Pavan Deolasee @ 2018-09-24 08:56 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: pgsql-general@lists.postgresql.org
On Mon, Sep 24, 2018 at 2:20 PM, Laurenz Albe <laurenz.albe@cybertec.at>
wrote:
>
>
> But how can it be that the first run has to touch 74917 blocks,
> while whe second run only needs to touch 1185?
>
>
The first index scan may have killed lots of index tuples.
Thanks,
Pavan
--
Pavan Deolasee http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Mysteriously varying index scan costs
@ 2018-09-24 10:03 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Pavan Deolasee <pavan.deolasee@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Laurenz Albe @ 2018-09-24 10:03 UTC (permalink / raw)
To: Pavan Deolasee <pavan.deolasee@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
Pavan Deolasee wrote:
> On Mon, Sep 24, 2018 at 2:20 PM, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
> >
> > But how can it be that the first run has to touch 74917 blocks,
> > while whe second run only needs to touch 1185?
> >
>
> The first index scan may have killed lots of index tuples.
So the first index scan visited lots of table tuples, found them
dead, and set the LP_DEAD flag on the corresponding index items
so that subsequent index scans could ignore them, right?
Thanks, that must be the correct explanation. It correlates nicely
with the dirtied pages, too.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2018-09-24 10:03 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-09-24 08:50 Mysteriously varying index scan costs Laurenz Albe <laurenz.albe@cybertec.at>
2018-09-24 08:56 ` Pavan Deolasee <pavan.deolasee@gmail.com>
2018-09-24 10:03 ` Laurenz Albe <laurenz.albe@cybertec.at>
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