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 1rebM5-00CHUx-Mo for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 13:49:18 +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 1rebM4-00Dm67-8G for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 13:49:16 +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 1rebM3-00Dm5t-Gx for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 13:49:16 +0000 Received: from m15.mail.163.com ([45.254.50.220]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rebLu-001Aad-Cf for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 13:49:15 +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=1YpZmTjIKquOlcuVR5yZB7wc2RAdQ5HItmYYrTlDmNE=; b=kyIxbLoxp54UCN4dD0BlfdIAL/K5NXHwR2dCaNcdyPOelqPXQkZsVdSSpBF+cb SMVoEcFq02nq1gnC4x9RvvkT/UzRaWGrGdwzIAuFbQe+9ct6YiGy1O1H9EjDscue HtuOkdicyjBPAha6kq+X5SZJ3ulRP2QadSfal858Ib2jA= Received: from 8235eee8a2a0 (unknown [140.205.118.201]) by gzga-smtp-mta-g0-3 (Coremail) with SMTP id _____wB358q+ltxlFUGNFA--.19683S3; Mon, 26 Feb 2024 21:48:47 +0800 (CST) References: <87il4jrk1l.fsf@163.com> <87h6jxw41k.fsf@163.com> <87sf3andy2.fsf@163.com> <87wmskm9qu.fsf@163.com> <87v87kvboq.fsf@163.com> <71321d83-391b-473b-aaf6-618c7f682b96@postgrespro.ru> <87r0i7vos3.fsf@163.com> <874je3hcwn.fsf@163.com> <8734tmg88e.fsf@163.com> <7f4c8673-4c5d-4dbf-b8e5-0ec11cd2fba0@enterprisedb.com> <87h6i2djf9.fsf@163.com> <87jzms0xza.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Nikita Malakhov Cc: Tomas Vondra , Michael Zhilin , Peter Smith , vignesh C , Matthias van de Meent , pgsql-hackers@lists.postgresql.org Subject: Re: Shared detoast Datum proposal Date: Mon, 26 Feb 2024 21:22:39 +0800 In-reply-to: Message-ID: <87frxf1gld.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wB358q+ltxlFUGNFA--.19683S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7tFWfGFWfAFyftF4UXrW5Wrg_yoW8CF13pr WSqrW3Kr4DC3yDAwn7X3WrWr9Yvw4FkF45J3s5A3y8uw15G34Ikr4ktrW5JFWUCw4kZr4a vF4UXr45ZanrAaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRpwZ3UUUUU= X-Originating-IP: [140.205.118.201] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiQBeQU2VOBoK3AgABsP List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, > When we store and detoast large values, say, 1Gb - that's a very likely scenario, > we have such cases from prod systems - we would end up in using a lot of shared > memory to keep these values alive, only to discard them later. First the feature can make sure if the original expression will not detoast it, this feature will not detoast it as well. Based on this, if there is a 1Gb datum, in the past, it took 1GB memory as well, but it may be discarded quicker than the patched version. but patched version will *not* keep it for too long time since once the slot->tts_values[*] is invalidated, the memory will be released immedately. For example: create table t(a text, b int); insert into t select '1-gb-length-text' from generate_series(1, 100); select * from t where a like '%gb%'; The patched version will take 1gb extra memory only. Are you worried about this case or some other cases? > Also, toasted values > are not always being used immediately and as a whole, i.e. jsonb values are fully > detoasted (we're working on this right now) to extract the smallest value from > big json, and these values are not worth keeping in memory. For text values too, > we often do not need the whole value to be detoasted. I'm not sure how often this is true, espeically you metioned text data type. I can't image why people acquire a piece of text and how can we design a toasting system to fulfill such case without detoast the whole as the first step. But for the jsonb or array data type, I think it is more often. However if we design toasting like that, I'm not sure if it would slow down other user case. for example detoasting the whole piece use case. I am justing feeling both way has its user case, kind of heap store and columna store. FWIW, as I shown in the test case, this feature is not only helpful for big datum, it is also helpful for small toast datum. -- Best Regards Andy Fan