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.94.2) (envelope-from ) id 1v3juy-002l9j-4u for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Sep 2025 23:38:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v3juv-00DVfR-RL for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Sep 2025 23:37:58 +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.94.2) (envelope-from ) id 1v3juv-00DVfG-Cr for pgsql-hackers@lists.postgresql.org; Tue, 30 Sep 2025 23:37:58 +0000 Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1v3jut-000m95-0n for pgsql-hackers@lists.postgresql.org; Tue, 30 Sep 2025 23:37:57 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 3CDF314000D3; Tue, 30 Sep 2025 19:37:55 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 30 Sep 2025 19:37:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1759275475; x=1759361875; bh=wXc0rETr/J Pid8ex0PK+mTZmQ7YiMduk3Sop6VVgNF4=; b=ol8qSnGTjQqf4GAqGw/J8tMJrI jx2pwewLdVgF7hEIgpzNOOLiLHChGtHBsDf+nD4T1y8icbbso3SDgWFdYoEbBoFr RQV6L6l4NcHBUYTSdIkPube0VqEqxZYQefOqQ2O7boXYuMz/8ViCEky3vDLz2LNz S9iDbjuOUPye1IB975AftLmUiDJjNC+NGD0chgJvo7Kw/RcDDAyJdccnquZRydop JThLvSLJjZ4IP4LA0irhoA0EV9d0jliJ21R7+0lXram1p9+jxaMYYdwAxahgriVj Oh1qHY9AS81d+tK8JgxnRV7Orm8gkNlTs2uPIWtbEZYkLKLa6s1Gu7G/prag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1759275475; x=1759361875; bh=wXc0rETr/JPid8ex0PK+mTZmQ7YiMduk3So p6VVgNF4=; b=urNz37xZ9h/yte/i3kVVCKTQwKTOicZMabBQiOenJQmuNjL72jv oWdUZNJYAAZVq8OOc0Yq32wBMY4/bWktphkD9cwf9MkYQdaryui6lPs+T2C2MRZ+ XMBl4rrG7L8OBxAPlPXIDUkW6/gn9mspgOBCKFa1OuvYls8+vmPoAjZqCjlZ5OMu p46qEqHsElxq5K9y1y5YfzdIZthf4Ajb9XcSGNiNoi7UTuNMY+wrC1wUfzS7E4aK ED1UBz0vzEUnecw56xNel+H0XSybjKIF11oaH4r1sQa6wNLnxiWz3dZ/pkFI2z65 Io5KSSeU2xpnC5SZuZCV99dCy0RAWdcEw3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdekudejjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlh cuvffnffculdefhedmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvden ucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprghquh hivghrrdighiiiqeenucggtffrrghtthgvrhhnpeegffejvefgveduvdejtddvtdeijeeh udeuledvudeftdfgfeejvdekveekiedvvdenucffohhmrghinhepphhoshhtghhrvghsqh hlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidpnhgspghrtghpthhtohepfedpmh houggvpehsmhhtphhouhhtpdhrtghpthhtohepughgrhhofihlvgihmhhlsehgmhgrihhl rdgtohhmpdhrtghpthhtohepghhrvghgsegsuhhrugdrmhgvpdhrtghpthhtohepphhgsh hqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Sep 2025 19:37:53 -0400 (EDT) Date: Wed, 1 Oct 2025 08:37:40 +0900 From: Michael Paquier To: David Rowley Cc: Greg Burd , PostgreSQL Hackers Subject: Re: [PATCH] Add tests for Bitmapset Message-ID: References: <76DBEF5D-EA47-4C30-8D28-97B3B88E2E2D@greg.burd.me> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="FbyGySStWCa4TVzg" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --FbyGySStWCa4TVzg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Oct 01, 2025 at 12:00:39PM +1300, David Rowley wrote: > 1. Added helper macros PG_ARG_GETBITMAPSET() and > PG_RETURN_BITMAPSET_AS_TEXT(). These themselves save a few hundred > lines of code and make the functions easier to read. +#define PG_RETURN_BITMAPSET_AS_TEXT(bms) \ + do { \ + text *result = BITMAPSET_TO_TEXT(bms); \ + bms_free(bms); \ + PG_RETURN_TEXT_P(result); \ + } while (0); This is also something I've considered as embedding in a macro, and discarded it. The reason was code readability, because it gives to the reader a quick knowledge of what can be freed once a call to a specific bitmapset.c routine is done, acting as a kind of reference template. Here, the free call knowledge gets hidden. test_bms_copy() becomes more confusing to me. This argument comes down to one's taste and philosophy on the matter of test modules. These are for me tools of coverage, but also can work as reference templates when calling an internal routine because we also document some of its implied behaviors, like the inputs recycled. > 2. Standardised that the test function returns NULL when it receives > invalid input. e.g if we aim to pass an "int" to the underlying > Bitmapset function, if someone calls the test function with an SQL > NULL, just return NULL rather than trying to come up with some logic > on what we should do about that. +static const char *emptyset = "(b)"; Not sure that I'm on board with hardcoding this knowledge in the test module. But well, if you feel strongly about it, I'm not going to put a fight for it. > 3. I couldn't quite understand the extra parameter to > test_bms_get_singleton_member() so I ended up removing it and making > the test function return -1 when the set isn't a singleton. I didn't > search for discussion about that so I might have missed the specific > reason it was done that way. It is not very far. In short, I am caring about the status returned by bms_get_singleton_member(), then translated in the output of the SQL function based on the default given in input: https://www.postgresql.org/message-id/aNolInqSzt1d1338@paquier.xyz Perhaps not the most elegant solution, but simpler than returning a setof without changing the meaning of the tests. So we could return the status directly or use the default value from the input, not doing any of these actions reduces what's reported back at SQL level. > 4. Wrote some comments to try to communicate the standards defined. > This aims to offer guidance to callers of these functions and anyone > hacking on the module itself in the future. +/* Helper macro to fetch Text parameters as Bitmapsets. SQL-NULL means empty set */ +#define PG_ARG_GETBITMAPSET(n) \ + (PG_ARGISNULL(n) ? NULL : TEXT_TO_BITMAPSET(PG_GETARG_TEXT_PP(n))) True that embedding the PG_ARGISNULL() call may be better in a macro, as passing NULL values to the internal routines is OK. > I also wonder how worthwhile it is to try to free the Bitmapsets. I'd > have expected these allocations to be in a pretty short-lived memory > context. I count 44 calls to bms_free(). I've wondered about that as well. However, I have concluded to leave the free calls arounds, for the memory context argument if someone plays more with this module. I don't mind the removal of the NULL checks when calling bms_free() to cut lines in the module, though. I was also seeing an argument with cross-checking the frees after a REALLOCATE_BITMAPSETS copy, as well, for sanity checks. So I would rather leave them as they are, not remove them. Again, that may come up to one's view on the matter and one's philosophy around these modules. -- Michael --FbyGySStWCa4TVzg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmjcacQACgkQnvQgOdby QH0m6hAApls7rbgSnHUmOHbWsDuZCq+h4vivIlYZzIlnDd/8gP0btyITootRrmGm uk9p1AAQDppjKYgokk4JZvmqRNfG3n1QRw8HcpvKF4nmIut8Gcy6AqeYHs1GbcIz 9ehaMRoYHNDr7mbJRTwpaZbCDj+bMJgo1jDHW5wX9R8ugcQkVNrAYJgF4CFyexQv Tde8qa5wUB7+QqF84mt+9yq7Aho8YC4blFQv5gv0PVk4rW4NEa3kyOIY27oiET/g muOZEy4o4I4XAn7kdOzC1AdKt7gBXPU5TF9FtyWTDJl9dhNlBWYGCJQdeyNzzuXB HAowoOIyNdW41boZwYPsZ+g3Rojn4O6DX3/fzDliaE+Tao+XRWtbnfWuSO+zBjwi KQ68gbxpeqvD2uoLvD+Wbxde8wejvZr2KMN41f/ZGDu0GLuJkp699dnJEaLRQ+o9 fAoS7Gjma7v/m0T4aiwXVqfcA+JtzsYRXZYnUVmal94CVqwvtlZA+2CPsgEjYa/v /tOXR9PXuYZlpr5CuLc5kD1YFe8p5BU24k5SmfzVWZnmIptvjbYFKbdzish7vj2n UQF/cioXw+2fWF5rQAA0nH0ccP/jpFBeESzeeRbei9ujiCpAmCFuZC70C2oYIxvw u5M5M2T1A1WIxzDDwIEzirDpTt+e+4JcrlqUyWpGKZEGknoc9wM= =5kkY -----END PGP SIGNATURE----- --FbyGySStWCa4TVzg--