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 1rea6u-00C9kn-Ju for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 12:29:33 +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 1rea6s-00DI5M-Tl for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 12:29:31 +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 1rea6s-00DI5E-Fw for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 12:29:31 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rea6j-001BcU-FA for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 12:29:29 +0000 Received: from [172.30.0.166] (unknown [172.30.0.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id DFCEDE20C38; Mon, 26 Feb 2024 15:29:15 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1708950557; bh=IzThxkFPf+Ejps4rVT0Ro5S3KlNkevyflzS1xbNsmE0=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=L2x48kUYBh9t9Gzc6yu3w7Qh9dP9POY05SFlkQYbzJr0Kp4GbTG+uKOOslk34K+Ul MgVp6PmtChjTi0je1wWHyjr468llsUccNwbzivhevSz/1Pow9advxccGLzKh00JVYw JgADXRC2mAAG/kxkY5QBUA+1S0zKNwKv0l7YfH/7qumA2436uFmiQ845gk73DUsfoX PWZA7exb7KSp5nQiceMAPsjHxhCCsn5n7AdDkqhzy8pDHz/FsT4+lJbil0lXUE4W5N KapwO7NGgw+f/8+FsMPq8S9CViVFS9EdZwaGc+01zD1Eqr4e73h4mOp01CF+75No4g DTHCPtXaI2abw== Message-ID: Date: Mon, 26 Feb 2024 19:29:12 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: "type with xxxx does not exist" when doing ExecMemoize() Content-Language: en-US To: Richard Guo Cc: Tender Wang , PostgreSQL Hackers , David Rowley References: <7a6a807c-193f-4333-937b-8211b1330579@postgrespro.ru> From: Andrei Lepikhov Organization: Postgres Professional 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 26/2/2024 18:34, Richard Guo wrote: > > On Mon, Feb 26, 2024 at 3:54 PM Andrei Lepikhov > > wrote: > > On 26/2/2024 12:44, Tender Wang wrote: > > Make sense. I found MemoizeState already has a MemoryContext, so > I used it. > > I update the patch. > This approach is better for me. In the next version of this patch, I > included a test case. I am still unsure about the context chosen and > the > stability of the test case. Richard, you recently fixed some Memoize > issues, could you look at this problem and patch? > > > I looked at this issue a bit.  It seems to me what happens is that at > first the memory areas referenced by probeslot->tts_values[] are > allocated in the per tuple context (see prepare_probe_slot).  And then > in MemoizeHash_hash, after we've calculated the hashkey, we will reset > the per tuple context.  However, later in MemoizeHash_equal, we still > need to reference the values in probeslot->tts_values[], which have been > cleared. Agree > > Actually the context would always be reset in MemoizeHash_equal, for > both binary and logical mode.  So I kind of wonder if it's necessary to > reset the context in MemoizeHash_hash. I can only provide one thought against this solution: what if we have a lot of unique hash values, maybe all of them? In that case, we still have a kind of 'leak' David fixed by the commit 0b053e78b5. Also, I have a segfault report of one client. As I see, it was caused by too long text column in the table slot. As I see, key value, stored in the Memoize hash table, was corrupted, and the most plain reason is this bug. Should we add a test on this bug, and what do you think about the one proposed in v3? -- regards, Andrei Lepikhov Postgres Professional