pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ayub Khan <ayub.hp@gmail.com>
Cc: Pgsql Performance <pgsql-performance@lists.postgresql.org>
Subject: Re: slow query
Date: Tue, 08 Jun 2021 13:14:28 -0400
Message-ID: <1121000.1623172468@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHdeyE+Rhk646X4E2_dH6g-CD_nU8LJ=15XYvb7jjf8gid71Yw@mail.gmail.com>
References: <CAHdeyE+Rhk646X4E2_dH6g-CD_nU8LJ=15XYvb7jjf8gid71Yw@mail.gmail.com>

Ayub Khan <ayub.hp@gmail.com> writes:
> I checked all the indexes are defined on the tables however the query seems
> slow, below is the plan. Can any one give any pointers to verify ?

You might try to do something about the poor selectivity estimate here:

>                                       ->  Index Scan using
> menu_item_restaurant_id on menu_item a  (cost=0.42..177.31 rows=1
> width=87) (actual time=0.130..3.769 rows=89 loops=1)
>                                             Index Cond: (restaurant_id = 1528)
> "                                            Filter: ((active =
> 'Y'::bpchar) AND (is_menu_item_available(menu_item_id, 'Y'::bpchar) =
> 'Y'::bpchar))"
>                                             Rows Removed by Filter: 194

If the planner realized that this'd produce O(100) rows not 1,
it'd likely have picked a different plan.  I'm guessing that
the issue is lack of knowledge about what is_menu_item_available()
will do.  Maybe you could replace that with a status column?

			regards, tom lane





view thread (112+ messages)  latest in thread

Message-ID: <1121000.1623172468@sss.pgh.pa.us>
Permalink:  ../1121000.1623172468@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1121000.1623172468@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, ayub.hp@gmail.com, pgsql-performance@lists.postgresql.org
  Subject: Re: slow query
  In-Reply-To: <1121000.1623172468@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