pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Shubham Mittal <mittalshubham30@gmail.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: Query takes around 15 to 20 min over 20Lakh rows
Date: Thu, 02 Sep 2021 19:22:46 -0400
Message-ID: <2441707.1630624966@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwZecBri-p0Zh-Fn8-1T6FNPH94wPYXOZ3QQaON2pk1=6w@mail.gmail.com>
References: <CA+ERcR_a-UDe5iomYU+FOK+pmPd=cr1eJFyWVtdrF4HeEyyKkg@mail.gmail.com>
	<CAKFQuwZecBri-p0Zh-Fn8-1T6FNPH94wPYXOZ3QQaON2pk1=6w@mail.gmail.com>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thu, Sep 2, 2021 at 3:16 PM Shubham Mittal <mittalshubham30@gmail.com>
> wrote:
>> *Please help in optimizing this query. I need to actually generate reports
>> daily using this query.. It takes almost 15 to 20 min to execute this query
>> due to joins.. *

> Use jsonb_populate_recordset (or one of its siblings) to get rid of as many
> of these key-based value extraction operations as possible and build a
> table from the contents of the jsonb.

While those duplicative extractions sure look inefficient, it's not
clear from the (lack of) given facts whether that's the main cost,
or whether the complicated FROM clause is producing a bad plan.
I'd suggest first looking at EXPLAIN ANALYZE output to verify which
plan step(s) are slow.  If it's the final output step that's expensive,
then yes the next step is to optimize the extractions.

Otherwise, see

https://wiki.postgresql.org/wiki/Slow_Query_Questions

			regards, tom lane





view thread (14+ messages)  latest in thread

Message-ID: <2441707.1630624966@sss.pgh.pa.us>
Permalink:  ../2441707.1630624966@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2441707.1630624966@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, david.g.johnston@gmail.com, mittalshubham30@gmail.com
  Subject: Re: Query takes around 15 to 20 min over 20Lakh rows
  In-Reply-To: <2441707.1630624966@sss.pgh.pa.us>
  References: <CA+ERcR_a-UDe5iomYU+FOK+pmPd=cr1eJFyWVtdrF4HeEyyKkg@mail.gmail.com> <CAKFQuwZecBri-p0Zh-Fn8-1T6FNPH94wPYXOZ3QQaON2pk1=6w@mail.gmail.com> <2441707.1630624966@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