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 1vfxBG-006PE0-1V for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 09:28:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vfxBD-009JcV-36 for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 09:28:44 +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 1vfxBD-009JcL-1y for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 09:28:43 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vfxBA-000Ofs-1b for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 09:28:43 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-47edd6111b4so12505065e9.1 for ; Wed, 14 Jan 2026 01:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768382919; x=1768987719; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0wtMPsCEgDAp7tNwfDYW3+eGhQat/1VTmLpeZoLzxx0=; b=fWSLnWFb5cmxHI/ZLmRcYERcfhhZHVVqt64bew6/3WUx1o0PY047C1rsaDR5+nd69G J3l4u38G4RMk8i7Kmvx65SLIQXS/x3YS7aN2SEKi0Se/IMNTyBEMPCUdn3pEbv8OKU0U kH4e9TdRKLWU0dAxNolJ4OqoScbLtHT6A1aE84i6VkfqWjVa9GBWjNWYWSBicq1TyGiA gb6lo6kFyjBUGKB30Y8ti+R7UwRaTWKguIyg9I+ALHxOut4UT4h+A8iNQtpAi8HFMZm3 wjCT3JJbAiO+oS7RscmfUxbEg+x7uwcTKYJ/25gZTWNIui5gWoY7XwVPUbmfk++xX4Xu Gx7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768382919; x=1768987719; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0wtMPsCEgDAp7tNwfDYW3+eGhQat/1VTmLpeZoLzxx0=; b=SzELfkzlgfZ1IBJck8wdOcLDLQVmER+NycCRgr9rLAsNj6Ty5D+/OdS7CTZdIaLua2 1DMkviu52AeIvQ/D5CG3vfGUuyR0aqHV4tJcjv/dIDTDTVAoIs4y5ReijxxfcgLDrtNP A5YEFylr5kKPiDSRPmUDDoFbzkf3geeGX9Se94B+9kmf63RBbdLuUBXh7QXl1ncNJTSl MNMZTzs6y2JIXDfTkrL8XhF/BTZq/FqsD+kphGhNHWHZBXB9twdPqer81W8rcl9QmJtr Bg0+r+Ga1/TYvHt9QKJpWYYlRPcSsaG5d5umZiEgW83wE6Fv767KHwbIeqWJ/vVuzKRK zSLQ== X-Forwarded-Encrypted: i=1; AJvYcCU+Bp5Pd28uwIzswzr8N5jrHt9wrG5v3IFcyEA+37Zg43pDCHRwz0BSZgbEWBR1NWsDsbY9h8Lb/BZ2N+zh@lists.postgresql.org X-Gm-Message-State: AOJu0YyPi0v6Z1Z1x4xQ7D4CVtUDeCcWg12xDuuL1KW4coGJpYWGqF5W Y80rTXdyU/85sdYiaf/pcJdoQBMaF1o00BzBG6qrOzC6Jix4ywcf2A40 X-Gm-Gg: AY/fxX4cJS6pyhkruXce2twMuSptqZz0aKg/bL/JslmHUDIdxr+idtAwTKJ+EU5Vikw 5GJuC9H4TGIk3QOz5CluxtRhODXC457kEYWgYYI5CcQDwoNROa2U113aTIMvwKINmkGpvhJsDxe XSCQ74HjRWBfOG0LPtakIqKxj3FUxWVfsF6ZSpfmKBGGWXDYTa+Bff97yPVStOGKipZdNDmxdn7 HoI7C9oA6ElShIpg1F+OLKRnvrGpuwfLHL9YreTs8AZKvurVIVHka6yK6+HCUkmNKQ/SR2MgDp+ v+yi9KXLCfv1MUKF2MxXUfSPEvXOnRBhMCLZdPUtYw9z8V2/fYu8/QDnlWKg9Pc+UyoqdlW8MX4 lwXRXe+fvgyujWnuTz/RpNO70gpg3rAunVeoHAJqs7rxEb6u9RT8VkYcF2dWwGGrvN1qEHfQFr7 4tgG6cAlkLdX540zMzv9xeH7VC78ejA3eVd+UtuvXIvgHOqngZ8tJNCMOLQqOONsT+VTiL78aXD HlvTSH5H9VNUOSnn6iPJXFDYHICasi0i8PE+YB7yeX/mA== X-Received: by 2002:a05:600c:c4a6:b0:47d:3690:7490 with SMTP id 5b1f17b1804b1-47ee47c8db0mr16059125e9.9.1768382918931; Wed, 14 Jan 2026 01:28:38 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432bd0e180csm47638620f8f.10.2026.01.14.01.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 01:28:38 -0800 (PST) Date: Wed, 14 Jan 2026 09:28:37 +0000 From: Bertrand Drouvot To: Jelte Fennema-Nio Cc: Thomas Munro , pgsql-hackers@lists.postgresql.org Subject: Re: Safer hash table initialization macro Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Jan 14, 2026 at 09:46:41AM +0100, Jelte Fennema-Nio wrote: > On Wed, 14 Jan 2026 at 08:57, Bertrand Drouvot wrote: > > + * WARNING: If you use char[N] to store binary data that is not null-terminated, > > + * the automatic detection will incorrectly treat it as a string and use string > > + * comparison. In such cases, use hash_make_ext() with .force_blobs = true to > > + * override the automatic detection > > > > maybe s/is not null-terminated/may contain null bytes/? > > Changed wording and changed to NOTE. Thanks, looks good. > So if we don't have the foreach_hash_with_hash_value macro treat 0 > special, then we'd need to replace this single while with two for > foreach loops. A foreach_hash for the 0 case and a > foreach_hash_with_hash_value for the non-zero one. Okay, let's forget about introducing foreach_hash_with_hash_value() then. > > -static void > > -cfunc_hashtable_init(void) > > -{ > > - /* don't allow double-initialization */ > > - Assert(cfunc_hashtable == NULL); > > > > Most of the hash_make_fn_cxt() callers check that the destination is already > > NULL so that removing the Assert() is not that worrying for them. There are 2 > > places where it's not the case: InitializeAttoptCache() and build_guc_variables() > > , should we add an Assert (or an if check) in them? I think that an Assert is > > more appropriate for those 2. > > I'm a bit confused about this comment. I didn't change anything for > those two places about their checks for NULL. Did you mean this as a > separate but related improvement to existing code? Agree that you didn't change for NULL check in those places. I meant that 0003 introduced calling hash_make_fn_cxt() in InitializeAttoptCache() and build_guc_variables(), which made me think if we could add an Assert while at it. > (To be clear, the removed Assert that you quoted doesn't matter when > inlining, because it's the only item in an if (!cfunc_hashtable) block) Right, the removed Assert is fine. > > As long as the new macro definitions get in, any way a committer thinks > that's sensible is fine by me. e.g. The List foreach macros also haven't > been replaced in bulk, but I'm still very happy that I can use them for > new code. +1 Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com