Re: Strange Bitmapset manipulation in DiscreteKnapsack()

David Rowley <dgrowleyml@gmail.com>

From: David Rowley <dgrowleyml@gmail.com>
To: Richard Guo <guofenglinux@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2024-01-18T21:46:51Z
Lists: pgsql-hackers
On Thu, 18 Jan 2024 at 16:24, David Rowley <dgrowleyml@gmail.com> wrote:
> On Thu, 18 Jan 2024 at 15:22, Richard Guo <guofenglinux@gmail.com> wrote:
> > Do you think we can use 'memcpy(a, b, BITMAPSET_SIZE(b->nwords))'
> > directly in the new bms_replace_members() instead of copying the
> > bitmapwords one by one, like:
> >
> > -   i = 0;
> > -   do
> > -   {
> > -       a->words[i] = b->words[i];
> > -   } while (++i < b->nwords);
> > -
> > -   a->nwords = b->nwords;
> > +   memcpy(a, b, BITMAPSET_SIZE(b->nwords));
> >
> > But I'm not sure if this is an improvement or not.
>
> I considered this earlier but felt it was going against the method
> used in other places in the file. However, on relooking I do see
> bms_copy() does a memcpy().

I feel it's not worth debating the memcpy thing any further, so I've
pushed the v2 patch.

Thanks for reviewing.

David



Commits

  1. Fix broken Bitmapset optimization in DiscreteKnapsack()

  2. Require empty Bitmapsets to be represented as NULL.