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 10:28:21 -0500
Message-ID: <1079393.1675178901@sss.pgh.pa.us> (raw)
In-Reply-To: <b847d458-5a03-718e-5467-422fc0e51004@gmx.net>
References: <b847d458-5a03-718e-5467-422fc0e51004@gmx.net>

Dimitrios Apostolou <jimis@gmx.net> writes:
> The question is why this simple query is taking so long to complete.

Do you get the same 10 rows when you repeat the command?

On the basis of the limited info you provided, I'm going to guess that

(1) there are huge subranges of the table containing no live rows,
so that a seqscan might have to pass over many blocks before it finds
some to return;

(2) once you do reach an area having live rows, the next SELECT picks
up scanning in that same area due to the effects of
"synchronize_seqscans", so you get immediate answers until you reach
the next desert of dead tuples.

If turning synchronize_seqscans off changes the behavior, that'd
be a good clue that this is the right theory.  As for a real fix,
it might be time for a VACUUM FULL or CLUSTER on that table.

			regards, tom lane





view thread (11+ messages)  latest in thread

Message-ID: <1079393.1675178901@sss.pgh.pa.us>
Permalink:  ../1079393.1675178901@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1079393.1675178901@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: <1079393.1675178901@sss.pgh.pa.us>
  References: <b847d458-5a03-718e-5467-422fc0e51004@gmx.net> <1079393.1675178901@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