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 1ueDI0-006TUm-Vg for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 13:44:17 +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 1ueDHz-008BVF-Vg for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jul 2025 13:44:16 +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 1ueDHz-008BV7-J8 for pgsql-hackers@lists.postgresql.org; Tue, 22 Jul 2025 13:44:15 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ueDHx-000DIj-39 for pgsql-hackers@postgresql.org; Tue, 22 Jul 2025 13:44:14 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4560add6cd2so44770015e9.0 for ; Tue, 22 Jul 2025 06:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753191852; x=1753796652; 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=UVW1lBEVhJLpqOnVty5trxKcJ5CBb55EBBoVh87XqbE=; b=aX/QHu33WIKXnZyM8/kbHwE/N+fEFGyluu0jS0gW99Kbjbfa0FtnSE+1wBT+MZG9zK j1Uj8pr0Kvo3lUl0Ohcv4kdRONziR6hMaBiNUjhOLyDNu3mm7wNEE1MCEqmXdPVyCQPn CXDyGb5sw9GIR3PN45SaJlJpN+taBXf+82BaQ5yINr8B7j4O56cIlETI4rjGv2QMy6Er GNha+aIdjFayDA59BKOZ8sfTZEwckwd0FtTLd2gWlDeK0DAMMVEB4N+akgSVqJ3jk3A5 Z3ghFkDpT+4CwzCPBtowHHkXr4QkGuKv1qU2MnhB+fldWxRr3dDFDAuhFQISo7vEeCPE Xqog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753191852; x=1753796652; 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=UVW1lBEVhJLpqOnVty5trxKcJ5CBb55EBBoVh87XqbE=; b=Ggmnx/a5GN8BoNPcNQbqvdOEG1Z4rmJKvZCq0nlY3H5FkUrznqfSNhFEhuwdX9zYwE P95zgPz5/9vCwBSppcORLscqSVsoHRWkbdSzP1rKLl67DwNPqm+qMzoJGimaCous6dnL OdcDzYkRuiREQk7oCVtyiTudm/i6UfiJrEqkszEdwVI/zp+lkXrcbac7lbREEuz+w+jK WhuGK85sjR8SiCJH4rkQ0MMrREzDzctR8b5OUabIWCkktvw7ZKJjtWaGgB8RPAwVy+oV 2ctfSFu80AO3cRFMkc5HTzOddblJeuGyPL06nPHuETRcCodhKwG20OKWwXStLOKWzmzH TLAw== X-Forwarded-Encrypted: i=1; AJvYcCUo7HqUH/1cmx+Mwsg4qPC4GePb1EKkR+kIZoMbnWIHmLVjcA/5JBtuhUhgA/kkJonCz/mhNvmnrdCxupRX@postgresql.org X-Gm-Message-State: AOJu0YxLTgI8wFvOG//Zt3GXCQGnEFO2MHvtSR4Q914ndjEuw4isi21A BAT5xAivDWEm4+EC78rndFjAeOcBTmhwtkPleiXDpHdZkTCU78HDpACx X-Gm-Gg: ASbGnct142GfUh6/Qocf2zZhqBJxrQ0tkKb6K2GyczMX/7/OUUgA44m4UG+NroLaaoL M3RsoEag7B1egbGUb4DLLUM3z9PuuJdWE/TOQjH3GghQ6W4RwrtItILM7VxY+ppfDZ5sF0NsTmo 5zMymLe6DgcwJil5wFi+EN8NiCAVC8da1z+ZkaDwszAGBOxkiFWbSygi1G8XT3R5KyusXQYBmhL MviLTuSKPZIt/Qp4R4ie+bJA77KpckXVi0PZ/y+d4AR0LOVlHp14daAnwEBkf8x3GpbKFNdZgYI EFCClONFNBux8ry64jE+1g1mrvOhWE8AULOOwIJzKwkOYqR/dSQJg+Vz38qgPKIlDHLGEJWzkBK Z5fGw9aeAD8vWbJSrCGd1Tsl6VkyIIOitV+iZQhatlBYC X-Google-Smtp-Source: AGHT+IEDUy+VeXRNoO/A3Zo0oJBcWIeEJug1EOI4XM1j75EkzpY16UYZ1JDSLio0/55VNUT5ZOMApA== X-Received: by 2002:a05:600c:46d1:b0:456:23e7:2568 with SMTP id 5b1f17b1804b1-45864c16535mr22224545e9.13.1753191852256; Tue, 22 Jul 2025 06:44:12 -0700 (PDT) Received: from [192.168.15.242] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b61ca48a2esm13574066f8f.51.2025.07.22.06.44.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jul 2025 06:44:11 -0700 (PDT) Message-ID: Date: Tue, 22 Jul 2025 15:44:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: track generic and custom plans in pg_stat_statements To: Michael Paquier , Sami Imseih Cc: Greg Sabino Mullane , pgsql-hackers , Nikolay Samokhvalov , Ilia Evdokimov References: <5f775987-8a93-452d-bb3f-a1de53836406@gmail.com> <56d31e81-79d8-40bd-b957-0d6dc7c46589@gmail.com> <2f2bde53-972d-402c-9da3-c5467cca00bf@gmail.com> <064b9efd-92c9-4670-95f4-d911d4c7ddeb@gmail.com> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: 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 22/7/2025 01:07, Michael Paquier wrote: > On Mon, Jul 21, 2025 at 04:47:31PM -0500, Sami Imseih wrote: >> Last week I published a v11 that adds a field to QueryDesc, but as I thought >> about this more, how about we just add 2 bool fields in QueryDesc->estate >> ( es_cached_plan and es_is_generic_plan ), a field in CachedPlan ( >> is_generic_plan ) >> and after ExecutorStart, and if we have a cplan, we set the >> appropriate plan cache >> mode value. I think it's better to confine these new fields in Estate >> rather than >> at a higher level like QueryDesc. See v12. > > Yes, I think that this is a much better idea to isolate the whole > concept and let pgss grab these values. We have lived with such > additions for monitoring in EState a few times already, see for > example de3a2ea3b264 and 1d477a907e63 that are tainted with my > fingerprints. I would like to oppose to the current version a little. Commits de3a2ea3b264 and 1d477a907e63 introduced elements that are more closely related to the execution phase. While the parameter es_parallel_workers_to_launch could be considered a planning parameter, es_parallel_workers_launched and es_total_processed should not. Furthermore, any new code that utilises ExecutorStart/Run/End must ensure that the fields es_cached_plan and es_is_generic_plan are set correctly. IMO, the concept of a generic or custom plan is a fundamental property of the plan and should be stored within it - essentially in the PlannedStmt structure. Additionally, it is unclear why we incur significant costs to alter the interface of ExplainOnePlan solely to track these parameters. It may be more efficient to set the is_generic_plan option at the top plan node (PlannedStmt) and reference it wherever necessary. To identify a cached plan, we may consider pushing the CachedPlan/CachedPlanSource pointer down throughout pg_plan_query and maintaining a reference to the plan (or simply setting a boolean flag) at the same location — inside the PlannedStmt. Such knowledge may provide an extra profit for planning - a generic plan, stored in the plan cache, may be reused later, and it may be profitable for an analytics-related extension to spend extra cycles and apply optimisation tricks more boldly. -- regards, Andrei Lepikhov