pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: iserbin@bostonsd.ru
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16280: dead tuples (probably) effect plan and query performance
Date: Thu, 27 Feb 2020 10:41:06 -0500
Message-ID: <21504.1582818066@sss.pgh.pa.us> (raw)
In-Reply-To: <16280-e393fbb744eae7aa@postgresql.org>
References: <16280-e393fbb744eae7aa@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> Issue description:
> After some minimal activity in database first plan changes to the second.
> Analyze on table1 do not help (tried with various default_statistics_target
> values).
> content_idx index recreation helps for some time, but several minutes later
> plan degrades back to second one.
> The only thing helped (surprisingly) is vacuum. It also helps for some time,
> but once number of dead tuples reaches something  like 300-500 - plan
> changes back to second one.

Surely it is *not* a bug that dead tuples affect the plan choice.
The density of live tuples is an important factor in the relative
costs of different table scan techniques.

In the case at hand, I wonder why your rowcount estimate is off
by a factor of 50:

->  Bitmap Index Scan on content_idx  (cost=0.00..155.07 rows=409 
width=0) (actual time=4.932..4.932 rows=21952 loops=1)
       Index Cond: (content @> '{"anotherjsonkey": {"values": ["13"]}}'::jsonb)
       Buffers: shared hit=48

If you can't improve that you're not likely to get a good plan, and
futzing around with cost factors to make this particular query do
"the right thing" anyway is inevitably going to make things worse
for other queries.  Maybe a larger stats target for the content column
would help, but I fear that this @> condition is just beyond
the ability of the planner to estimate.  You might need to redesign
the data representation to make it a bit more SQL-friendly.

			regards, tom lane





view thread (7+ messages)  latest in thread

Message-ID: <21504.1582818066@sss.pgh.pa.us>
Permalink:  ../21504.1582818066@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21504.1582818066@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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, iserbin@bostonsd.ru
  Subject: Re: BUG #16280: dead tuples (probably) effect plan and query performance
  In-Reply-To: <21504.1582818066@sss.pgh.pa.us>
  References: <16280-e393fbb744eae7aa@postgresql.org> <21504.1582818066@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