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 1mQAef-0006y5-2A for pgsql-performance@arkaria.postgresql.org; Tue, 14 Sep 2021 15:47:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mQAed-0008Nu-2a for pgsql-performance@arkaria.postgresql.org; Tue, 14 Sep 2021 15:47:27 +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 1mQAec-0008Nl-Qk for pgsql-performance@lists.postgresql.org; Tue, 14 Sep 2021 15:47:26 +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 1mQAea-0007g8-ML for pgsql-performance@lists.postgresql.org; Tue, 14 Sep 2021 15:47:25 +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 18EFlLYB632225; Tue, 14 Sep 2021 11:47:22 -0400 From: Tom Lane To: Kristjan Mustkivi cc: Jeff Janes , Tomas Vondra , Pgsql Performance Subject: Re: Postgres chooses slow query plan from time to time In-reply-to: References: <31c01752-c4d6-7751-9d25-b1fac8f3a7aa@enterprisedb.com> <589350.1631628930@sss.pgh.pa.us> Comments: In-reply-to Kristjan Mustkivi message dated "Tue, 14 Sep 2021 18:36:45 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <632223.1631634441.1@sss.pgh.pa.us> Date: Tue, 14 Sep 2021 11:47:21 -0400 Message-ID: <632224.1631634441@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Kristjan Mustkivi writes: >>> Filter: (((product_code)::text = ($1)::text) AND >>> ((balance_type)::text = ($4)::text)) > But the Primary Key is defined as btree (cage_code, cage_player_id, > product_code, balance_type, version) so this should be exactly that > (apart from the extra "version" column). Oh, interesting. So this is really a datatype mismatch problem. I'd wondered idly why you were getting the explicit casts to text in these conditions, but now it seems that that's key to the problem: the casts prevent these clauses from being matched to the index. What are the declared data types of product_code and balance_type? And of the parameters they're compared to? regards, tom lane