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 1vkdTz-000QbM-2b for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 07:27:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkdTx-00CTVF-2x for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 07:27:26 +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 1vkdTx-00CTV7-22 for pgsql-hackers@lists.postgresql.org; Tue, 27 Jan 2026 07:27:25 +0000 Received: from mail-dy1-x1335.google.com ([2607:f8b0:4864:20::1335]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vkdTv-002Wgw-17 for pgsql-hackers@lists.postgresql.org; Tue, 27 Jan 2026 07:27:25 +0000 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-2b7381d2d95so2200087eec.0 for ; Mon, 26 Jan 2026 23:27:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769498843; x=1770103643; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qOJ+y9lnu8mUDjc5aogTpsNUmcDnUqZq5kplnXXtYZk=; b=AkwjE7oUSqTo+R3DmPbO6AnzRKKH3UmROB3ycVuEqhpHTOLHuXeYCM4FPkkF4gRGot 8jxGCJSgBhiXdbzX3Ak23C1Jrb56VEmgrEooGwlgQ1y6gBvsMnLkZon/s2xwjKelo9DC xl5Q4NMMSZ9zfBEx1G2bma+mXXO+Jek51CLB9sDb/f//lOFXq8Q34889ebaqQlqeApRW Pt8tNX2rUdzyPNX143pRr0Kv3sdg2qYC9cJ9ZlN26Nqo78vuuaBqyS+Irh/SQzUgG4lz V3r0v4nrtxxj6dE4/pXc0HsnyrkBMlJiY/YBbzJsRJCv3bKMZaWHbkQzHhZcvK+Eed+r arEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769498843; x=1770103643; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qOJ+y9lnu8mUDjc5aogTpsNUmcDnUqZq5kplnXXtYZk=; b=YAkqQ1Yn9ujmvRxBjc0bDI9xyFSOkolD16Bdsv0q9Ge+jda0XH1wOLh947JP1bv0+F NfEwJhYr9o8cMF5hmcx1Ssgp3M6wqUzjts4MMdMC+RF+9vio1dBgNPU66s7OisoOrIA1 OmlbbYosrKWzgZTZel8uzrOb4VuPGHYDbxsRkBF7WYJitoykpvl9NMMBDspKf0dzfBg3 jNpMGz98ULXHaJmsUXTzSRu+A1iOmqWi07AUtJw1lpQvoojEtzMnhoWL7lq+VDb2J1Vj zv8GyjpQlyQ9kr6pM+ctYy3xY/Xf/JiAa6n71Cr+m4klRlYyJV211W/bMcgY1c9FV+0/ pn6Q== X-Forwarded-Encrypted: i=1; AJvYcCV7p793jctAON1SFw7KhM6ZzFNVpGsM4IDdVE8blbAvREtMd5U5bEmFeY8lDOyjHQzbW8zKmeMT55EyIf0Y@lists.postgresql.org X-Gm-Message-State: AOJu0YxVd/8SlSwMi2Lt8k27XnunA+3SS1nEoA0V4DENULEfMVTuV69l KlJMFUKDQVJ6lMwsd65YJBx289e9xu0bSZGOpz7+aruE6q1KDqg2BKIu X-Gm-Gg: AZuq6aLqGkDxRk6iGSMDybq1TAgBvuiAzP2D04meMVYkJjFHioce0Cj+aubkD4iOLgo IRoxeq59QOg1g+arh/5yXtdivnAQfMTfpI/OYOmZz37MmseXL+dQ2piS8xQ6KSEIKkEmhF2QA3h s70+WJZsp/mNV17FPetOgop24yv1YKBHnsMPcMErJ0pZ4I8cbQiYLX4PhRgEfY73ZiTPyNryT4P yo0HEDTh9WmtDedKrmMnZQIRAN9CT2hnWmOa3nvYy/QcSLulRTncQxmFrMP9oEjPegkdSATJv0u iXE+v1q0aNtG65lVhyuVtFHwAAxFON87ShgqvtwFKZVqZmbmYc16yRvfZjooRcFguWyjfH6sAlX Gwd4j0BPpW8nP5IvGwcCgS8bYQkJu/+fiJDAKZkrAiPHRaqu5bHRVTdAgaw6GTU/PfA8wfxLNzS lPA3ed+pa6GXjplfLdvepk X-Received: by 2002:a05:7300:640e:b0:2a4:3593:ccba with SMTP id 5a478bee46e88-2b78e6beba3mr553898eec.1.1769498843110; Mon, 26 Jan 2026 23:27:23 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b73aa2a3c0sm16152045eec.31.2026.01.26.23.27.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Jan 2026 23:27:22 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.300.41.1.7\)) Subject: Re: Safer hash table initialization macro From: Chao Li In-Reply-To: Date: Tue, 27 Jan 2026 15:26:48 +0800 Cc: Bertrand Drouvot , Thomas Munro , pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <2903820E-A053-4FF8-BEB7-DCECFBB6A21A@gmail.com> References: To: Jelte Fennema-Nio X-Mailer: Apple Mail (2.3864.300.41.1.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jan 26, 2026, at 18:50, Jelte Fennema-Nio = wrote: >=20 > On Mon Jan 26, 2026 at 11:26 AM CET, Bertrand Drouvot wrote: >> I can still see it. If I apply from 0001 to 0004 and compile, I see = it. It looks >> like it's fixed in 0005: >=20 > Ugh, you're right. I had ammended that fix to the wrong commit. Fixed > now. > = = Hi Jelte, A solid patch. Looks like 0004 is conflict to master branch = (3fccbd94cba), thus needs a rebase. Anyway, I hard reset the an early = commit and applied the patch set locally. Here are a few comments for 0001 and 0002: 1 - 0001 ``` void +hash_opts_init(HASHCTL *ctl, int *flags, + Size keysize, Size entrysize, bool = string_key, + const HASHOPTS *opts) +{ + MemSet(ctl, 0, sizeof(*ctl)); + ctl->keysize =3D keysize; + ctl->entrysize =3D entrysize; + + *flags =3D HASH_ELEM; + + if (opts !=3D NULL && opts->hash !=3D NULL) + { + /* force_blobs only affects default hash selection, not = custom hash */ + Assert(!opts->force_blobs); + ctl->hash =3D opts->hash; + *flags |=3D HASH_FUNCTION; + } + else if (opts !=3D NULL && opts->force_blobs) + { + *flags |=3D HASH_BLOBS; + } + else + { + *flags |=3D string_key ? HASH_STRINGS : HASH_BLOBS; + } + + if (opts !=3D NULL && opts->match !=3D NULL) + { + ctl->match =3D opts->match; + *flags |=3D HASH_COMPARE; + } ``` This function has a lot of duplicate checks on opts!=3DNULL, I think it = can be simplified as: ``` *flags =3D HASH_ELEM; if (opts =3D=3D NULL) { *flags |=3D string_key ? HASH_STRINGS : HASH_BLOBS; return; } if (opts->hash !=3D NULL) { /* force_blobs only affects default hash selection */ Assert(!opts->force_blobs); ctl->hash =3D opts->hash; *flags |=3D HASH_FUNCTION; } else if (opts->force_blobs) { *flags |=3D HASH_BLOBS; } =E2=80=A6. ``` 2 - 0002 ``` +HASH_SEQ_STATUS +hash_seq_new(HTAB *hashp) +{ + HASH_SEQ_STATUS status; + + hash_seq_init(&status, hashp); + return status; +} ``` Why this function returns a structure by value? Which looks quite = uncommon. Usually, when a function is named with =E2=80=9Cnew=E2=80=9D, = it returns a pointer to a new object. 3 - 0002 foreach_hash feels fragile. It requires to call foreach_hash_term before = break, which is easy to forget. And the documentation doesn=E2=80=99t = mention how to continue, how to return from a loop, and how to goto from = inside a loop. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/