Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8Jy2-00GHfT-IO for pgsql-performance@arkaria.postgresql.org; Mon, 13 Oct 2025 14:56:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v8Jy0-006FcF-Ao for pgsql-performance@arkaria.postgresql.org; Mon, 13 Oct 2025 14:56:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8JxD-006Cmw-EW for pgsql-performance@lists.postgresql.org; Mon, 13 Oct 2025 14:55:16 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v8JxC-001Xrq-2D for pgsql-performance@lists.postgresql.org; Mon, 13 Oct 2025 14:55:15 +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 59DEt7N8228092; Mon, 13 Oct 2025 10:55:07 -0400 From: Tom Lane To: Andrei Lepikhov cc: =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Yhuel?= , "pgsql-performance@lists.postgresql.org" , Jehan-Guillaume de Rorthais , Christophe Courtois , Laurenz Albe Subject: Re: Indexes on expressions with multiple columns and operators In-reply-to: <22c38fe8-e673-46ec-b025-6ea964b3502f@gmail.com> References: <1507576.1758120083@sss.pgh.pa.us> <62133334-b844-4d0b-b248-1a8446757e5f@dalibo.com> <1916727.1758209549@sss.pgh.pa.us> <1972974.1758213639@sss.pgh.pa.us> <76fbd9ef-1fbb-49f0-bc8b-844462b18d1d@dalibo.com> <2432873.1758387110@sss.pgh.pa.us> <6ad08c0c-2c03-4b30-b5a7-dc486aa29c52@dalibo.com> <493a013c-63d1-467a-b9ec-352f77baf37a@dalibo.com> <9756a3e9-5dea-4506-a077-72a4d9c302df@gmail.com> <6754b8f8-6dad-4778-8c10-b3aed4b495e4@dalibo.com> <22c38fe8-e673-46ec-b025-6ea964b3502f@gmail.com> Comments: In-reply-to Andrei Lepikhov message dated "Mon, 13 Oct 2025 16:00:35 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <228090.1760367307.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 13 Oct 2025 10:55:07 -0400 Message-ID: <228091.1760367307@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrei Lepikhov writes: > On 25/9/2025 12:41, Frédéric Yhuel wrote: >> So, on SQL Server, you can do this: >> CREATE STATISTICS FooStats ON foo (ackid, crit) WHERE crit = 'WARNING'; > Nice! Thanks for the report. I think the only reason why Postgres > doesn't have it yet is the computational cost. I think it's more lack of round tuits. If we had such an option for statistics objects, presumably we'd determine the applicability of a particular statistics object to a query the same way we do for partial indexes, namely try to prove the statistics' restriction condition from the query WHERE clauses. I've not heard complaints about that being unduly expensive. In the meantime, I believe the old-fashioned approach of creating a partial expression index and letting ANALYZE collect stats on that will serve, at least for simple statistics. regards, tom lane