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 1rhyLn-00ENLr-Gb for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Mar 2024 20:58:56 +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 1rhyLm-00EMm2-0p for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Mar 2024 20:58:54 +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 1rhyLl-00EMlt-NA for pgsql-hackers@lists.postgresql.org; Wed, 06 Mar 2024 20:58:54 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhyLh-003CQd-Kg for pgsql-hackers@lists.postgresql.org; Wed, 06 Mar 2024 20:58:52 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-51344bebe2fso138139e87.2 for ; Wed, 06 Mar 2024 12:58:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1709758729; x=1710363529; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Cp1RqU/P7z6NY7CDuaRRZRhrwKB4hbND3AfRF/5+N/E=; b=djFtTTRPPTZmDLrGtMpCg3RI0NaOMiLlLXYdUOp5ufHmDpDG9Gt7j9sQ8juDxrb265 dfCFhjekEt/XMLxecdNmBxaYl0yQnNXm40JqdOzgWxi+HY2fexw754GY3W2XWaRyCpDj tySJ3W3eAkz41jQfJv/T7trdNtz7wGEhXHXHdzt5PfgAm0k3zCf6p7thCBlZu4Xe8g3U keqIr0NDIRd90Fum5uB4k8o9w0cG9MeeUrOSX0pI1cYpvTRJaOwNaXRZ9fMu+JRmtdY/ Qn4ATJ7+8ssR0xDzXu2d64FJpFJ9WxsZEFezEg9WrDy+BIi8FvVo32oF6tFo6njIKoZf mhTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709758729; x=1710363529; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Cp1RqU/P7z6NY7CDuaRRZRhrwKB4hbND3AfRF/5+N/E=; b=h8UdDyJAd/B42HCEMQV/I9g0f0md7fvvkEUS+z+tmNO1pAmC7kyp7T9KKLgaLyPvPB MlrGl28Iqi7kiIULBgPPNy2S4Ma3GM3gtM0gRu8pIOMKgaq4D0mhe1vjiPNepxIiW4ZC lB45WI5QAqh4QyfwpdHDIwT7Ys2AIGuhEqmc1pa++Lx6J92X7eVYxiU9rjsIZLHHfFkJ T3mLU0Sbgre35Wod10BpCN0o9lPw8Fn5FZOIhw4VfBTQwmVDBQe83TdYx8UeWCAsoD4e iAsiJp2H3RN3m5SV+YtuB5uvuQ/yQ/w++9sxo/tqbd8jCrv5oQ/iVgRwac6hInF67ph7 rGUg== X-Forwarded-Encrypted: i=1; AJvYcCU0u3+lFbovpvv5m4UkIz+JnTGpqc41StnnUghz326a50QUESUyYz0dUlKSk9EV6oI+DLsQy3LM1vexWEjvdiGbJWRQJ2LdOjqQznxQgOjCuYn6 X-Gm-Message-State: AOJu0YwsO5PDZ9UPBIvfaSkBdjfUYyT+eZKcuCnFdXGq7B2sygX+xn1M WLOe9mmfeUrZ11u+JjnqY0CtJXOsNfRAfMQmNtsS42lAMigGOMNtq7WzV65NQw== X-Google-Smtp-Source: AGHT+IHY1LLeZztdvmSMAuAw2HjWWl23XWxAFZ175dh00TEISzs90tNDE92HQELstNBPUdL5jip7qg== X-Received: by 2002:ac2:5b43:0:b0:513:1a44:61e2 with SMTP id i3-20020ac25b43000000b005131a4461e2mr146334lfp.10.1709758728926; Wed, 06 Mar 2024 12:58:48 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-225-124.bb.vodafone.cz. [86.49.225.124]) by smtp.gmail.com with ESMTPSA id se24-20020a170906ce5800b00a45c4d3ee11sm468461ejb.123.2024.03.06.12.58.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Mar 2024 12:58:48 -0800 (PST) Message-ID: <233cce7b-d9ae-4605-9b76-1f3b98cbc7f0@enterprisedb.com> Date: Wed, 6 Mar 2024 21:58:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Shared detoast Datum proposal Content-Language: en-US To: Nikita Malakhov , Andy Fan Cc: Michael Zhilin , Peter Smith , vignesh C , Matthias van de Meent , pgsql-hackers@lists.postgresql.org References: <87il4jrk1l.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> <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> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/5/24 10:03, Nikita Malakhov wrote: > Hi, > > Tomas, sorry for confusion, in my previous message I meant exactly > the same approach you've posted above, and came up with almost > the same implementation. > > Thank you very much for your attention to this thread! > > I've asked Andy about this approach because of the same reasons you > mentioned - it keeps cache code small, localized and easy to maintain. > > The question that worries me is the memory limit, and I think that cache > lookup and entry invalidation should be done in toast_tuple_externalize > code, for the case the value has been detoasted previously is updated > in the same query, like > I haven't thought very much about when we need to invalidate entries and where exactly should that happen. My patch is a very rough PoC that I wrote in ~1h, and it's quite possible it will have to move or should be refactored in some way. But I don't quite understand the problem with this query: > UPDATE test SET value = value || '...'; Surely the update creates a new TOAST value, with a completely new TOAST pointer, new rows in the TOAST table etc. It's not updated in-place. So it'd end up with two independent entries in the TOAST cache. Or are you interested just in evicting the old value simply to free the memory, because we're not going to need that (now invisible) value? That seems interesting, but if it's too invasive or complex I'd just leave it up to the LRU eviction (at least for v1). I'm not sure why should anything happen in toast_tuple_externalize, that seems like a very low-level piece of code. But I realized there's also toast_delete_external, and maybe that's a good place to invalidate the deleted TOAST values (which would also cover the UPDATE). > I've added cache entry invalidation and data removal on delete and update > of the toasted values and am currently experimenting with large values. > I haven't done anything about large values in the PoC patch, but I think it might be a good idea to either ignore values that are too large (so that it does not push everything else from the cache) or store them in compressed form (assuming it's small enough, to at least save the I/O). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company