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 1rA8uv-0050n0-Es for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2023 13:23:22 +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 1rA8ut-00Gqhc-CA for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2023 13:23:19 +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 1rA8us-00Gqh5-Cu for pgsql-hackers@lists.postgresql.org; Mon, 04 Dec 2023 13:23:19 +0000 Received: from m12.mail.163.com ([220.181.12.197]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rA8un-00A3KI-B1 for pgsql-hackers@lists.postgresql.org; Mon, 04 Dec 2023 13:23:17 +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=mziUVIucImdL0Yk+DbG2TGBd/gNWOFA66sFPhzBwRAc=; b=gmVPSUGu3/E9BqZxvu18Zo7KbxUoOFLeRDhZuMyrOG2QzpviAqRt7/2Bikr94o fU9DTW6PtBQMZbpgGtjKMsuKCFXimdWTpeg4RK0S5zQwFuMaTJQ2yOPVfosa8rPk d00SW1fMsBBHighFn5tlamVCJ5t3cwMFX0xKdUqWv8g2Y= Received: from b97369165980 (unknown [140.205.118.26]) by zwqz-smtp-mta-g4-0 (Coremail) with SMTP id _____wAH_ra10m1lBat8Eg--.61135S3; Mon, 04 Dec 2023 21:23:01 +0800 (CST) References: <87ttoyihgm.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: zhihuifan1213@163.com To: Matthias van de Meent Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Avoid detoast overhead when possible Date: Mon, 04 Dec 2023 20:55:05 +0800 In-reply-to: Message-ID: <87a5qqhzka.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID:_____wAH_ra10m1lBat8Eg--.61135S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr1DAr4rCrWDWr47ArW7CFg_yoW8Wr1UpF 45KryfKr1kAay3AwnxZF48JF4fArn5JFy5Ar97t34I9w45WryIqr13KrWq9FW7ur4kAr4Y vF42qryYvanY9a7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR-Aw-UUUUU= X-Originating-IP: [140.205.118.26] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiDhs8U2SAZE6LggADs+ List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Matthias van de Meent writes: > On Mon, 4 Dec 2023 at 07:56, wrote: > ..It would also add overhead when > we write results to disk, such as spilling merge sorts, hash join > spills, or CTE materializations. > > Could you find a way to reduce this memory and IO usage when the value > is not going to be used immediately? Using the toast pointer at such > points surely will be cheaper than storing the full value again and > again. I'm not sure I understand you correctly, I think the issue you raised here is covered by the below design (not implemented in the patch). " However this patch just throws away almost all the benefits of toast, so how can we draw a line between should vs should not do this code path? IMO, we should only run the 'eagerly detoast' when we know that we will have a FuncCall against the toast_col on **the current plan node**. I think this information can be get from Qual and TargetList. If so, we can set the slot->detoast_attrs accordingly. " Let's see an example of this: SELECT f(t1.toastable_col) FROM t1 join t2 using(c); Suppose it is using hash join and t1 should be hashed. With the above design, we will NOT detoast toastable_col at the scan of t1 or hash t1 since there is no one "funcall" access it in either SeqScan of t1 or hash (t1). But when we do the projection on the joinrel, the detoast would happen. I'm still working on how to know if a toast_col will be detoast for a given PlanState. If there is no design error, I think I can work out a version tomorrow. -- Best Regards Andy Fan