Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olB1P-0000mZ-NX for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 15:30:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1olB1O-0005Nc-D9 for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 15:30:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olB1N-0005NT-Cc for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 15:30:18 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olB1J-0007mI-0d for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 15:30:16 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 0D3E65C01B9; Wed, 19 Oct 2022 11:30:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 19 Oct 2022 11:30:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1666193410; x=1666279810; bh=t 37CyGLO1pi5z8P7IV9NeX+y4453f+hZzU1osP3RQg0=; b=qIUXTXMZ7O+YD+Dyk 9H1PyfFCKiILQUlDi4cq0Wk/7u/NN4DRvOBSvtVkmzbw9QI6q3ZIHcJUbb9UtuI0 A4Nowq2FsF1HnAYaHkJ8wqKMprLVNQBLgjQh7+TGgef+Wzs66jbpCIAfxfV090Vr Iba9Ub1duOr6QYtFy/BzJPUT9PjUhpGgkOhkJRuZndq2FSbnHDkKWJCYW4P9LP/d UVUhIUbZU2ZtRYMNIdF+NEgdVmyHXivMND6JlF0pcrHLX7MdzChiftrN1u5MqH+x EE7+17C4gvKQuG6/iRodY3GW5ck8i+ZGQUg0ZQsQADqY3NAG28DzM9i7/V+WGbYW DeUGg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeelgedgkeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 19 Oct 2022 11:30:09 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id AE6AE70; Wed, 19 Oct 2022 17:30:06 +0200 (CEST) Date: Wed, 19 Oct 2022 17:30:06 +0200 From: Alvaro Herrera To: Dominique Devienne Cc: pgsql-general@lists.postgresql.org Subject: Re: How to store "blobs" efficiently for small and large sizes, with random access Message-ID: <20221019153006.zmzz4hljtkbo456c@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022-Oct-19, Dominique Devienne wrote: > Anybody has an answer to my question regarding how substr() works on > bytea values? I.e. is it "pushed down" / optimized enough that it > avoids reading the whole N-byte value, to then pass it to substr(), > which then returns an M-byte value (where M < N)? > > If TOAST stores 2,000 chunks, and those chunks' PKs are numbers, > simple arithmetic should be able to select only the chunks of > interest, those incurring only the necessary IO for the selected > range, no? That's exactly what I was trying to say. If there's no compression, we don't read prior chunks. (This is valid for bytea, at least; for textual types we have to worry about multibyte characters, which are again a potential source of confusion regarding the exact location you want to seek.) This can be seen in detoast_attr_slice() in src/backend/access/common/detoast.c, though there are way too many^W^W^W multiple layers of indirection if you start from bytea_substr() in varlena.c. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/