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 1tvL2z-003el0-FC for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 18:55: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 1tvL1y-006q8k-O8 for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 18:54:14 +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 1tvL1y-006q65-Dr for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 18:54:14 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tvL1w-000Bp7-0T for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 18:54:14 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-38a25d4b9d4so567817f8f.0 for ; Thu, 20 Mar 2025 11:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742496851; x=1743101651; 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=IkFQrlmhN2ma/7RyqwCDEmcET62dgW00132AJYk76SA=; b=NQ5lHzKCFJZ5LhuWwmYkBUyGO8gCN5ucspj0m6Qmzvkx70/ILNWBLrWfbJcSl86qQ+ MsQwHQQMFpsg0yspI2Tg01tw6LVuWj3BXzSBHS4hNCZm4+X93jGEzqX4MKcO5/AtfLnd WL7xoCi6plScL4cdqqUU/7VBn8tsDXYTFs1iMzL6DciO6jodQhBsp4cMtV8WgyndWQvK QPzBYpuVTnAztMAhyPmerU5QJahUwA0LibA5R6FviEeV7Hsd0gFoehOTlfzSKWRHC2Tp mFts3tUzJd54q8GxZZ4a7FxQXaIs5Q6GICtVhZHaAFW3m1uL2G6+wKCP+Lq4w1obGOYL +ABw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742496851; x=1743101651; 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=IkFQrlmhN2ma/7RyqwCDEmcET62dgW00132AJYk76SA=; b=wsQPsDGHdIgyrc4Wx45yjUSguWiU6pv3xlpenrVfHW2hm+xqcU3kkgidF3msq5eQBc s5Gk0OYBmtaJiPxdpcYIx+S4pO4mA9KIISwu9n0sRU4or8/bevzFQDKtxYk5M32YlyBa uOZrvSVr3rn9IZ02ciXFsPR6xfx3U68hsPedbM2hqqQWReGvA6wrwyqt5WPkfRU6zlMi IXbzVhnca/pp6Me9y1nC5znN6NrU9YN5oH40HnQCXWnkRcj64y1CzVZY/qbuiAhk600W PP6WJgOSOgcwnAsVsAxVdCtxcYoTrHAI7BvyJ3/hTe0gsefmoiU1MskQ81DO5OEZ5l1z POzg== X-Forwarded-Encrypted: i=1; AJvYcCUdFu/9azXp5t+HjMev12kNHNoibCIfVYOOFv8hTUZKlhBFISBOs61yT3KphSh8Gn+eI2a8IqLnDLO7Ip/+@lists.postgresql.org X-Gm-Message-State: AOJu0Yy2jDdGQZrg3BNbs5Zk6DgmQKMkROqMI6XvEmkyKXKkZHRXe/JS +08EEm7jvMVSN7gNqvvvIN7/YJrPqeuN1ckn602OL/liAYhVJR6l X-Gm-Gg: ASbGncup7OJtxVsfKPD+LQ22C1N+L0XJzCIkqIRRZu4XtgKbqq64jbAc/43R5AJzyLM 89B3rsP6IqdAp/nGP8k7CCgpeSVpkrdqxWZKE7w2yW89nqI2gOB2IxeyR/XGl3t766kYa0bu07R TMOFQRigol9oCV9UMaTZ6z3ymhgRenvMjt8Pwapfg2dBmApOJAB5vkGvOPMo16UnBpPGjYzos91 tQSjJ9vbOy70fkxMqZ+fNRPH+wY/h/mKZ8BpbBD/Wsj0GNIN1gbxgwP4lNaloagd7/FkMtGBCb4 bS/qdEIR9is0FLiYB2sEMzroFKvX8WYHNnAnOI77TgKMRWyHb5TQ X-Google-Smtp-Source: AGHT+IEnp/w9y5n5FTfsKqFQOINep0DFbuo/pUgGHaAgjPlE6xaJfrWUbPEiJIIklAgDQVYh+qS1ZA== X-Received: by 2002:a5d:64e4:0:b0:391:43cb:43fa with SMTP id ffacd0b85a97d-3997f9595a8mr594626f8f.51.1742496850554; Thu, 20 Mar 2025 11:54:10 -0700 (PDT) Received: from [10.59.3.23] ([90.121.90.131]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3997f9ef1f7sm308142f8f.82.2025.03.20.11.54.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Mar 2025 11:54:09 -0700 (PDT) Message-ID: <8e12aa55-39eb-4e03-a8f7-077fe02309c3@gmail.com> Date: Thu, 20 Mar 2025 19:54:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment To: Ilia Evdokimov , David Rowley Cc: Lukas Fittl , Daniel Gustafsson , PostgreSQL Hackers References: <51A15CD7-E31B-483D-B911-D0EB9F5FF952@yesql.se> <44229379-3901-4cb0-8812-b354ef70d5e2@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 20/3/2025 15:03, Ilia Evdokimov wrote: > > On 20.03.2025 15:32, Andrei Lepikhov wrote: >> 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. > > > Then before proceeding further, I think we need to benchmark this change > to ensure there are no performance regressions. If performance issues > arise, then using extensible EXPLAIN might be the only viable approach. > > I have addressed most of the review comments except for the > ExplainPropertyText change. I am attaching v3 of the patch with these > updates. If anyone notices any performance issues, please let me know. > Issue with ExplainPropertyText for this thread I'll fix in the next > patches if it will be necessary. > > So far, I have tested it on small machines. There are no performance > issues yet. I'll run benchmarks on larger ones soon. I have some doubts here. The number of distinct values says something only when it has taken together with the number of calls. Frequently, one of the caching keys is from outer table A (10 tuples), and another is from outer table B (100 tuples). Calculating the number of successful cache fetches predicted by the planner may not be evident in the case of a composite cache key. What I may propose here is: 1. Use fraction of calls, for example - 50% duplicated key values. 2. Show the calculated hit and eviction ratio. The second option looks better to me. It is pretty understandable by a user and may be compared to the numbers obtained during the execution. -- regards, Andrei Lepikhov