pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
query gets very slow when :jsonb ?& operator is used
2+ messages / 2 participants
[nested] [flat]

* query gets very slow when :jsonb ?& operator is used
@ 2018-09-06 23:51 davidjesse091@aol.com
  2018-09-07 01:39 ` Re: query gets very slow when :jsonb ?& operator is used Jeff Janes <jeff.janes@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: davidjesse091@aol.com @ 2018-09-06 23:51 UTC (permalink / raw)
  To: pgsql-performance@lists.postgresql.org

I have also asked this question on Stackoverflow and DBA stack exchange with no answer. It's a fairly long post, so I will post a link to it, as on Stackoverflow it is formatted nicely 
https://stackoverflow.com/questions/52212878/query-gets-very-slow-when-jsonb-operator-is-used

Any idea why my query slows down so much when I add account.residence_details::jsonb ?& array['city', 'state', 'streetName'] ?

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: query gets very slow when :jsonb ?& operator is used
  2018-09-06 23:51 query gets very slow when :jsonb ?& operator is used davidjesse091@aol.com
@ 2018-09-07 01:39 ` Jeff Janes <jeff.janes@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jeff Janes @ 2018-09-07 01:39 UTC (permalink / raw)
  To: davidjesse091@aol.com; +Cc: pgsql-performance@lists.postgresql.org

On Thu, Sep 6, 2018 at 7:52 PM <davidjesse091@aol.com> wrote:

> I have also asked this question on Stackoverflow and DBA stack exchange
> with no answer. It's a fairly long post, so I will post a link to it, as on
> Stackoverflow it is formatted nicely
>
>
> https://stackoverflow.com/questions/52212878/query-gets-very-slow-when-jsonb-operator-is-used
>
> Any idea why my query slows down so much when I add account.residence_details::jsonb
> ?& array['city', 'state', 'streetName'] ?
>

The planner has no insight into what fraction of rows will satisfy the ?&
condition, and falls back on the assumption that  very few will.  This is
(apparently) a very bad assumption, and causes it choose a bad plan.

Rewriting the `phone_number.account_id IN (subquery)` into an exists query
might help.

Cheers,

Jeff

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-09-07 01:39 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-09-06 23:51 query gets very slow when :jsonb ?& operator is used davidjesse091@aol.com
2018-09-07 01:39 ` Jeff Janes <jeff.janes@gmail.com>

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