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 1lpbzG-0002eR-De for pgsql-performance@arkaria.postgresql.org; Sat, 05 Jun 2021 19:29:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lpbzF-00074U-6y for pgsql-performance@arkaria.postgresql.org; Sat, 05 Jun 2021 19:29:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpbzE-000734-Uw for pgsql-performance@lists.postgresql.org; Sat, 05 Jun 2021 19:29:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lpbzB-0004QF-67 for pgsql-performance@lists.postgresql.org; Sat, 05 Jun 2021 19:29:35 +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 155JTUE0560774; Sat, 5 Jun 2021 15:29:30 -0400 From: Tom Lane To: Ayub Khan cc: Pgsql Performance Subject: Re: query planner not using index, instead using squential scan In-reply-to: References: Comments: In-reply-to Ayub Khan message dated "Sat, 05 Jun 2021 19:42:37 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <560772.1622921370.1@sss.pgh.pa.us> Date: Sat, 05 Jun 2021 15:29:30 -0400 Message-ID: <560773.1622921370@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ayub Khan writes: > could someone clarify why the LEFT JOIN order_offer_map oom using > (order_id) in the below query is using sequential scan instead of > using index on order_id which is defined in order_offer_map table. Probably because it estimates the hash join to restaurant_order is faster than a nestloop join would be. I think it's likely right. You'd need very optimistic assumptions about the cost of an individual index probe into order_offer_map to conclude that 156K of them would be faster than the 476ms that are being spent here to read order_offer_map and join it to the result of the indexscan on restaurant_order. If, indeed, that *is* faster on your hardware, you might want to dial down random_page_cost to get more-relevant estimates. regards, tom lane