Re: BUG #17330: EXPLAIN hangs and very long query plans - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #17330: EXPLAIN hangs and very long query plans
Date
Msg-id 70745.1639154362@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #17330: EXPLAIN hangs and very long query plans  (Strahinja Kustudić <strahinjak@nordeus.com>)
Responses Re: BUG #17330: EXPLAIN hangs and very long query plans  (Strahinja Kustudić <strahinjak@nordeus.com>)
List pgsql-bugs
=?UTF-8?Q?Strahinja_Kustudi=C4=87?= <strahinjak@nordeus.com> writes:
> On Fri, Dec 10, 2021 at 10:53 AM Pavel Stehule <pavel.stehule@gmail.com>
> wrote:
>> pá 10. 12. 2021 v 10:25 odesílatel Strahinja Kustudić <
>> strahinjak@nordeus.com> napsal:
>>> I allowed EXPLAIN in Docker to finish and it took almost 500 seconds and
>>> it was reading data all the time. After I reindexed the biggest table,
>>> EXPLAIN finished instantly. Can the index corruption cause this?

>> The index can be bloated.

> Is bloat just enough to make it slower, or the index needs to be corrupted?

bloat != corruption.  The problem you're dealing with here is a whole lot
of dead index entries at the very end of the index range (could be either
the lowest or highest entries).  The planner is wasting time scanning
through those to find the extremal non-dead value for a range estimate.
REINDEX got rid of the dead entries; a VACUUM would have done as well.

As noted upthread, more recent PG versions are a bit smarter about
such cases.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: BUG #17330: EXPLAIN hangs and very long query plans
Next
From: PG Bug reporting form
Date:
Subject: BUG #17333: pgdg postgresql-common pg_upgradecluster duplicate data_directory in configuration file