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 1lEZY9-0004RX-S7 for pgsql-general@arkaria.postgresql.org; Tue, 23 Feb 2021 15:24:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lEZY7-0005m1-Ty for pgsql-general@arkaria.postgresql.org; Tue, 23 Feb 2021 15:24:31 +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 1lEZY7-0005lu-MD for pgsql-general@lists.postgresql.org; Tue, 23 Feb 2021 15:24:31 +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 1lEZY1-000619-CU for pgsql-general@lists.postgresql.org; Tue, 23 Feb 2021 15:24: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 11NFOKwZ3822527; Tue, 23 Feb 2021 10:24:20 -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: Comments: In-reply-to Ayo message dated "Tue, 23 Feb 2021 14:53:02 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3822525.1614093860.1@sss.pgh.pa.us> Date: Tue, 23 Feb 2021 10:24:20 -0500 Message-ID: <3822526.1614093860@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ayo writes: > I have a database where I converted an integer primary key column to a > custom base type that pretty much amounts to a wrapper around an > integer, and now some queries are resulting in much slower query plans. > Does Postgres have special optimizations for integers that are not > available for custom types, or did I perhaps overlook something? 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, or if you fat-fingered something about the index operator class for the custom type. As of v13 I don't think there's anything in that area that custom types can't replicate ... but there certainly is plenty of infrastructure for the standard types that you'll need to build out if you want equivalent functionality. regards, tom lane