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 1hkBPr-00078h-RC for pgsql-performance@arkaria.postgresql.org; Sun, 07 Jul 2019 17:57:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hkBPq-0007k7-HW for pgsql-performance@arkaria.postgresql.org; Sun, 07 Jul 2019 17:57:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hkBPq-0007j3-4B for pgsql-performance@lists.postgresql.org; Sun, 07 Jul 2019 17:57:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjlEG-0001CV-Qe for pgsql-performance@lists.postgresql.org; Sat, 06 Jul 2019 13:59:54 +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 x66DwwHB026690; Sat, 6 Jul 2019 09:58:58 -0400 From: Tom Lane To: Ancoron Luciferis cc: pgsql-performance@lists.postgresql.org Subject: Re: Custom opclass for column statistics? In-reply-to: References: Comments: In-reply-to Ancoron Luciferis message dated "Sat, 06 Jul 2019 11:02:27 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26688.1562421538.1@sss.pgh.pa.us> Date: Sat, 06 Jul 2019 09:58:58 -0400 Message-ID: <26689.1562421538@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ancoron Luciferis writes: > I've been wondering whether it is possible somehow to have the standard > column statistics to respect a certain operator class? In principle, pg_statistic can represent stats for a non-default opclass. Teaching ANALYZE to collect such stats when appropriate, and then teaching the planner to use them when appropriate, is left as an exercise for the reader. I think the "when appropriate" bit is actually the hardest part of that. Possibly, if you were satisfied with a relatively manual approach, you could proceed by using CREATE STATISTICS to declare interest in keeping standard stats for a non-default sort order. Not sure what to do if you want it to be automatic, because I don't think people would hold still for having ANALYZE collect stats for any random non-default opclass automatically. Maybe a new opclass property? regards, tom lane