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 1vm11s-006IjB-2O for pgsql-hackers@arkaria.postgresql.org; Sat, 31 Jan 2026 02:48:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vm11o-0074Ni-0c for pgsql-hackers@arkaria.postgresql.org; Sat, 31 Jan 2026 02:48:05 +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.96) (envelope-from ) id 1vm11n-0074NU-2W for pgsql-hackers@lists.postgresql.org; Sat, 31 Jan 2026 02:48:04 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vm11m-00000000I1v-1DyA for pgsql-hackers@lists.postgresql.org; Sat, 31 Jan 2026 02:48:04 +0000 Received: by mail-qt1-x843.google.com with SMTP id d75a77b69052e-503bf474fdfso23796891cf.1 for ; Fri, 30 Jan 2026 18:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769827681; cv=none; d=google.com; s=arc-20240605; b=jIVDt94upjqkAIxh/tG8Qb76y6RikS463AVrmqL9hfFDIJsZAKpus1eBQQkGS3Am1o 8tWKpDlJ4HuT76z1cwhBuMg73aFINTHsxJN5d+w+jYEifk3cW6O4GPr8aQKSOwEeTLX8 LW9f+r6fWMKXSPlCbb0XCCch6sCD7MaN6SgVv3Gya6AMxh+FS+g2LQ0Sf73a89SinLPm eUfZtDD1EhTRZ2yUcoCwjmXzG6pQrLbYgqgThgWOA/EuDcJxUzDiOQdzGu7ip2/WqA2n Vr3FcI4MVLEOKhj9XFShAA0fSZNddx3J9oV/CirlMn7mEXPxtJmIjfM4TmS+dyDGPlJd x0SA== 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=4vI/vw7tFVSo8GxKyRDqFIOWq6zZ+J2MqKUANWuX3dQ=; fh=mxtOOka1brfUN9tTsQaV7IYa4vOgoDUXoSylHJF6Vfk=; b=GDkzXZvVoxcECi5mDpoulDVuTphLNbGqNQuGtjULzI3ILw18HowrvzXDpJWW6QL4fF JWPI1IUb3blb4GAugWFObBkfhVz0t9U2jOHQk2KLbHWNTN1yuX0I0QxlWQFbwjgJsEn0 ni0ag5mgrR2DUakR/QdOINmbwBZo+pcIGMyUuMiG8kef71nBSrtY5XHVG5Db0vpmku5Z +pP5hSOW7PQ35P7ZrmHf2bQsSujkFM1mS75Z8V79PNP7817eUCqE7KWR45VbAEUHoUER eqiTFo9q8qKB2MaTRWjEncEcBiJi7ck0n63LyIbGnavtJuHp0i0RzjwiH8VwBBRJ9y2m kZ/w==; 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=1769827681; x=1770432481; 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=4vI/vw7tFVSo8GxKyRDqFIOWq6zZ+J2MqKUANWuX3dQ=; b=cqu7W3V3f0OLhv+jfjFl42P3fnQ+8ZPOZRc5m7Zvzg6b1w1Z5pfquKXZtTx7tTdMZy zoas9furuQ2louzzU3ZsJU9pLonoC4IYwSV0pqITcVF4Kwi4uh6+pYUWi2I2cm8QVtlz 4FjjPrhboIn9KZ7mRbTMSvpAOKsFltcNNOSdP/UXG21j6wBdIeBPBlTLM4A4TM9Wt2aW WQplrKnPNEQEiZ4ulRe9Y/wNs6E1nlyXZyylDYiPrHRuPsSXQXatgZCXDv/yatGEFXh5 vhuv3240DlN2HLj2rlV6vNm5BK47hIDo7Hsu8oCSmH9Fu3ayNH0HavmA7t8w3fr1ydI4 CO2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769827681; x=1770432481; 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=4vI/vw7tFVSo8GxKyRDqFIOWq6zZ+J2MqKUANWuX3dQ=; b=pkNu59+VLpSAH6E+yfXPaQVP4+Zb+gtXHj8Pl5SarK66GtgormRcPS062KLXWLCNL4 OdZL8cRHZU+Ww8nq67S3Sh3mbMHEnoaHLxW3bWYsyNWtfj+9Os7uG/TAPpkAJ47l2CmX /9b9HnwjiOGkfQQ9qdxRAeBHO1R2O0IQmlg+ekquKDhaAS9BDF8QXSA6qvu0LWq778UP ikN1a5SdtuOxoJEYwrWYIiTlRTe/W3MuMlDkzdvjM0+g9YJgX1V1Ngc9qJeE3Tq5n7Eo OgAjAdZ6z5iFP87krMjIixOXwvg0rnfhSopjn6EVQ5p8tRVB7mgvAT2FNW/rENWHGQQq ajaw== X-Forwarded-Encrypted: i=1; AJvYcCXHbA/abpZ8oFOC0I/Ob1PjNX+YK41IF2lxY01S9x2XR++jU8OGLukTvgDdrBD8k8TEqhWZ8iFQjoeHFuOL@lists.postgresql.org X-Gm-Message-State: AOJu0YxQ01rb4hYa32L0ri8H4wFcv8DFEtownoSlCn/WXc3XIdEe3Ru+ nDlfkN+0Gqyf803hjnbjJ7QKIeplUG224knG8pxV1HTEIW43sVfNd+zLtVN0uLvFhi7cfDehhWP q4iplyS7J5+nYmUzTC8EkmKO8DGa/zCk= X-Gm-Gg: AZuq6aJDKr3helsLuB6Jitb82imP/wwm1TSA6MD3HvemzM6HNDqjeM7BjUGb7Nh/f9P J1D3uejkO9GQUdgeY7E9eYVVh6udZZEySvzj29oky0S2XeiOKZTEoM06dIzqbZOqOe2kLtOGRIN mh/X4of0ANkUfEx6rYJoBaFXzR21HLjUcZyMpMZfmUq1qSr9SSRs3Yl1IdikKBeyIgfRSRKST/v jL7J8KRVEpzjQEn82NIrh0spNNd3hbgN5jry/zSt4AB3FPN0vFMqFoGHDKRIAIg4RE3I6XRaQXf jrwGmBZbtRUnQL9qEvARWHRu8bv2Of543lrRNT/p/B0hyIbEWFRuF7/YgzFNsGbUEWh1+hrJt6/ NrR9D984YV8MNlfA= X-Received: by 2002:a05:622a:64c:b0:4ed:6e70:1ac4 with SMTP id d75a77b69052e-505d226dbcbmr65295731cf.42.1769827681010; Fri, 30 Jan 2026 18:48:01 -0800 (PST) MIME-Version: 1.0 References: <9A17C43D-7A28-4885-8974-555A40C9523E@gmail.com> In-Reply-To: From: John Naylor Date: Sat, 31 Jan 2026 09:47:49 +0700 X-Gm-Features: AZwV_QiQOPfDk2g2lNHaWwcslPOPKeUq4W9ppX2G07KH5uprujwU-x0A925zrI8 Message-ID: Subject: Re: More speedups for tuple deformation To: David Rowley Cc: Andres Freund , 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 Tue, Jan 27, 2026 at 8:34=E2=80=AFPM David Rowley = wrote: > I've also included a slightly revised patch. I made a small change to > the first_null_attr() to get rid of the masking of higher attnums and > also now making use of __builtin_ctz to find the first NULL attnum in > the byte. For compilers that don't support that, I've included a > pg_rightmost_*zero*_pos table. I didn't want to use the pg_bitutils > table for the rightmost *one* pos as it meant having to special-case > what happens when using index 255, as that would return 0, and I want > 8. I'll make the MSVC version use _BitScanForward() in the next patch. I don't get why we'd need to special-case 255 in only one place. + /* Process all bytes up to just before the byte for the natts index */ + for (bytenum =3D 0; bytenum < lastByte; bytenum++) + { + /* break if there's any NULL attrs (a 0 bit) */ + if (bits[bytenum] !=3D 0xFF) + break; + } + + res =3D bytenum << 3; + +#ifdef HAVE__BUILTIN_CTZ + res +=3D __builtin_ctz(~bits[bytenum]); +#else + res +=3D pg_rightmost_zero_pos[bits[bytenum]]; +#endif If bits[bytenum] is 255, then __builtin_ctz(0) is undefined. The top of the function says + * We expect that 'bits' contains at least one 0 bit somewhere in the mask= , + * not necessarily < natts. ...in which case it should be well defined everywhere. Am I missing something? If we need to handle the 255 case, this should work: pg_rightmost_one_pos32(~((uint32) bits[bytenum])) -- John Naylor Amazon Web Services