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 1vfYoA-002pbP-2n for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jan 2026 07:27:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vfYo8-003NaQ-2T for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jan 2026 07:27:16 +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 1vfYo8-003NaH-1W for pgsql-hackers@lists.postgresql.org; Tue, 13 Jan 2026 07:27:16 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vfYo6-0009zS-0o for pgsql-hackers@lists.postgresql.org; Tue, 13 Jan 2026 07:27:15 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-47796a837c7so49100575e9.0 for ; Mon, 12 Jan 2026 23:27:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768289233; x=1768894033; 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=thcdKOq7IYnAPdrWJJurjay1X7+tjvq1llfsXYQEhH4=; b=lPnm9tx9Q9dJMzesg7KQABCkoW49va/MtgCJHifVfjMorHeHb4vpEeBnaNjvcx9XML tGI+eMbFixpnj4Gt0YEwUn4XPQan/yNgMfSdRToHQ8VW0dxoau8YCbCp6stLJnj6EMrp 5GhCEC5grBK1kn9qtCEtd3rAJ/CIAMxjeuGkmy9WUlEuYT/Emj/6NoxOFV3ghlp8BbnG CEtLgWWikmKPK4JWKCAEcm9f1cInO3svie3xcUWYC1M/0QovoyoA6W73D9/475BCuKQ7 B7lcv83JG+MGJQC/y50Aa+mDpacyIIQWO8cBEj5TNGGCytWW6JmNXT94yNI0waYaL9DO A7og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768289233; x=1768894033; 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=thcdKOq7IYnAPdrWJJurjay1X7+tjvq1llfsXYQEhH4=; b=YFMIe2H6pMYSBAKZg2/Jf0W8o1P05k20dRfG29U9aK50mPR+TXkwpZo6vO/JZ+MlBJ I4Oy/ozNhkYBVOtMtbQj4vaPYpmlXEf0bhpgZGKAO/eEZcvmkP9AitLHMLn7XJbDeUvg dhhSRyP6HVksluhJZjNqQnSPDUzhwQAXtOOGZ1c0I39glpnaQQBS/AWiVp9Qnx5WP/nD FeUdnc36ehwcmAS3UpVcw9ORNA/oaqA7tqrHayDDzzhVv2+tcImT2K3AkHZJ1xYKFFnj BUKSDYYufN8A0tRAAfRFkMCVa2gMWbFyhLEWTtU26Lp/p/w1W1qf2XpCF/Ho2LwIf2U3 IA2Q== X-Forwarded-Encrypted: i=1; AJvYcCUbEzYnqetEPLpuW7Mm6Ko7BVJ1+HXyXj0ofBx8RLwC1zvEhEEbGn2UvLTxmORahefOG+nkeY/cqctPe0vb@lists.postgresql.org X-Gm-Message-State: AOJu0YxnP228321T2DfuSgbIqQZhS3g+WKOMYAiJYnXX2IjuDhCT/O6W 8rblA4kPCyuSOkcwaOnH2FNB/gv8tl5oZ9VDa6aWrT8nqmjJP4tvvoCp X-Gm-Gg: AY/fxX7Q1JtgmM5yOFV4sgfGi5LxIFgqcr1O/cD0FPFUHQNiAq8/vAe0UTubGqbGDaS 7TLb0z2psD67PaqveTUao53MnAxAiyy1YElXx0F7bxgHqI9yfHkUyyee5z7IU2J36vmMNhkqveV N3tXnD9aP3PWJgIbnLLjd/Qn2LbycTns8P5JMcBJc/o6uhvOvNr1i2Kxeea4PmdsOmvLyBq2VJO jmsAm0ymi3TmSpphpNRhS7QdSarwdrtpEg9cxA+5v/49e64IkgaCFSKiTgwgeK0p7OWpcD4yRhA vUDnHzEZDZTwz3ARm+tDtYwF4gx/R6c8cZPi2D1BY6+Iwb7mP6acZICf+xhlBnqTCJZXqooR0oa RN1eCSP4z4ylDyO+c1q1K/ZF/c7rfcCP0Izc+MvUPXjV/lN7AGFpt+4aUQ1YFnB3qg1bnBgzhoA ldHAr6H+MKuy/e37bmhpTohefv3C/szIKiPhP/UWKb1Fkqi5zFfS4SlrlKaavKrJ+xkPLI2ZABF 25QIqJr70j+DI9y6RYyqmoujcJbPFT/u6g+WA2MWjsCgERhMXiIClOT X-Google-Smtp-Source: AGHT+IFT7KbV+zBoo1hgCI+QgKrb+BNZj/ZUIJETquRLF0+NuZ904XIDshQhvp64DRUyMPDi/RXTeg== X-Received: by 2002:a05:600c:8b0a:b0:47d:264e:b435 with SMTP id 5b1f17b1804b1-47d84b54c62mr232919255e9.22.1768289233229; Mon, 12 Jan 2026 23:27:13 -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 5b1f17b1804b1-47d7f653cd6sm411169915e9.9.2026.01.12.23.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 23:27:12 -0800 (PST) Date: Tue, 13 Jan 2026 07:27:11 +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 Sat, Jan 10, 2026 at 12:32:39PM +0100, Jelte Fennema-Nio wrote: > On Tue Dec 9, 2025 at 8:27 AM CET, Bertrand Drouvot wrote: > > Thanks for this patch series! > > v4 attached, which fixes some rebase conflicts. Also I moved the patches > that start using the new API to the end of the series, so the > introduction of the new APIs is now done in the first two patches. Thanks for the new version! A few random comments: === 1 +#define HASH_PTR_AS_STRING(ptr, size) \ + (pg_expr_has_type_p((ptr), char(*)[size]) || pg_expr_has_type_p((ptr), NameData *)) +#define HASH_KEY_AS_STRING(entrytype, keymember) \ + HASH_PTR_AS_STRING(&((entrytype *)0)->keymember, \ + sizeof(((entrytype *)0)->keymember)) +#define HASH_TYPE_AS_STRING(type) \ + HASH_PTR_AS_STRING(pg_nullptr_of(type), sizeof(type)) I've probably a too paranoid concern: what if someone use char[N] to store binary stuff with embedded null? That would detect it as string and then make use of strncmp() and then would provide incorrect result. While the risk is probably very low, I think it is there. What about using: hash_make_str() hash_make_blob() or force a flag: hash_make(..., HASH_STRINGS) hash_make(..., HASH_BLOBS) instead? That breaks some of the patch's intend, so I'm not sure it's worth it given the low probability risk... === 2 The patch introduces foreach_hash() but the foreach_hash_with_hash_value() counterpart seems missing. It could be used in TypeCacheTypCallback() and InvalidateAttoptCacheCallback(). I think that we could add it or make the new hash_seq_new() accept an extra hashvalue parameter? (when set to 0 would call hash_seq_init() and hash_seq_init_with_hash_value() otherwise? Some minor comments: === 3 +extern "C++" { should be "+extern "C++" +{" as per pgindent. === 4 +#define pg_nullptr_of(type) ((type *)NULL) s/(type *)NULL/(type *) NULL/ ? (and in the comment in top of it) === 5 +#define foreach_hash(type, var, htab) \ + for (type *var = 0, *var##__outerloop = (type *) 1; \ s/type *var = 0/type *var = NULL/? (see ec782f56b0c) === 6 + * serialized++ = *value; s/* serialized/*serialized Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com