pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Adlersburg <peter.adlersburg@gmail.com>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Advice needed: query performance deteriorates by 2000% within 1 minute
Date: Thu, 24 Feb 2022 11:10:51 -0500
Message-ID: <1351442.1645719051@sss.pgh.pa.us> (raw)
In-Reply-To: <CAD1Uk1ouyBstWpEj+aKYn6F5otKCuJMGkMtNuSrHXDOqgZuCVA@mail.gmail.com>
References: <CAD1Uk1ouyBstWpEj+aKYn6F5otKCuJMGkMtNuSrHXDOqgZuCVA@mail.gmail.com>

Peter Adlersburg <peter.adlersburg@gmail.com> writes:
>  Limit  (cost=0.00..804.97 rows=10 width=22) (actual
> time=23970.845..25588.432 rows=1 loops=1)
>    ->  Seq Scan on "order"  (cost=0.00..3863.86 rows=48 width=22) (actual
> time=23970.843..25588.429 rows=1 loops=1)
>          Filter: (jsonb_to_tsvector('english'::regconfig, content,
> '["all"]'::jsonb) @@ '''1.20709841'''::tsquery)
>          Rows Removed by Filter: 9652
>  Planning Time: 0.430 ms
>  Execution Time: 25588.448 ms

I think the expense here comes from re-executing jsonb_to_tsvector
a lot of times.  By default that's estimated as 100 times more expensive
than a simple function (such as addition), but these results make it
seem like that's an understatement.  You might try something like

alter function jsonb_to_tsvector(regconfig, jsonb, jsonb) cost 1000;

to further discourage the planner from picking this plan shape.

Possibly the cost estimate for ts_match_tq (the function underlying
this variant of @@) needs to be bumped up as well.

(Bear in mind that pg_dump will not propagate such hacks on
system-defined objects, so you'll need a note to reapply
any such changes after dump/reload or pg_upgrade.)

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <1351442.1645719051@sss.pgh.pa.us>
Permalink:  ../1351442.1645719051@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1351442.1645719051@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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, peter.adlersburg@gmail.com, pgsql-performance@lists.postgresql.org
  Subject: Re: Advice needed: query performance deteriorates by 2000% within 1 minute
  In-Reply-To: <1351442.1645719051@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