pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
To: Atul Kumar <akumar14871@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: query issue
Date: Tue, 15 Jun 2021 13:41:51 +0200
Message-ID: <20210615134151.0e54b642@firost> (raw)
In-Reply-To: <CA+ONtZ760jt+57hDYKHqU60t0CPHw5nHizAvqwMBVH8snBN6qw@mail.gmail.com>
References: <CA+ONtZ760jt+57hDYKHqU60t0CPHw5nHizAvqwMBVH8snBN6qw@mail.gmail.com>

On Tue, 15 Jun 2021 16:12:11 +0530
Atul Kumar <akumar14871@gmail.com> wrote:

> Hi,
> 
> I have postgres 10 running on RDS instance.
> 
> I have query below:
[...]
> 
> So my doubt is initially when I run this query it takes around 42
> seconds to complete but later after few minutes it completes in 2-3
> seconds.
> 
> I tried to create indexes on table for columns score & "updatedAt"
> DESC seperately but found no proper satisfied solution.
> 
> So please help me telling what I am exactly missing here ?

The worst part of your plan is the Bitmap Heap Scan, where the plan is actually
fetching the rows from the table. The bitmap index scan and sort are fast.
There's not much to do about them.

This query need to fetch 3882 rows from your table. So either the fetching part
of the plan is really, really slow (IO/CPU bound), or the simple filter, on only
~4k, is really slow (CPU bound).

You might want to avoid "SELECT *" and only specify the fields you really need.
Try first with only "SELECT _id", just to compare. You have an average row size
of 1.3k that the executor need to fetch and carry all the way to the result set.
This can cost a lot of useless IO and CPU.

You might want to tweak random_page_cost/seq_page_cost/effective_cache_size to
find out if an index scan would do a better job, but I'm unsure because I lack
of informations about your data and system.

Regards,





view thread (6+ messages)  latest in thread

Message-ID: <20210615134151.0e54b642@firost>
Permalink:  ../20210615134151.0e54b642@firost/
Also on:    postgresql.org/message-id/20210615134151.0e54b642@firost

 · 

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: jgdr@dalibo.com, akumar14871@gmail.com
  Subject: Re: query issue
  In-Reply-To: <20210615134151.0e54b642@firost>
  References: <CA+ONtZ760jt+57hDYKHqU60t0CPHw5nHizAvqwMBVH8snBN6qw@mail.gmail.com> <20210615134151.0e54b642@firost>

* 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