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 1wEXjc-0047tK-2m for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Apr 2026 19:23:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEXic-00G2nt-31 for pgsql-hackers@arkaria.postgresql.org; Sun, 19 Apr 2026 19:22:10 +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 1wEXic-00G2nl-0K for pgsql-hackers@lists.postgresql.org; Sun, 19 Apr 2026 19:22:10 +0000 Received: from fhigh-a8-smtp.messagingengine.com ([103.168.172.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wEXiY-0000000211Q-2HWd for pgsql-hackers@lists.postgresql.org; Sun, 19 Apr 2026 19:22:09 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 1FA841400057; Sun, 19 Apr 2026 15:22:03 -0400 (EDT) Received: from phl-imap-14 ([10.202.2.87]) by phl-compute-02.internal (MEProxy); Sun, 19 Apr 2026 15:22:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=burd.me; h=cc:cc :content-transfer-encoding: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=1776626523; x=1776712923; bh=hjBbfNUrHeqsapH69H74lT8I2r4uuWw5i7eT4tokwEY=; b= PTjxyBAIJcLdDqWrnpKYjk/1q4BBbTNUi6IEh4YDPiWw+8FjvCxsYl+Rr5xkHiCn OwHTj8EmATak9c4A0EcgO8G2W1CzEB8YNoQXgLxeA5PiwQ5lNwRdX+H2BO7H2Yal V0Gak+dm35U4lnHJSiadQpsHi7CVh6vryEBaIKI/H75iHb+VK3E9gIzb5kf2ZFix vqpLtrfSrU+3OG7ybLyTzmtdy7w9eP4D2/Ub1tHdBRX5LU9xKuwqf3qpNsjC7mCg noGUoL2UkW3FrvhovAexDzjqffEox0I3F9juohd8yrTEH1UC7PZDK6RE1k+wJHXT XBHWgtG4xtZCDfG3HsbAfA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=1776626523; x= 1776712923; bh=hjBbfNUrHeqsapH69H74lT8I2r4uuWw5i7eT4tokwEY=; b=b 4kB1aU4nYrSkDfA5TogkAz344CdjpDA/UtUmumEuta/LJO0xttPZZDP9/Mpoi3UI cjFBfia64zKzjPGjbbNCKJY4WAkAp7X0rZaa4gvtAUrDWnY4TSIvxeL4JlgCdi+u AIcxVrUV+5rb2wk3XjJ0TI/4mNWKkCLavqACH2B5CeJYGMSUMWgAyI9aNAhbsnVa OP5IsNg1cV+xlx/10V5DkoYUGiuARZXdjsIwWTJ2LX0EEK5CiOKduReA/J0iG+7M dee7wwJnlVMUT1TxJgQqAqgXxPcF6ilhZeIm2juG5hlBtJuw+cs85XeDWRMZai4p P4A5t9y8pZU0Ojbw7dYZQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdehieegiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfirhgvghcu uehurhgufdcuoehgrhgvghessghurhgurdhmvgeqnecuggftrfgrthhtvghrnhepvdeuhf fftddvveeuffetheehfeelveetvdeftdeufeffieejfeduleevfedtffdunecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsegsuhhrug drmhgvpdhnsggprhgtphhtthhopeegpdhmohguvgepshhmthhpohhuthdprhgtphhtthho pegughhrohiflhgvhihmlhesghhmrghilhdrtghomhdprhgtphhtthhopehlihdrvghvrg hnrdgthhgrohesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgv rhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehtghhlse hsshhsrdhpghhhrdhprgdruhhs X-ME-Proxy: Feedback-ID: i675e48f3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 580DCC4006E; Sun, 19 Apr 2026 15:22:02 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: AL8iTvk4FHio Date: Sun, 19 Apr 2026 15:21:41 -0400 From: "Greg Burd" To: "David Rowley" , "Tom Lane" Cc: "Chao Li" , "PostgreSQL Hackers" Message-Id: <77f5109f-6d39-4cf1-8d0d-f826435d6cb6@app.fastmail.com> In-Reply-To: References: <278B9FE3-F349-4494-99C5-483105C1C999@gmail.com> <1900289.1776212948@sss.pgh.pa.us> <1913188.1776220247@sss.pgh.pa.us> Subject: Re: Add bms_offset_members() function for bitshifting Bitmapsets Content-Type: text/plain Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Apr 18, 2026, at 3:49 AM, David Rowley wrote: > On Wed, 15 Apr 2026 at 14:33, David Rowley wrote: >> >> On Wed, 15 Apr 2026 at 14:30, Tom Lane wrote: >> > >> > David Rowley writes: >> > > I'd not considered surprise-prone as an aspect. I understand we have >> > > bms_join and bms_union, which do the same thing if you only care about >> > > the value of the result and not what happens to the inputs. >> > >> > Sure, but bms_join is an optional optimization of the far safer >> > bms_union operation. It bothers me to create the optimized case >> > but not the base case. >> >> Hmm, yeah. That seems like a good argument for making a new set. I'll >> go make it so. > > Patch attached for the version that creates a new set rather than > modifying the input set in-place. > > David Hey David, > Attachments: > * v2-0001-Introduce-bms_offset_members-function.patch I applied, tested, and reviewed these changes. Thanks for doing this, only a few small things jumped out. nit: in bitmapset.c there is a new line added above bms_add_range() + * Arguments: + * arg1: optional random seed, or < 0 to use a random seed. + * arg2: the number of operations to perform. + * arg3: the maximum bitmapset member number to use in the random set. + * arg4: the minimum bitmapset member number to use in the random set. nit: whitespace ahead of arg1, also should be "NULL" not "< 0" in test_bitmapset.sql +-- perform some random test on bms_offset_members() nit: "tests" Also, I think the random testing will likely cover these, but here are a few more explicit tests for odd corner cases. -- shift that shrinks nwords SELECT test_bms_offset_members('(b 64 65 66)', -64); -- drops into word 0 -- shift that drops some low members and keeps others SELECT test_bms_offset_members('(b 0 1 2 10)', -2); -- expect (b 0 8) -- entire set shifts below zero -> empty SELECT test_bms_offset_members('(b 1 2 3)', -10); -- expect empty -- word-aligned positive and negative shifts SELECT test_bms_offset_members('(b 1 2 3)', 64); SELECT test_bms_offset_members('(b 65 66 67)', -64); -- INT_MIN boundary SELECT test_bms_offset_members('(b 1)', -2147483648); I like the functionality and the reduction of repeated code that you've identified and fixed. best. -greg