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 1sAL4x-0095DO-2h for pgsql-hackers@arkaria.postgresql.org; Fri, 24 May 2024 02:54: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 1sAL4w-001TR3-5F for pgsql-hackers@arkaria.postgresql.org; Fri, 24 May 2024 02:54:46 +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 1sAL4v-001TQt-ET for pgsql-hackers@lists.postgresql.org; Fri, 24 May 2024 02:54:45 +0000 Received: from m16.mail.163.com ([117.135.210.4]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sAL4o-000TR7-93 for pgsql-hackers@lists.postgresql.org; Fri, 24 May 2024 02:54:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=+oT51V4CGFt39KNZOQxSdpDYpIJaOz7a/Skf9xuSzxo=; b=na1xJxrSSM/sNgI9tK+bTGoeaoBYXSa2FOKoxJkQLn5caTrqgad9qNM783JGOm PrBsX7cZVIYgeOjL7PDRBdn8iM/6hGqhSQe71AcrLcL9Nv4taD7Z00mbNNg4xv8H J3d6AdS39lpOz0suvcg653QXmRgs0kVBx7DO9tl+mkKuU= Received: from ae33eed2ccd8 (unknown [121.237.177.100]) by gzga-smtp-mta-g1-5 (Coremail) with SMTP id _____wDXpwldAVBmU5fFAw--.61862S3; Fri, 24 May 2024 10:54:21 +0800 (CST) References: <87il4jrk1l.fsf@163.com> <87frxf1gld.fsf@163.com> <875xyb1a6q.fsf@163.com> <87zfvedbsr.fsf@163.com> <87y1axc1o1.fsf@163.com> <05aca065-f1f1-48af-b0e8-5eaa72ee6b6f@enterprisedb.com> <87ttllbd00.fsf@163.com> <233cce7b-d9ae-4605-9b76-1f3b98cbc7f0@enterprisedb.com> <875xv6k3k1.fsf@163.com> <87ikz5i9m1.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Robert Haas Cc: Nikita Malakhov , Tomas Vondra , Michael Zhilin , Peter Smith , vignesh C , Matthias van de Meent , pgsql-hackers@lists.postgresql.org, Andres Freund Subject: Re: Shared detoast Datum proposal Date: Fri, 24 May 2024 02:46:38 +0000 In-reply-to: Message-ID: <874janudgi.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXpwldAVBmU5fFAw--.61862S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7urW5Ww4kCw1DWrWkKFWUCFg_yoW8uFWUpF W3JFsFkw4qvF1kXrnxZw10vF1Fyry0vry3Jr95J34kAr4YqryxXF95JrWYkFZ8uryvgF4Y va1jqa4UGasxZa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRf-PbUUUUU= X-Originating-IP: [121.237.177.100] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBZwDoU2V4HQ4qWwAAsj List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Wed, May 22, 2024 at 9:46=E2=80=AFPM Andy Fan = wrote: >> Please give me one more chance to explain this. What I mean is: >> >> Take SELECT f(a) FROM t1 join t2...; for example, >> >> When we read the Datum of a Var, we read it from tts->tts_values[*], no >> matter what kind of TupleTableSlot is. So if we can put the "detoast >> datum" back to the "original " tts_values, then nothing need to be >> changed. > > Yeah, I don't think you can do that. > >> - Saving the "detoast datum" version into tts_values[*] doesn't break >> the above semantic and the ExprEval engine just get a detoast version >> so it doesn't need to detoast it again. > > I don't think this is true. If it is true, it needs to be extremely > well-justified. Even if this seems to work in simple cases, I suspect > there will be cases where it breaks badly, resulting in memory leaks > or server crashes or some other kind of horrible problem that I can't > quite imagine. Unfortunately, my knowledge of this code isn't > fantastic, so I can't say exactly what bad thing will happen, and I > can't even say with 100% certainty that anything bad will happen, but > I bet it will. It seems like it goes against everything I understand > about how TupleTableSlots are supposed to be used. (Andres would be > the best person to give a definitive answer here.) > >> - The keypoint is the memory management and effeiciency. for now I think >> all the places where "slot->tts_nvalid" is set to 0 means the >> tts_values[*] is no longer validate, then this is the place we should >> release the memory for the "detoast datum". All the other places like >> ExecMaterializeSlot or ExecCopySlot also need to think about the >> "detoast datum" as well. > > This might be a way of addressing some of the issues with this idea, > but I doubt it will be acceptable. I don't think we want to complicate > the slot API for this feature. There's too much downside to doing > that, in terms of performance and understandability. Thanks for the doubt! Let's see if Andres has time to look at this. I feel great about the current state.=20 --=20 Best Regards Andy Fan