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 1ucJMU-00BTFt-OP for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Jul 2025 07:49:02 +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 1ucJMS-00Ha3d-KC for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Jul 2025 07:49:01 +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 1ucJMS-00Ha3V-8K for pgsql-hackers@lists.postgresql.org; Thu, 17 Jul 2025 07:49:00 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ucJMQ-008DPj-2L for pgsql-hackers@postgresql.org; Thu, 17 Jul 2025 07:49:00 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-45610582d07so4609895e9.0 for ; Thu, 17 Jul 2025 00:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752738537; x=1753343337; 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=Qi7sQk+3OQWUqLWFi0VGhVx1Wy/WMM1LFMGy1uQAQbM=; b=V/jjAa9WafO3cpBXy6pxd6vvWM1PSaKeo2cz0eiBIhGyxGGCumPfxckiOgNWnxtY4F DCW9PlC/ifPTQxAuDvYXz6eKayNHYQeGK0hjtOdCQu25bmGFPP0ItoA64ezjb23wmnpk 3p4j7wsbFOLIqbSvEdR0xVBQhtM+CQg7H1EzvIj0Bza2pP+A8lLf+ZfAW9HBFLKIa47Z /yfl0BUuFA3L04pOrnEF1fPTcvtATAdhW3MTOGSFbz+aQIBbzTu2jDnQCTnqtGCFdB8C d5HIRVHOnb1Kc3B+ZdHS91g6XxTFy80P/qTxS+Jurk1AAxcVyhNEjLx411ZqIK4ePbAu r1AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752738537; x=1753343337; 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=Qi7sQk+3OQWUqLWFi0VGhVx1Wy/WMM1LFMGy1uQAQbM=; b=MJkbawgPxEP5Zjmui0TeYFiyHNNxN9tKQZj+NbLnnqW4Qn7dNjhI9oWhR8Xpk/i4vK 0dB5AcpmN4pTnBrhY40KLVhnCE9WbnCS+QKIdTH25I8u6SOFTLIabfNRGVFqI/kIDvYR CheRUHmGrVrVnKZhMKCVfCNeOH6lNZZ000y3uEratoAU3BRdrqBn9eOrtCCNAY7RQuS+ qagf9kHInGi8HruyyrZwWxYhYnB/NbtEg2l/MSu75+TnfQVbkfPX/mN/v/GPFyt7WX/k teQTqqi8NtkKsGrUWJ+6IXG17M0o3m9Y/Yix6gvTvHPUaEvAFt6a2iT6codgFhdYlyuc YlmA== X-Forwarded-Encrypted: i=1; AJvYcCXRKBZYA7AD4rGCAoLrDM2yRFsPyC5l70kRLMUvHLtYAJABdBSLdzPFcf9O4CsSgqFGCvv8QvQcocRK5rOJ@postgresql.org X-Gm-Message-State: AOJu0Yzx0ecKN2G18mDhXvaT0wtYDxrUHOx3BOqajeqU0NY7A2k3AIlv p53OuL5LZLL3Hfduh+ahXcBJ1nZttW4AK5SSB8oCbTjuMwdq+Olv2qkGOORmQka1 X-Gm-Gg: ASbGncuQcd8eXT7UNEp+zykyVrFD9vtaOO3wJEPDWjscCuLWWcIfXyG6qSvh2oK7qHN cbd/2dNanL3VB0iHTyFd+DiaynrRw6rjsxedc15K/dG1mOee/HF3vkreDM1vUjKUwvBqLfSj71B DMmoQ2sUZIRSoVnfBEk9ohHsCxI5/HOKK8a7RG397Y6wrjGr6uncKth0kmo3SFgMSltg5EDWsyd DqDgywOtrnIa6/UQyPk1eHNE7u1TZJ7wXCVFz7TUkXeDvtRuGQZJ9eo8hWaSSzUhwyI1rYZYkEw iIumZnh3XPCqXPs8BkAkVI9rvYZSv8yb2T5mOztm/DtJw3cVVQbg+U9+Z4rnuy9qKxb8AySjZuF wqva2vN5ii7d4nSdcvUmgZFKZJSGsq78WcQ== X-Google-Smtp-Source: AGHT+IEZPlMO1pUE0HPGFQfZiIcPo4EgQR3iGuuhNJEWW4RuggVwZFiLYeIO6hVDf2z81EVnR7RRHg== X-Received: by 2002:a05:6000:248a:b0:3a5:25e0:1851 with SMTP id ffacd0b85a97d-3b613e60138mr1219373f8f.7.1752738537369; Thu, 17 Jul 2025 00:48:57 -0700 (PDT) Received: from [192.168.15.217] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45634f4c546sm14183065e9.7.2025.07.17.00.48.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jul 2025 00:48:56 -0700 (PDT) Message-ID: <56d31e81-79d8-40bd-b957-0d6dc7c46589@gmail.com> Date: Thu, 17 Jul 2025 09:48:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: track generic and custom plans in pg_stat_statements To: Sami Imseih Cc: Greg Sabino Mullane , pgsql-hackers , Nikolay Samokhvalov , Ilia Evdokimov References: <1d667f28-c739-417b-b024-7f5c1004a008@tantorlabs.com> <60f09467-bfe6-49bc-a47a-fe887050a23a@tantorlabs.com> <5f775987-8a93-452d-bb3f-a1de53836406@gmail.com> 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 17/7/2025 00:58, Sami Imseih wrote: >> this for better tracking. By adding a CachedPlanSource::cplan link, we >> can establish a connection to the entire PlanCache entry instead of only >> CachedPlan within a queryDesc and, consequently, make it accessible from >> the executor. This would give an access to statistics on costs and the >> number of replannings. > > This maybe out of scope for this patch, but can you elaborate on what you mean > by "CachedPlanSource::cplan link" ? You need to introduce a 'status' field, right? - to allow someone to identify the plan's type, which was previously somewhat complicated. However, it may be implemented in a slightly different way, by adding CachedPlanSource::cplan (meaning 'Current Plan') and a trivial convention: 'cplan' references the gplan field or it refers a custom plan. Instead of the CachedPlan, we may provide the executor with a link to more stable and informative CachedPlanSource entry. That's the main idea. As I see it, CachedPlan doesn't make sense without plancache and a CachedPlanSource entry. So, it is at least a valid solution. With that link, you can access various statistics: num_custom_plans, num_generic_plans, total_custom_cost, and generic_cost. It would also be possible to clear the *_cost fields and allow Postgres to make a new attempt at choosing the plan type - who knows, maybe the previous decision is already outdated? My point is that we can address one of the common issues with generic plans in a more extensible way, enabling modules to access the CachedPlanSource data at the time they have access to the execution instrumentation. It seems impractical to me to invent one more patch: since you've already modified the CreateQueryDesc interface and introduced a plan type identification logic, why do it twice? -- regards, Andrei Lepikhov