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 1lEbMb-00031A-PF for pgsql-general@arkaria.postgresql.org; Tue, 23 Feb 2021 17:20:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lEbMa-0004m1-LM for pgsql-general@arkaria.postgresql.org; Tue, 23 Feb 2021 17:20:44 +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 1lEbMa-0004lu-E6 for pgsql-general@lists.postgresql.org; Tue, 23 Feb 2021 17:20:44 +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 1lEbMU-0006sM-9r for pgsql-general@lists.postgresql.org; Tue, 23 Feb 2021 17:20:44 +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 11NHKYZK3873893; Tue, 23 Feb 2021 12:20:34 -0500 From: Tom Lane To: Ayo cc: pgsql-general@lists.postgresql.org Subject: Re: Custom base type and suboptimal query plans In-reply-to: References: <3822526.1614093860@sss.pgh.pa.us> Comments: In-reply-to Ayo message dated "Tue, 23 Feb 2021 17:09:39 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3873891.1614100834.1@sss.pgh.pa.us> Date: Tue, 23 Feb 2021 12:20:34 -0500 Message-ID: <3873892.1614100834@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ayo writes: > On 2021-02-23, Tom Lane wrote: >> The slow query isn't using the chars_pkey1 index, which makes one >> wonder if you have a corresponding index in the custom-type case, > The index exists and is usable in the custom-type case: Hmm. The next most likely theory seems to be something wrong with cost estimation, causing the planner to avoid the nestloop-with- inner-indexscan plan even though it would work. Have you tried "enable_seqscan = off" (and maybe also disable merge and hash joins) to see if you can force choice of that plan? regards, tom lane