Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdEGa-0004jh-29 for pgsql-performance@arkaria.postgresql.org; Tue, 18 Jun 2019 13:35:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdEGY-0007sl-Mc for pgsql-performance@arkaria.postgresql.org; Tue, 18 Jun 2019 13:35:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdEGY-0007sc-DN for pgsql-performance@lists.postgresql.org; Tue, 18 Jun 2019 13:35:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdEGW-00008G-4F for pgsql-performance@lists.postgresql.org; Tue, 18 Jun 2019 13:35:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5IDZ8hZ000803; Tue, 18 Jun 2019 09:35:08 -0400 From: Tom Lane To: AminPG Jaffer cc: pgsql-performance@lists.postgresql.org Subject: Re: Incorrect index used in few cases.. In-reply-to: References: Comments: In-reply-to AminPG Jaffer message dated "Tue, 18 Jun 2019 06:11:54 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <801.1560864908.1@sss.pgh.pa.us> Date: Tue, 18 Jun 2019 09:35:08 -0400 Message-ID: <802.1560864908@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk AminPG Jaffer writes: > Is there an explanation why it is using incorrect index? > SQL: > SELECT count(*) FROM tc WHERE ((tc.a_id = $1)) AND ((tc.m_id = $2)) AND > ((tc.ag_id is not null)) AND ((tc.id in ($3))) AND ((tc.pt in ($4, $5, $6))) What data types are these columns? For that matter, could we see the whole schema for the table (psql \d+ output or equivalent)? regards, tom lane