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 1rebjK-00CK5o-2y for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 14:13: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 1rebjI-00DvVX-7r for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Feb 2024 14:13: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 1rebjH-00DvVP-UK for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 14:13:16 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rebjC-001Avq-9B for pgsql-hackers@lists.postgresql.org; Mon, 26 Feb 2024 14:13:14 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-512f3e75391so1812595e87.2 for ; Mon, 26 Feb 2024 06:13:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1708956788; x=1709561588; 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=Sqs5WTTr2kSTyuUmzMebwYIhC5sf9PPfgmHpMq7F8D0=; b=jSpSOMsC5RKbC9bRqvcEgtErCNhMXg0BBURugsn/5g04K6qQOTvAXU6wXKfAoO7SXF 7bI0IaShVVT/GqogKcGWzJpaZtENAvsqMWXcDHO1qmf2gILpRu1fsRMy7oRqZMTm3OYD oVnh+s6ub5NltNnitTa5vkAdnx2obBgpFvWCdeNTIR1ZWwaqTefecqQjawpnVZlXmevy DrIWR6RCZ574SZksPcApCJ7AWVSMHTaQcnVeHFboXfgB4xOT3c3vjE0xQDiYPkZVtTRO 5snitDuFhkO68cr4AFeYHr+b4AqFiuybSgkY8izO2bDK8LYFVRdYjbumsEy6KMJl1yrh SqIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956788; x=1709561588; 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=Sqs5WTTr2kSTyuUmzMebwYIhC5sf9PPfgmHpMq7F8D0=; b=UE7F4hNYEZSMBrYh2VNwcaoNRGQM7DjvuRbnYJ8Pja7Kke28rWvYJ2rzKK4kPTP9c9 Ya5jUlXifIaOFpR5lkHhm0jssaEt43IEj+eilGUTTX2wcIjMVerNj8q3y0lBwgxnKH9A GXnrH2HPQYabd4iQP4ww+41j5yJ59EKFJCBhs0x6hjxAG7rp5yGoO7QsShzm56y7mDeD bLEM/zdXWwyzHtc4xZUIueRzTgCFLTzY8MXbEF/Npz2jNXwK3YHQuMfBlXMfWDo4BN61 FvA/q62EjSQCIfx8kfJ3VXHvBYHLmk0AfWjPyMhqNqeAcMRT9ui5laUsu0RGCF3gDTjZ BcRA== X-Forwarded-Encrypted: i=1; AJvYcCUjFEH6wXAwY5WEKkYJ3JyDqL4A/RP4R8X/fLVo5Oox2T+qd+3HFPfZ7mcU/kVarSiqEUsUQW7HsmD5cX0vPZ5qXnCKaNmOS4uIltcBcV+WGohn X-Gm-Message-State: AOJu0YyHdegLA46P8ELfiDsbS0inFxsDqKT4ckqfZ7CJj8EFuPY/e+jm HAXHGXPHWhHVWKPhliqtuTjJs8+nVD2fMOXdjFor/cYJOvgae4FwVTPFMXXmWQ== X-Google-Smtp-Source: AGHT+IE0DM28EQNG2D5ZOIWIi9M77qEehDQGspoNhR/ABOCqz4sniREYk9ICAvEdEaaTFnevUPtKHQ== X-Received: by 2002:ac2:44a1:0:b0:512:aad2:80c9 with SMTP id c1-20020ac244a1000000b00512aad280c9mr4337139lfm.27.1708956788346; Mon, 26 Feb 2024 06:13:08 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id h10-20020aa7c94a000000b00565dd45b53esm1361365edt.39.2024.02.26.06.13.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Feb 2024 06:13:08 -0800 (PST) Message-ID: Date: Mon, 26 Feb 2024 15:13:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Shared detoast Datum proposal Content-Language: en-US To: Andy Fan , Nikita Malakhov Cc: Michael Zhilin , Peter Smith , vignesh C , Matthias van de Meent , pgsql-hackers@lists.postgresql.org 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> <87frxf1gld.fsf@163.com> From: Tomas Vondra In-Reply-To: <87frxf1gld.fsf@163.com> 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 2/26/24 14:22, Andy Fan wrote: > >... > >> 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. > Any substr/starts_with call benefits from this optimization, and such calls don't seem that uncommon. I certainly can imagine people doing this fairly often. In any case, it's a long-standing behavior / optimization, and I don't think we can just dismiss it this quickly. Is there a way to identify cases that are likely to benefit from this slicing, and disable the detoasting for them? We already disable it for other cases, so maybe we can do this here too? Or maybe there's a way to do the detoasting lazily, and only keep the detoasted value when it's requesting the whole value. Or perhaps even better, remember what part we detoasted, and maybe it'll be enough for future requests? I'm not sure how difficult would this be with the proposed approach, which eagerly detoasts the value into tts_values. I think it'd be easier to implement with the TOAST cache I briefly described ... regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company