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 1v79rS-00FpSe-DA for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Oct 2025 09:56:30 +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 1v79rQ-00BSWK-6c for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Oct 2025 09:56:29 +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 1v79rP-00BSWA-UL for pgsql-bugs@lists.postgresql.org; Fri, 10 Oct 2025 09:56:28 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v79rP-00117X-0K for pgsql-bugs@lists.postgresql.org; Fri, 10 Oct 2025 09:56:27 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3f0ae439bc3so933785f8f.1 for ; Fri, 10 Oct 2025 02:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760090186; x=1760694986; 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=lNkkJpdn3Agx7Gb7jwws14KQz0uDnh10/lPlce7RVFU=; b=kUZNBIYHB8GZBYNVOHHHdM49Joe6crVlnrcN8xQ+aZfb0KNEDebSYU+Cj/50PYe5DK +JvtgzG6pDglUbTFuVfBE72BtgAu1+U44NneRcJNhRX1Xtww3JjxmZGd9dSHRk1p+hda UIn3B5x3Jgez3frr4bzOON7xEmY/2brfkTg06F8vDJ4FXaK2NlQpZs1AxxbbtJg7g69A SNahZybDn3A3OxUlNGGLIF1cBW92SUfFeH6n20QB3E6yTI6oCpCNxwz6cgVe1hRwt4nK E+9hCUnmxupJzu6u5710ypIExmtfqewqQzXMlwTgkWsrXtPQPyxzQqhfqtFZwzKoky0u RWcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760090186; x=1760694986; 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=lNkkJpdn3Agx7Gb7jwws14KQz0uDnh10/lPlce7RVFU=; b=rmB6ZLw9XchG+pb1N7tVzx/oXu8Qy1sKxU1cvGdHNiClRN6TgVV0BXzev9NcDt/Ix0 MdXTHODI8/ipM58WCxbroATh2FOn1RzC992MuhJvEl5+jzplWnnw58kv3tgPrt/ij9Zq 7J0b2MgoFaySUSqMyoccir1A7ZT5duYtmDrSbXluLu6ISi630y7bU0j0iTf1bw5Yr7iL 2nsG8EGGablcsTb8Qw4FvFiCZm9ZQGnSb3us94nvhno+MHgvUBi4VAMadkkWrTnIwXs/ Uwi0GxUKLnxNUOG96vKGDRdPwQYdN3N7JbNgn+QNANASmSU9gwK0wCyLjCgm46OZHaeR ULCA== X-Forwarded-Encrypted: i=1; AJvYcCVkDPLjQKUIsAlyxMtih1KGCZZ6f7MNJH1f3vTcpsOD2xfNPrAteRq+j3qEtZSuhMyiRabHG2fB0k8C@lists.postgresql.org X-Gm-Message-State: AOJu0YxD/vwiVGkUAt6UDbWNoPS2VkVVRwcoVvvROg60lKQMh3MY5JOh 69Cdbk+9q4TmHwkQO9oAEVQYgMvhBOGrXErqAOkcqv4Usulkx43FPTIH X-Gm-Gg: ASbGnct5yl2oK8TiXLTujgS2vwoJF/uKC9u+fIaWocxyItedyAwpwoc/JevR5FMvsOK xjv3y8ooY4z4kLkyWs1jP9cFDht/ewBu6bPw0vP7ZVwKpGN+WXLnxXbM0jo6jSoViFyu6LCLkJF KNxb1DXK5ah8cqScosCieJn3NdKENIjK72OrVCYHXYsUHx9X9YKNQ7qZvT90+KHUV2X3NVYZKzl +cDn+Pzqg5f3NK0L3k2txiwiFMbxO0Bg6BzLk92hUMul4jsVkAck3GaJqmqu4BCy9kU7tB1XoXK Rk5tfeVFri7Uu/g/oHgZxlK4+lt6KDgf1F0OF5RXRG1oNQfoNJCNdTppW42FgN0Mn+Wliznpq0e Xtpeb/e5sdgLWtgVCVS2l50pgP9A18jd7X4OaJGmQKLzQ6Ur1U4Ws X-Google-Smtp-Source: AGHT+IE2ZNvY/6DZJPI/ehNddHXphe4whG71s47X5kkw4LRu5RiqeOzIfN7RvgKAo9dK2McrCjWQ5w== X-Received: by 2002:a05:6000:26ca:b0:400:1bbb:d279 with SMTP id ffacd0b85a97d-4266e7d44f1mr7546599f8f.39.1760090185362; Fri, 10 Oct 2025 02:56:25 -0700 (PDT) Received: from [192.168.15.198] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-426ce5e8b31sm3364758f8f.54.2025.10.10.02.56.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Oct 2025 02:56:24 -0700 (PDT) Message-ID: <95b73780-94cc-496c-8658-1f71da4c8a71@gmail.com> Date: Fri, 10 Oct 2025 11:56:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19076: Generic query plan is extremely slow To: David Rowley Cc: premal.patel@veeva.com, pgsql-bugs@lists.postgresql.org, Laurenz Albe References: <19076-4d897c04a44a9627@postgresql.org> <281ae4783e0174e1cb77a560936b86a9f542bba4.camel@cybertec.at> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/10/2025 11:13, David Rowley wrote: > On Wed, 8 Oct 2025 at 21:21, Laurenz Albe wrote: >> Either don't use a prepared statement for this statement, or make sure >> that "plan_cache_mode" is set to "force_custom_plan" for that single >> prepared statement.We already have a couple of proposals that would alleviate this recurring issue. The first one [1] introduces 'referenced' planning for generic plans. There, the optimiser may use current values for incoming parameters to predict estimations, rather than using magic constants like 0.3 and 0.005, which seem too conservative in many cases. To my knowledge, SQL Server, Oracle, and some other systems employ this approach. Although not the ideal solution, it is optional and may help people choose a proper planning strategy. The second feature [2] is an addition to the first one. It slightly changes the behaviour of plan_cache_mode: it prioritises the strategy declared in the CachedPlanSource::cursor_options over plan_cache_mode. It provides users with the option to select a specific query and set a generic/custom/auto strategy to mitigate severe performance degradation. With later changes in the master branch, these features open the door for extension developers to introduce 'execution-based' metrics and choose a plan type for a specific plan cache entry. [1] https://www.postgresql.org/message-id/19919494-92a8-4905-a250-6cf17b89f7c3@gmail.com [2] https://www.postgresql.org/message-id/458ace73-4827-43e1-8a30-734a93d4720f%40gmail.com -- regards, Andrei Lepikhov, pgEdge