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 1sS6oi-0046yR-FP for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jul 2024 03:19:28 +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 1sS6nj-003uov-0q for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jul 2024 03:18:27 +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 1sS6ni-003uom-NX for pgsql-hackers@lists.postgresql.org; Fri, 12 Jul 2024 03:18:26 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sS6ng-001eyh-Nf for pgsql-hackers@postgresql.org; Fri, 12 Jul 2024 03:18:26 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-52ea79e689eso2057009e87.1 for ; Thu, 11 Jul 2024 20:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720754304; x=1721359104; 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=57EXP55pbFw5wjy2gqq9hj2wl/mFZTjIAkHVUO5woYw=; b=fDCaUjCZYs7zzB2Lus0eYZMbzKkghYlCyXUyCmk9IkwPeotSVYJFXHiycdU9cLAvBh oW/5wtALOUFQj8ISx6KUc0J792pUMZw6XrU+BxASYIEMhQU5igGOlnDyYg4h30gAKvdC va65a6qRsYYVSWptn3ziT/lc87vTIKfgXMusFy0SHA2PjOyFgoVCltCXu2/eSbZ8G2dO fjncjH1xtLEXf/T5LyHzbQAxde2Ahnz0J8e8dWKs0NlVwuhLqfINvaeo6LKK5r5GMidg ORfGu2/ZjkfNHKQ8Ptcbnjy1E+xXafZDAQ4mWwwjeJyCOU/x013JpjfhgNksv/IeQE2l f/4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720754304; x=1721359104; 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=57EXP55pbFw5wjy2gqq9hj2wl/mFZTjIAkHVUO5woYw=; b=rgjwQLrnk467xYAIHEOHFUr3jhCi6NGFiwzYsvEWmSDUGbPkAAsuA52kAvQsoqLMmf DtLyytijYZ/F2rLFVI2Jec2Exjua0X4ysgKuEljvLIks1f3c/FzC3I1BdiDFpQrsYFYc Bk3WXM5QWHQuBdDcsREviFPqxZD/rrRjdAeSzAKguoz/+tyKE+L3H6TRBcgmp/lTpP7x R9J2HzJ0qEX8u2VOc+wEaf2DyjwhY9Z82OwK5gBvqluCzGQKK2aeiO6KM33tm5ClUi+J STH1KyMB0x/ON4Z6kdPjecaYcp3QwX/Lky4fFeLYAfpq2+KCyvMqeVF6mvkkgk5u0Tbd 7tgQ== X-Gm-Message-State: AOJu0Yx5hBLeTAAp8ZUhx/hmxguOjms8Sx1npJFvC8D3nheLfsWxEm2u Oqy8BDwzsNsQTp+5/TR6Yt9crdJD5yp2Phfqw2nMQXI5bFeFqd1f X-Google-Smtp-Source: AGHT+IFScC9nKPxuHdFGPjBfPEtEl5c+o24Gky8bEXgdjZVd+I/tlQ+I4xCCXNxjgUfVSfGURu4Jpg== X-Received: by 2002:a05:6512:1597:b0:52d:b226:942a with SMTP id 2adb3069b0e04-52eb9764a56mr9583669e87.0.1720754303512; Thu, 11 Jul 2024 20:18:23 -0700 (PDT) Received: from [10.10.20.99] (node-bah.pool-113-53.dynamic.totinternet.net. [113.53.57.41]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52eb8e49251sm1152857e87.110.2024.07.11.20.18.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jul 2024 20:18:23 -0700 (PDT) Message-ID: <2a76386f-a104-461b-8d15-ff6c4d762925@gmail.com> Date: Fri, 12 Jul 2024 10:18:10 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Check lateral references within PHVs for memoize cache keys To: Richard Guo Cc: PostgreSQL-development , David Rowley , Tom Lane References: <1724688.1688837323@sss.pgh.pa.us> Content-Language: en-AU 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 7/11/24 16:18, Richard Guo wrote: > On Fri, Jun 28, 2024 at 10:14 PM Andrei Lepikhov wrote: >> I got the point about Memoize over join, but as a join still calls >> replace_nestloop_params to replace parameters in its clauses, why not to >> invent something similar to find Memoize keys inside specific JoinPath >> node? It is not the issue of this patch, though - but is it doable? > > I don't think it's impossible to do, but I'm skeptical that there's an > easy way to identify all the cache keys for joinrels, without having > available ppi_clauses and lateral_vars. Ok > >> IMO, the code: >> if (bms_nonempty_difference(outerPlan->chgParam, node->keyparamids)) >> cache_purge_all(node); >> >> is a good place to check an assertion: is it really the parent query >> parameters that make a difference between memoize keys and node list of >> parameters? > > I don't think we have enough info available here to identify which > params within outerPlan->chgParam are from outer levels. Maybe we can > store root->outer_params in the MemoizeState node to help with this > assertion, but I'm not sure if it's worth the trouble. Got it > > Attached is an updated version of this patch. I'm not sure about stability of output format of AVG aggregate across different platforms. Maybe better to return the result of comparison between the AVG() and expected value? -- regards, Andrei Lepikhov