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 1v3XcH-000Fks-I8 for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Sep 2025 10:29:53 +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 1v3XcF-008es5-JR for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Sep 2025 10:29:52 +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.94.2) (envelope-from ) id 1v3XcF-008erx-A1 for pgsql-hackers@lists.postgresql.org; Tue, 30 Sep 2025 10:29:51 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v3XcD-000sk0-2X for pgsql-hackers@lists.postgresql.org; Tue, 30 Sep 2025 10:29:51 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-371e4858f74so43060631fa.1 for ; Tue, 30 Sep 2025 03:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759228188; x=1759832988; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7WWCa7xSvydoKBRzIMMwsp4+OMNDvuIzua4hV/NoP6w=; b=er37yMr3PAhovwE7DMIpoblVQdFsDJKrDKTYRNbdtAbwQx6jjFrcpHkk0JdDM/cb1V PMSULetax+KieD53sk5R+S9wZUsv43uqOhH9/cbxHh2TFThRQVGuM+NXkDcZ+7PI1nr6 pyPOEikb9d0rfihizwVRvqpLbfBPsGgX2iWuPsq3nm0K0rvYpUtOCM+IfNVWqmne//FO VHzkpG+/t01P9Fjhl6FZDa/vQiIHI9WaQXeogGlHZqG/7NHjWzJygW/boIinZEHfgOzD jl0wOrLqY+owRWO7gUXU59beNNQpo3TGj/Up1+VDY3QNCSOY9saEgLYobJ57131RacUd 3SoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759228188; x=1759832988; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7WWCa7xSvydoKBRzIMMwsp4+OMNDvuIzua4hV/NoP6w=; b=Oy6Wd4qrQJcf2+xX2p/+EwNMPdif+hBHkGRUHaFZM1yNd3rb9mLRyPXSLznGFCaNuW y3LIjbm1a4o+Cq+i74VMNt9qp6EQhcu0zuSchKDyWUiM81CUpIk6SnOUBeirN38RKyLl RVYQ4I6FksXsdnw/PAcZvIyZ7xsnPIDuF/RKJ/gDIQvASHcbuWMQIypBlfJqFCNAFfwe tVUYWV1GMUn+0we10kr2FTJSC+apLh2hacgbcQN6dhuBAETTi2szFiMqNil+RUz2da1u FtHyBDmd5vPEX/vObozwvYxxzGokihpxwLIaSCGtcJNZ6Z2ypqeCmLVlFp1iZyo44uBC l5hw== X-Forwarded-Encrypted: i=1; AJvYcCWDbJp1ntrZpqv638oT/cvJPR9wCtdYhf9XQze/iVgsw/BaswXZlGHCeQIHW16eNxsKI9x+XfVIwrR75fJQ@lists.postgresql.org X-Gm-Message-State: AOJu0YwICy1n5jeW04sETlF8831iWpFUJwZAXTF24R3VJ5/+d+RkrSib okUrRhph6FAIjjyTw79DxLnBCiMztSZT9oqvzEasaKiO0jch1N35Z+mll2JIZ5g1Ki91fp+oeJh Iuw3hn9p5tX73TI1/TDcET1Mu6UiqDlY= X-Gm-Gg: ASbGncsAZzePGBfROxhWgJ/MPODtTTpJ0gCd1qeErhorCrC++NDOF7aWv2Sl+6Xx6tR 4ApHPnFq/ajY+GzRdwcuIISfNne5OEGB82LrSDORcCUyy5+8bh4trM5cih37+JpP2syTTkgBDen /Cuj/PgpN8F4jCswRTf6VvsdcKeot678lqxTdlc6SZ3qujNDEhCe2ATkI1YNNxlYTWbbk+KQ871 gPFWGZeEje8OlI0skKn+HUE6YXpGQzquEnePsPnmlsNUgSRRI4t0MUZ/fGbPUVxAoZfuV3NAZEz J5niXBdFMD+DvvefAMehcol9l07Hi54E X-Google-Smtp-Source: AGHT+IGSyprYVep4AiLKHrNOgfdFSx3spgau/D12BnHDC0qNSiRJ0tOWqqQ5TFqPksgV/DfoESG3FqqbZgKOR30d/cs= X-Received: by 2002:a2e:a902:0:b0:36c:2899:7a33 with SMTP id 38308e7fff4ca-372fa231595mr10712231fa.5.1759228188030; Tue, 30 Sep 2025 03:29:48 -0700 (PDT) MIME-Version: 1.0 References: <48833E2B-C6E4-4C3D-A002-87234AF9782F@greg.burd.me> In-Reply-To: <48833E2B-C6E4-4C3D-A002-87234AF9782F@greg.burd.me> From: David Rowley Date: Tue, 30 Sep 2025 23:29:36 +1300 X-Gm-Features: AS18NWBOaRmRYxq6xZbIWtwn-Uu8wPVzrmC94Oe9MW1F94w2ARKNE2cP6RMA2fA Message-ID: Subject: Re: [PATCH] Add tests for Bitmapset To: Greg Burd Cc: Michael Paquier , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 30 Sept 2025 at 22:30, Greg Burd wrote: > Thank you both, patch attached. Patch looks good to me. Just while reviewing, I was confused at the following code in test_bms_add_range(). /* Check for invalid range */ if (upper < lower) { bms_free(bms); PG_RETURN_NULL(); } That seems wrong. You should just return the input set in that case, not NULL. This results in: postgres=# select test_bms_add_range('(b 1)', 2, 5); -- ok. test_bms_add_range -------------------- (b 1 2 3 4 5) (1 row) postgres=# select test_bms_add_range('(b 1)', 5, 2); -- wrong results test_bms_add_range -------------------- (1 row) I'd expect the last one to return '(b 1)', effectively the input set unmodified. If I remove the code quoted above, I also see something else unexpected: postgres=# select test_bms_add_range('(b)', 5, 2); test_bms_add_range -------------------- <> (1 row) Now, you might blame me for that as I see you've done things like: if (bms_is_empty(bms)) PG_RETURN_NULL(); in other places, but it's not very consistent as I can get the <> in other locations: postgres=# select test_bms_add_members('(b)', '(b)'); test_bms_add_members ---------------------- <> (1 row) It seems to me that you could save some code and all this inconsistency by just making <> the standard way to represent an empty Bitmapset. Or if you really want to keep the SQL NULLs, you could make a helper macro that handles that consistently. For me, I think stripping as much logic out of the test functions as possible is a good way of doing things. I expect you really want to witness the behaviour of bitmapset.c, not some anomaly of test_bitmapset.c. David