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 1tvF5n-002hQu-WC for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 12:33:48 +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 1tvF4o-000Uy0-8j for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 12:32:46 +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 1tvF4n-000Uxs-VC for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 12:32:45 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tvF4l-0007qy-3D for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 12:32:45 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43d0c18e84eso3168065e9.3 for ; Thu, 20 Mar 2025 05:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742473962; x=1743078762; 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=dqtPC92zFkVxsalfdi/IIk6UIz3cZEya1xIjJ2a15ng=; b=D03Kx/hFfdwVOdB113l2O1Rx1MgqMwn+fx2+vNlAXllOhEpH6ErxK1zVppneO/ycCU 0noLFb1mv+Sp5OANXROJ5rPZgGIf960ckGy4xK2BUMKK//jrNGrvx31yH/Uxc39pnp/p 4CTSbIZogFCW14hW3Gb/2h20ivbw5xskGZg0qZHBClgujb7mMDUuRSGC+4zOdCHGyDfA YVNJsg9AO5gK/j3jG/byfAXNZ3xBWiusljuyDRmZC2KESMNU02ub9+/UYYeLWe8gnuOB udn88Asygni4sdCLEbM0wY0TCVDkkwmdc1EHAvIxXCWRgGcxRgRF8fxrxK9WbOziRpA+ RJDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742473962; x=1743078762; 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=dqtPC92zFkVxsalfdi/IIk6UIz3cZEya1xIjJ2a15ng=; b=APZWpI3mSzQgcOB6w8UqCsY6mnilBo+n9iuk3vvQtjJSSxziA+9jXJr2vIq9tFyRRf bJppBZI+C57jaSw7M/8k6brUtYFzTS+SeGaZ7kAd2GkCeTiV8V3lY5vDq/LNHHvVsBsT OO++GWN3d0WsvXjkpOnQIr6Bvuvsb5zy+EMKrT2rrY28TxQsETw9DBdXft3BcawAjpNW TEi+PTlQQKqhVojcKZIzF7cCPVXNGCctQEr0LbU6vbHVmyDelSALd+pfAWBAedem9c2Y 2PiNJOhpdy6WtwIzdOP3dAIXdHMWrXpfBksXmP84S9c+JRZM8fFIlQ/vcHRd67tbZeYF /PJA== X-Forwarded-Encrypted: i=1; AJvYcCW2lzfyTCd68BoD5sOgqJ3TRGOCCektSWXZM6exGlp+vk0jM/4ZoWV1rmTuw4gSq5S4b3Wi2I17U/BXW0u5@lists.postgresql.org X-Gm-Message-State: AOJu0YynaV0fzCOm5kSPp42Q3dcKC7CbG8Tb+PdCu7MKJgr5dhN/6hm1 RZUwNCHOYnQ2OYGtMJCW0oEAK7ynEVBOWsLshEzpRfF31zIgPpin X-Gm-Gg: ASbGnctb7LPY/Sh6r3vaMoZ2bJ27nFJelH/C4KZhXbXblihhzY/avjVB1qVlGS4fOB6 ztX/gVgixH7vLxURgP0TsXh/iEW5fmOCSelWwAz5kr2B5dkce++ifMI3jHQbxcuhIqzlv8o7bRB GBWRAFt4WkIwaXcCpETAye277nyBxxGZcOYgQUxwtzasD1sF8hjIrINz52ixSE/xI65G6H1jNz8 0zimkGEPsCZgTF7OePIqCIHCnZXYWXbOJrssl7DMbq9m0fMDjWc5nfE8JJ94C+AtyOpTCdCD6/e 1ayIOa4ukhVW+UstkxzhGLNsxu59DSqRRZ+fyI0kmoljkVU3g/2LDmQYbyPUeKEWxpstdNOqA9Y wDE8ZbB3010+sUkJ+5yHyEaQnDTHrQo5hupU= X-Google-Smtp-Source: AGHT+IEy+npzKWfdSgTS7OovIbg/9SplWK0SnSnMUIyvcuhTADPW6oBhq57RCHIkfWhsBx3QEz4gLw== X-Received: by 2002:a05:600c:384d:b0:434:fa55:eb56 with SMTP id 5b1f17b1804b1-43d495367fcmr29621205e9.7.1742473962030; Thu, 20 Mar 2025 05:32:42 -0700 (PDT) Received: from [192.168.13.16] (laubervilliers-657-1-8-163.w80-12.abo.wanadoo.fr. [80.12.80.163]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb7ebaedsm24315638f8f.90.2025.03.20.05.32.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Mar 2025 05:32:41 -0700 (PDT) Message-ID: <44229379-3901-4cb0-8812-b354ef70d5e2@gmail.com> Date: Thu, 20 Mar 2025 13:32:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment To: David Rowley , Ilia Evdokimov Cc: Lukas Fittl , Daniel Gustafsson , PostgreSQL Hackers References: <51A15CD7-E31B-483D-B911-D0EB9F5FF952@yesql.se> 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 20/3/2025 11:37, David Rowley wrote: > I'm also slightly concerned about making struct Memoize bigger. I had > issues with a performance regression [1] for 908a96861 when increasing > the WindowAgg struct size last year and the only way I found to make > it go away was to shuffle the fields around so that the struct size > didn't increase. I think we'll need to see a benchmark of a query that > hits Memoize quite hard with a small cache size to see if the > performance decreases as a result of adding the ndistinct field. It's > unfortunate that we'll not have the luxury of squeezing this double > into padding if we do see a slowdown. I quite frequently need the number of distinct values (or groups) predicted during the Memoize node creation to understand why caching is sometimes employed or not. But I had thought about an alternative way: having an extensible EXPLAIN (thanks to Robert), we may save optimisation-stage data (I have the same necessity in the case of IncrementalSort, for example) and put it into the Plan node on-demand. So, the way I want to go is a Plan::extlist node and create_plan hook, which may allow copying best_path data to the final plan. So, here, we will add a new parameter and avoid touching the core code. But I would give +1 to current approach if it were done in a shorter time. -- regards, Andrei Lepikhov