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.96) (envelope-from ) id 1w1lrJ-000aoL-2U for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Mar 2026 13:50:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w1lrI-004aNG-2V for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Mar 2026 13:50:21 +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.96) (envelope-from ) id 1w1lrI-004aN8-1A for pgsql-hackers@lists.postgresql.org; Sun, 15 Mar 2026 13:50:21 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w1lrG-00000000Fac-2UzA for pgsql-hackers@lists.postgresql.org; Sun, 15 Mar 2026 13:50:19 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-b9795ca4e6dso168307366b.2 for ; Sun, 15 Mar 2026 06:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773582617; cv=none; d=google.com; s=arc-20240605; b=NwJa4DRS0HhtHiAeo2n9J9J4ph/fEUjRT6K9Cjl5Ifg29kdlvzh8auwVGsyaRLVIff CMfcou7hvwBghkNdoW/rs64pMOMZ6TyZk57lbnjFyJTXnbzOIXiWrDpdlE/JMtptC3Qh 83iS+sZwdpf9nVIzvEK9rIbay2jygJsGU8ojoiINmA4z8q3Y0bkbgG3yQpUt3AaLfpLL SaBNGRBp9UkHXUMGlcGOMQJMbIigJ/wy1GxsOMjZzT+8C7N/bsDNd0MHisitcVi41Swh WfjZ228kkei/xqDYfx+tngT5RGVLCNpOg2BE0BykApw47yHnIclrg8yk8BnW9pgVn8Ge Gk/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=gvMRubv/WqfhIlawh5Gyu6id4mHOC8qA89Upmhi0060=; fh=TI/mRE2T0wxshY7cTEk5P+N2/eEIuN3s99W5JnkyPOY=; b=J3/QoQT5/JugE8SbVHM4IYPkcZ2LqvRpFLksLQ19nGmIQGu5ZKV2jtYeC8RWea0z3m w1XisObASnePS6rvWS/OQisLiZdcGOS3l7B+/179ZU0RZiCb6R7XEe6TOAH/t4GLpD4o Drprm8TCBYMCgHQoVntxy3Dx9ixMW/aJhHkt4f3huKBcWLVbbsFFw+hfR4d13h29rAkc Q+Jii11yjwzPsgjeHXHfe+bDLTI+6UwzvaG3XWDn4xbQsDeTRWm4LUGIcEyAPNG4XNDb aWh+ZsXSV38W3d+rN81wV02XuA1GftNdMdQ4LG8rhib170OfX2uFMJOrjsDiaCbJUo9u o6wQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773582617; x=1774187417; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gvMRubv/WqfhIlawh5Gyu6id4mHOC8qA89Upmhi0060=; b=Wr0YbRMB5k9YbcPXWoWvHP7Lms8VcVbyXFcGLYbiCOl2y52ArUaH36G/qSCesuSAV2 b2Pj6wFa9q2/BIZhIGpxJ1eOAaXJSYIhhgZ+xWNxs4OG3LZP0Hv9lodgro/84FiM//lD ZWOAoswHoj+9sO/bVvwN6HowQtTVmdIxhapJnbCx5CF+khMCiHhq3j6mYtuQkCkthity mCyciZG6hPS1J06oPqBS8ZiwcxJjo0vr8/EKJTXbpRV6njdQ5praW0t5sKGrAo09fko3 ZX8buNQyjex44/FcYbGPw9HZKCdO3cQ1DL7HEhsXu5OhgMwoIscYfW6GuWdKd8l2h07p uCXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773582617; x=1774187417; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gvMRubv/WqfhIlawh5Gyu6id4mHOC8qA89Upmhi0060=; b=M2U4x9ElRyQ3FU5Z/+7Z2DBVouT91EjOMywyD6GU+UfhFPvm3MwNDUouLihcja/1BQ 2J845FaImyW9mBrUWF3WG1fVKT325T4PkqoYYFiVcvU0ALlnfFeNyGyRyM+C5ODLTzui u1IxJ2MF5H4707A6TQusVWBYapfP7B7HtdKeXQk3PuGWGkRQ92+0AuPbJb4JvWAzv1gM G9Ob0wlRcTh3vjXeIuXVSXCV/qINsDngjsBpSRq6IGD1cpPz+YFN6ozUTxhhtJBpeg5s JGYSqQwDUoxnoSon3ql8RoM4lHYJOxWkCb+FgsMqUEGoF0uwlH5lCI5CnGewgpWZlpdb JAyw== X-Forwarded-Encrypted: i=1; AJvYcCVV3/rjY83Lu/cuE0pc7sxlzqVXiV8w5OafFFBKUOhJYW2fovAKIszwmpnvgmDzhM/O2Z+//tad1ihE5vIl@lists.postgresql.org X-Gm-Message-State: AOJu0YyzG9XexjDZ+BRiM4ty9dZ0UmMKiqpqCD2WJ8tmOIsdIaaSUuXq PneUly+AkQAgGGUYJd+3xLxLh8U7bIM9yOFzOmTWB5890J+UClw5fWOweD1x47Qhlb93FLPqCbw nfYPYyuilP1QqblXVYbcnfAs/CtBI4MkKsBi9 X-Gm-Gg: ATEYQzyV1HY1p4nAsMi1ulgG0WGXwJDn9+4vs2CyuY233npK0g8jlHhDWRwzDrXkMZK TXBMqL72+pGMJuAVdNyNi+5mmQkhkTZZLRFSypRcabSST+v9E+lLBX0DgUt0vRNuZKMghGyn71v e9Wt9U3FlXikl3xG2+TF402vR7SQdqGVT36cIun1p81aU4MBsAhpTdHwDIPb7AWOpEkOjZoQJ/p vCdRfeEIDDCQ72r7+NMBvrnqVsTQSr6pXOCpH9625rB1Xz9LLWesTKQxCTtVhCvToUndjqeHzZu /W/iz6gTcyXX+BjtGCgUlaX9uAGuItyfr0ou6STe5iCeprZOyQM6TyxaNR3UkMyJ5uZZkkFWTHf P8Uytb+n3 X-Received: by 2002:a17:907:3d12:b0:b96:eae4:e49 with SMTP id a640c23a62f3a-b9764f4b052mr565654166b.6.1773582617106; Sun, 15 Mar 2026 06:50:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Junwang Zhao Date: Sun, 15 Mar 2026 21:50:04 +0800 X-Gm-Features: AaiRm50zSQyJw4ONCFhourWjvpAw_O7tZ0NIrt7J9AFwIh147xRpfrsHHm6dS5c Message-ID: Subject: Re: More speedups for tuple deformation To: David Rowley Cc: Andres Freund , John Naylor , Chao Li , PostgreSQL Developers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Mar 13, 2026 at 8:19=E2=80=AFPM David Rowley = wrote: > > Thanks for having a look. > > > On Sun, 8 Mar 2026 at 05:36, Junwang Zhao wrote: > > I have some comments on v12-0004. > > > > 1. > > > > + off +=3D cattr->attlen; > > + firstNonCachedOffsetAttr =3D i + 1; > > + } > > + > > + tupdesc->firstNonCachedOffsetAttr =3D firstNonCachedOffsetAttr; > > + tupdesc->firstNonGuaranteedAttr =3D firstNonGuaranteedAttr; > > +} > > > > The firstNonCachedOffsetAttr seems to be the first variable width > > attribute, but it seems that the offset of this attribute can be cached= , > > for example, in a table defined as (int, text), the offset of > > firstNonCachedOffsetAttr should be 4, is that correct? > > Yes. > > > If TupleDescFinalize records the offset firstNonCachedOffsetAttr, > > it might save one iterator of the deforming loop. For example, > > add something like the following after the above mentioned code. > > > > if (firstNonCachedOffsetAttr < tupdesc->natts) > > { > > cattr =3D TupleDescCompactAttr(tupdesc, firstNonCachedOffsetAttr); > > cattr->attcacheoff =3D off; > > } > > The problem is that short varlenas have 1 byte alignment and normal > varlenas have 4 byte alignment. It might be possible to do something > if the previous column is 4-byte aligned and has a length of 4 or 8, > since that means the offset must also be 1-byte aligned. The main > reason I don't want to do this is that the only positive is that > *maybe* 1 extra column can be deformed with a fixed offset. The > drawback is that the following code *has* to use > att_addlength_pointer(), *regardless* instead of "off +=3D attlen;". > This means more deforming code and more complexity in > TupleDescFinalize(). I'd rather not do this. That explains, thanks. > > > 2. > > > > in slot_deform_heap_tuple, there are multiple statements setting > > firstNonCacheOffsetAttr, > > > > + firstNonCacheOffsetAttr =3D tupleDesc->firstNonCachedOffsetAttr; > > > > + /* We can only use any cached offsets until the first NULL attr */ > > + firstNonCacheOffsetAttr =3D Min(firstNonCacheOffsetAttr, > > + firstNullAttr); > > > > + /* We can only fetch as many attributes as the tuple has. */ > > + firstNonCacheOffsetAttr =3D Min(firstNonCacheOffsetAttr, natts); > > > > Based on the logic, it seems the second one could be moved > > to the third position, and the third one could then be safely > > removed? > > Yeah. Well spotted. I've done that in the attached. > > I've also modified the 0006 patch to add a new deform_bench_select() > function which allows the benchmark to call the new selective deform > function. See the attached graphs comparing master to v13-0001-0005 > and master to v13-0001-0006. It's good to see that there's still quite > a large speedup even from the tests that don't have an attcacheoff for > the column being deformed. Tests 1 and 5 do have a attcacheoff for the > column deformed, so they're a good bit faster again. To get the > 0001-0006 results, I used the deform_test_run.sh script from [1] and > modified it to call deform_bench_select() instead of deform_bench(). > > I also noticed that when building with older gcc versions, I was > getting warnings about attlen and 'off' not being initialised. I ended > up switching back to the do/while loops to fix that rather than adding > needless initialisation, which would add overhead. 1 loop is > guaranteed, and the older compiler is not clever enough to work that > out. > > David > > [1] https://postgr.es/m/CAApHDvo1i-ycAcWnK3L7ZASTuM8mW46kvRqMaUHD46HSuJmx= 7A@mail.gmail.com --=20 Regards Junwang Zhao