Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqfJC-0003Ev-Vu for pgsql-performance@arkaria.postgresql.org; Tue, 08 Jun 2021 17:14:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lqfJA-0002uG-SL for pgsql-performance@arkaria.postgresql.org; Tue, 08 Jun 2021 17:14:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqfJA-0002u8-G2 for pgsql-performance@lists.postgresql.org; Tue, 08 Jun 2021 17:14:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqfJ8-0002mu-CI for pgsql-performance@lists.postgresql.org; Tue, 08 Jun 2021 17:14:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 158HESok1121001; Tue, 8 Jun 2021 13:14:28 -0400 From: Tom Lane To: Ayub Khan cc: Pgsql Performance Subject: Re: slow query In-reply-to: References: Comments: In-reply-to Ayub Khan message dated "Tue, 08 Jun 2021 19:03:48 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1120999.1623172468.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 08 Jun 2021 13:14:28 -0400 Message-ID: <1121000.1623172468@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ayub Khan writes: > I checked all the indexes are defined on the tables however the query se= ems > 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=3D0.42..177.31 rows=3D1 > width=3D87) (actual time=3D0.130..3.769 rows=3D89 loops=3D1) > Index Cond: (restaurant_id =3D= 1528) > " Filter: ((active =3D > 'Y'::bpchar) AND (is_menu_item_available(menu_item_id, 'Y'::bpchar) =3D > '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