pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dimitrios Apostolou <jimis@gmx.net>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: SELECT * FROM huge_table LIMIT 10; Why does it take more than 10 min to complete, with cold caches
Date: Tue, 31 Jan 2023 12:15:29 -0500
Message-ID: <1137029.1675185329@sss.pgh.pa.us> (raw)
In-Reply-To: <8504ea0b-584f-773b-44c1-233f4ac8e630@gmx.net>
References: <b847d458-5a03-718e-5467-422fc0e51004@gmx.net>
	<1079393.1675178901@sss.pgh.pa.us>
	<8504ea0b-584f-773b-44c1-233f4ac8e630@gmx.net>

Dimitrios Apostolou <jimis@gmx.net> writes:
> On Tue, 31 Jan 2023, Tom Lane wrote:
>> Do you get the same 10 rows when you repeat the command?

> Yes. Just tested with both cold and hot caches. The first 10 rows are
> exactly the same, either they return slowly or immediately.

Hm.  I don't recall exactly how synchronize_seqscans works --- it
definitely changes the point in the table where a seqscan begins
scanning, but I don't remember where/when that point gets updated
(and I'm too lazy to go look).  This result suggests that the first
query advances the table's sync start point to someplace a bit before
the first live tuple, not after all the returned tuples as I'd been
thinking.  It might be that the start point is always the beginning
of a block, so that if you fetch only a few tuples that are all in
the same block then the next attempt will re-fetch them.  If you
increase the LIMIT to say 1000, does the behavior (with
synchronize_seqscans on) change?

>> If turning synchronize_seqscans off changes the behavior, that'd
>> be a good clue that this is the right theory.

> Turning it off makes the query slow no matter how many times I re-run it.

OK, well that's enough of a smoking gun to say that it is the sync
start point that's the relevant state, and not the contents of your
data caches at all.

Anyway, the follow-on discussion makes it clear that you do indeed
have a badly bloated table, and fixing that situation should fix
this performance issue.

			regards, tom lane





view thread (11+ messages)  latest in thread

Message-ID: <1137029.1675185329@sss.pgh.pa.us>
Permalink:  ../1137029.1675185329@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1137029.1675185329@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, jimis@gmx.net
  Subject: Re: SELECT * FROM huge_table LIMIT 10; Why does it take more than 10 min to complete, with cold caches
  In-Reply-To: <1137029.1675185329@sss.pgh.pa.us>
  References: <b847d458-5a03-718e-5467-422fc0e51004@gmx.net> <1079393.1675178901@sss.pgh.pa.us> <8504ea0b-584f-773b-44c1-233f4ac8e630@gmx.net> <1137029.1675185329@sss.pgh.pa.us>

* 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