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 1v8bLe-003Zuc-Fs for pgsql-performance@arkaria.postgresql.org; Tue, 14 Oct 2025 09:29:38 +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 1v8bLc-00C3SP-95 for pgsql-performance@arkaria.postgresql.org; Tue, 14 Oct 2025 09:29:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8bLb-00C3SH-V3 for pgsql-performance@lists.postgresql.org; Tue, 14 Oct 2025 09:29:36 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v8bLa-0025jb-2g for pgsql-performance@lists.postgresql.org; Tue, 14 Oct 2025 09:29:36 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-4257aafab98so4304797f8f.3 for ; Tue, 14 Oct 2025 02:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760434168; x=1761038968; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=/zsEe1efDvuwfvfKulsAXlKXNUWZ/CPwgxaiGqXYW3k=; b=LzvEb7uTfJhcKvRjYIk45B9NSU4fBs2DNWKfgYoO/9cC3ZyCh/7JWJ22yWie5zKJse BlziB0g6VzWYyAa3wih9TYyXDR09jkP29ZJvO4JagpA1HM6OoE1mdvSFdVW2qmzJT3eH t80t36ZZ7HzTWnBN1x+lnjR6OfvJwA/y0heMbCTcXoiEc3amCXXRlJe3jj+2oZOsyWom XDa0/l8w2Vt5pZPjmw172CJye/TQ2HS479TEEpDFdK3qkTMleaOXeLExWIRI3KxlTfyL 246Ie/yNPfbstOrUGl6tymT72YOjZ9Sqcib5SlnkT3oxg69Kt/U2frzCr7NONQNCewmO Pftg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760434168; x=1761038968; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/zsEe1efDvuwfvfKulsAXlKXNUWZ/CPwgxaiGqXYW3k=; b=h3J+gNSsE7vUFv1VAVdYqPFKGg8TkR4QXTshc1LhMn9gpUNmPletCPJ29IDZ43VQ0R mmQuXDyR97VupvEhT6fBb60GGMty+CiUAX4rokPJ/XJBbzjkTRZHi1dA+cgg3yDkceIf U2MuF8JG3wCMPfaFUi17uULrJd/XuIMUSrqoD280BXv9BHFIVnmkZA9Ijgj9hq8LT9V/ pDWcTx82fUTPu0ZbTAf7YV45eienR91LHu4htvbrRlmwevIa5w4ODe79RCm0fkoJFcBx T5MMm6GeYOHgHUeZ9ES/zLetXYHotvVzFK5geEBOrM3qeiy0sDxQbBEP18Nmyk01K7oN Woaw== X-Forwarded-Encrypted: i=1; AJvYcCW/MEdna2TmettTidOQslL1ze1O/Z3AI6BArELQzpf2jApnT6AIz05UJ6qO7F4UWt2pJniBbQCtaZVoVEwCE+FeIw==@lists.postgresql.org X-Gm-Message-State: AOJu0YzHixKnj9ZUWEMMjxxkAGN4VPLFnHMjdoHwVK4CJh9UbITRWZlQ zq42VlpKWhlBV+q492hgRKyRpzQcECWJKtukLH4+C1OmlfbedvbERT27 X-Gm-Gg: ASbGnctu8q0aB66VBizQKvKGLnYWBJZHNXtu1oVD69UWdgg07br8YW0N9xOIXgkOCYB AAYciFyM78vRX9EJerfqQlN84FB+UvrkCrlcPsjJ9zwIwwQXKMWpGbAffFBqjMDXmKG7CGvKhA1 N16P4vRyiOSFg95rFt6anA+y7bhSrFuS28aOCmyLkPrdTVzfj2VQFDfojyPPY71iiNKcoeLLWWi vnYEu8uzOywbVy1gQyW3E8W84d2uyCsw3O83fKS3aTQMjVIek4U+jDNF5RadKWSi83d0SaXkVI3 SsEkiFE370vLXLkQLa5PW6HylGFn2Bsrl6nJVNUH276EKHo3G2UMrksVbVd8KLaq47KY+dA1YL+ N5j+x562aeJfVX/aVv9RQCCQ0NJH68puzIH4Vyu7N0O1LEHnxuJUwdHxin1fnGF8= X-Google-Smtp-Source: AGHT+IFTg7EwlZrWq7Rga0ew2Vd0MUDO2jTRv2S1LHCDwg3U82pt/GALzbZ2cid6cmrOF9J36DLa9g== X-Received: by 2002:a05:6000:420a:b0:3ee:1521:95fc with SMTP id ffacd0b85a97d-42666ac6a8emr15274315f8f.14.1760434168409; Tue, 14 Oct 2025 02:29:28 -0700 (PDT) Received: from [192.168.15.198] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-426ce5e8b31sm22797137f8f.54.2025.10.14.02.29.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Oct 2025 02:29:27 -0700 (PDT) Message-ID: Date: Tue, 14 Oct 2025 11:29:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Indexes on expressions with multiple columns and operators To: Tom Lane Cc: =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Yhuel?= , "pgsql-performance@lists.postgresql.org" , Jehan-Guillaume de Rorthais , Christophe Courtois , Laurenz Albe 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> <228091.1760367307@sss.pgh.pa.us> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: <228091.1760367307@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 13/10/2025 16:55, Tom Lane wrote: > 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.I know at least two extensions (one of which is mine) that attempt to analyse query post-execution state, identify unsuccessful predictions on cardinality, number of groups, and work_mem, and fix these issues by creating MCV and distinct extended statistics. Of course, without extended statistics on join clauses, their effect is highly limited, but we are preparing ;). Many combinations of clauses may occur. Partial indexes can affect the whole system's performance in automatic mode. Additionally, I would personally like to play the same game as SQL Server already does - compute statistics in an efficient manner - during a Scan. The filter of such a scan may serve as a WHERE condition in the extended statistics. -- regards, Andrei Lepikhov, pgEdge