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 1uhCO2-00Bddo-No for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Jul 2025 19:22:51 +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 1uhCO1-00CFmX-LP for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Jul 2025 19:22:49 +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 1uhCO1-00CFmP-By for pgsql-hackers@lists.postgresql.org; Wed, 30 Jul 2025 19:22:49 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uhCNy-001iq6-1M for pgsql-hackers@postgresql.org; Wed, 30 Jul 2025 19:22:49 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3b7746135acso94662f8f.2 for ; Wed, 30 Jul 2025 12:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753903366; x=1754508166; darn=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=QNslHvC182M3jsmY6h3+zWR8nL65C6ScDXp0+7vmP/c=; b=mYnRGp8KB/v5MC0W7VAItcU5y4zEJu1fG9xp7VgcXIK7Qv1qY62RK2NwWaKI/zOo+T KcdtSEWMnYL94glnK2BaoLPjI2u3IezQemOJUqp1KM6xdXb5y/G93FopO6ycH5raF4Lg DMk+IoJmV7nkb2dLuteQoTI8xtWb2OMc0pxD+17gYCGWhXDVZEDJ9Rbsur6wUTUmtsD9 IVVxdFnVmU0VdZXsr0Ez7EHsKdCKJjEZklP0VYjzpCQiEgLEYmKekgX9mUEFPEiRvXrJ ToK9J1U8PRYLD6bCTE5iG2Q9/nQZAzKYBSpI1vYJWReqphpYi+/1dywRknjr5JCGSh6m i5MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753903366; x=1754508166; 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=QNslHvC182M3jsmY6h3+zWR8nL65C6ScDXp0+7vmP/c=; b=czezPUAvdCVkM/dg5cHbO1xZr/+zgC/k2isCUdWJypy63mqHx0Z01WABoJcBqnoj1Z 0KFFIqw55QmUdkXHgy/+PLu8Rsfnkf/d4lS5veuGwkooV9y8cQywZKdCVImeSSAmTVaW WV2t1i4nF7/LXLkdoIgyv8soPrD61N8t6pBfG7NlBPlN80XO9eTMcX05qE3UcyowWNwU V5aBycBMznVVVAgq+aO4hzrZ/i1uZJEBGfyIJDAiNMomHqzWSC/YojbErS/PrlXNtLed Nv/jZJOveRvCn7yGkZ437M8TE4IqtFnn+yiqIY+i25fQ883Du1YeSrDBh+x3rxnzm8Bi qj7g== X-Forwarded-Encrypted: i=1; AJvYcCWYHq6esL4fg1D62iHz9B2qhl68s2rvezfphQ/Ke43XdoSpz3GT999iaF6D9xGLDq2YKa4/PAQYjECbwcFj@postgresql.org X-Gm-Message-State: AOJu0Yw3MJn1RD9Rvake2nml/3n8cTtMY13ZcnCF6MxZSS5sk5+KD6jf XfYwJtg/Xvo1h+Na63tldBkvbdn7OW7BxVN+wAUWIbr4CGIuKuvsVgYj X-Gm-Gg: ASbGncunuM7a2nE9tyU8CnJt806Tn8A1w/WJ37Wx47k3HTYm4jEsny+17YBn28z5M/Y k4whotRmPqbqtxJIz/jjelk1eJBIkxVRl3/La4OSzFDHYzv0pd+4vv/5+qG6IlBGIpa1YT9YOnB +iLD6590LefHPsmO48ovX9GWlzaCXdqxuLlkpza+sGIBl9D6Y40pA9smmiw9t9MjY9wVrQIIycX 9GYYszWskuXzDYl83hygsvPPhb8CE8XEF5E0UGxu3r9iNrc4K/KQEYb7CI/NyOkIP9haIp4zRJH UDCxVQdHEERRdP3V/rla3adG88wnjTrxC8j5NweO3fJde6KMMI0pma31xMTrrqs0P83wTq1KTPK Wd1+O+oZ3sHiiakYsuQ9IU0F+Rz1YT0TZLUesFBsOwuCkY9RCKAOhst5T X-Google-Smtp-Source: AGHT+IEFcHTSBnkRUCNqEYRaxvj8S9CFohQ30wmoPpTIrkt3WYX6ASxf2BsSGUN3W5t3P2YCReXWCw== X-Received: by 2002:a05:6000:3101:b0:3a4:dfc2:bb60 with SMTP id ffacd0b85a97d-3b794fd3f6cmr3565444f8f.26.1753903365664; Wed, 30 Jul 2025 12:22:45 -0700 (PDT) Received: from [192.168.0.89] (84.123.234.224.dyn.user.ono.com. [84.123.234.224]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b778f0c866sm16243181f8f.55.2025.07.30.12.22.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Jul 2025 12:22:45 -0700 (PDT) Message-ID: Date: Wed, 30 Jul 2025 21:22:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: track generic and custom plans in pg_stat_statements To: Sami Imseih Cc: Michael Paquier , Tom Lane , Greg Sabino Mullane , pgsql-hackers , Nikolay Samokhvalov , Ilia Evdokimov References: <1673684.1753379027@sss.pgh.pa.us> <1933906.1753462272@sss.pgh.pa.us> <87249b23-c4c5-4c0b-88d3-efb13b8a04d1@gmail.com> Content-Language: en-AU 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 7/30/25 21:05, Sami Imseih wrote: >>> The term "NOT_SET" makes me itch a little bit, even if there is an >>> existing parallel with OverridingKind. Perhaps your proposal is OK, >>> still how about "UNKNOWN" instead to use as term for the default? >> +1 to "UNKNOWN". > > We currently use both UNKNOWN and NOT_SET in different places. > However, I'm okay with using UNKNOWN, and I've updated it in v16. > >> But generally, classification in the PlannedStmtOrigin structure seems a >> little strange: a generic plan has a qualitative difference from any >> custom one. And any other plan also will be generic or custom, doesn't >> it? > > I am not sure I understand the reasoning here. Can you provide more details/ > specific examples? Yep, When building a generic plan, you don't apply any constant to the clause, such as 'x<$1'. That means you can't use histograms or MCV statistics when building a custom plan. The optimiser should guess and frequently uses just a 'magic constant', like 0.05 or 0.33 for selectivity estimation. It sometimes drastically reduces the quality of the plan. So, analysing pg_s_s data, it would be beneficial to determine if a generic plan is effective or not. In practice, with this knowledge, we can access the CachedPlanSource of the corresponding PREPARED statement via an extension and override the decision made in 'auto' mode. Unfortunately, we cannot obtain a pointer to plan cache entries for plans prepared by the extended protocol, but this may be possible in the future. So, I meant that the source of the plan is one important characteristic, and the type (custom or generic) is another, independent characteristic -- regards, Andrei Lepikhov