Thread

Commits

  1. Simplify SortSupport for the macaddr data type

  1. [PATCH] Simplify SortSupport implementation for macaddr

    Aleksander Alekseev <aleksander@tigerdata.com> — 2026-02-25T13:05:46Z

    Hi,
    
    Since Datums are 64-bit values and MAC addresses have only 6 bytes,
    the abbreviated key contains the entire MAC address and is
    authoritative, as pointed out by John Naylor [1]
    
    This fact eliminates the need for cardinality estimation using
    HyperLogLog since macaddr_abbrev_convert() is dirt cheap and not
    lossy. There are no reasons to give up on abbreviation.
    
    Potentially we could go even further and pass MAC addresses by value
    rather by reference [2]. This would eliminate the need of abbreviation
    completely since SortSupport->comparator could just compare two
    Datums, as we do for Timestamps. This is a more invasive change though
    that deserves more discussion and thus not proposed here.
    
    [1]: https://postgr.es/m/CANWCAZYWdOEnoL_88VpMge1RtRpBz-VRCjdcu-eA4q3U6LvpDw%40mail.gmail.com
    [2]: https://postgre.es/m/CAJ7c6TM8up%3DYih8pRLPy4wHwLzHf7w22tQ80-8ZBm__E%3D8_5HA%40mail.gmail.com
    
    -- 
    Best regards,
    Aleksander Alekseev
    
  2. Re: [PATCH] Simplify SortSupport implementation for macaddr

    x4mmm@yandex-team.ru — 2026-03-05T18:02:45Z

    
    > On 25 Feb 2026, at 18:05, Aleksander Alekseev <aleksander@tigerdata.com> wrote:
    > 
    > <v1-0001-Simplify-SortSupport-implementation-for-macaddr.patch>
    
    The patch looks correct and useful to me.
    
    Two small points:
    
    1. The assignment ssup->ssup_extra = NULL can be removed. The
       SortSupport struct is zeroed before the callback is called (see
       sortsupport.h). There are about 22 similar assignments elsewhere;
       it does not seem to be established practice, many other places have
       no such assignment.
    
    2. I checked whether the existing tests actually use the SortSupport
       path. If macaddr_abbrev_abort() is made to error out, the macaddr.sql
       tests fail in two places: once for the index and once for the SELECT.
       So the current test file does exercise the SortSupport code path. I
       also tried making macaddr_abbrev_abort() always return true (so
       abbreviation is always aborted); the test dataset is small, but
       sorting seem to produce correct results.
    
    The patch looks good to me.
    
    
    Best regards, Andrey Borodin.
    
    
    
  3. Re: [PATCH] Simplify SortSupport implementation for macaddr

    Aleksander Alekseev <aleksander@tigerdata.com> — 2026-03-09T13:08:06Z

    Hi Andrey,
    
    Many thanks for your feedback!
    
    > 1. The assignment ssup->ssup_extra = NULL can be removed. The
    >    SortSupport struct is zeroed before the callback is called (see
    >    sortsupport.h). There are about 22 similar assignments elsewhere;
    >    it does not seem to be established practice, many other places have
    >    no such assignment.
    
    Agree. I removed this assignment in 0001 and added 0002 that removes
    if for the rest of *_sortsupport() functions.
    
    -- 
    Best regards,
    Aleksander Alekseev
    
  4. Re: [PATCH] Simplify SortSupport implementation for macaddr

    Michael Paquier <michael@paquier.xyz> — 2026-03-25T08:00:04Z

    On Mon, Mar 09, 2026 at 04:08:06PM +0300, Aleksander Alekseev wrote:
    >> 1. The assignment ssup->ssup_extra = NULL can be removed. The
    >>    SortSupport struct is zeroed before the callback is called (see
    >>    sortsupport.h). There are about 22 similar assignments elsewhere;
    >>    it does not seem to be established practice, many other places have
    >>    no such assignment.
    > 
    > Agree. I removed this assignment in 0001 and added 0002 that removes
    > if for the rest of *_sortsupport() functions.
    
    Sounds sensible to get rid of the estimation with the Datum size
    requirement and never give up with the abbreviated key sort, as done
    in 0001.  I'd leave the code touched by 0002 remain as-is.
    
    @Tom, why didn't you consider that as a continuation of 6aebedc38497?
    Just to keep the changes with SIZEOF_DATUM < 8 leaner, or just because
    it was not worth bothering based on your TODO list?  I am wondering if
    there is a reason I may be missing here.
    --
    Michael
    
  5. Re: [PATCH] Simplify SortSupport implementation for macaddr

    John Naylor <johncnaylorls@gmail.com> — 2026-04-07T06:51:35Z

    On Wed, Mar 25, 2026 at 3:01 PM Michael Paquier <michael@paquier.xyz> wrote:
    >
    > On Mon, Mar 09, 2026 at 04:08:06PM +0300, Aleksander Alekseev wrote:
    > >> 1. The assignment ssup->ssup_extra = NULL can be removed. The
    > >>    SortSupport struct is zeroed before the callback is called (see
    > >>    sortsupport.h). There are about 22 similar assignments elsewhere;
    > >>    it does not seem to be established practice, many other places have
    > >>    no such assignment.
    > >
    > > Agree. I removed this assignment in 0001 and added 0002 that removes
    > > if for the rest of *_sortsupport() functions.
    >
    > Sounds sensible to get rid of the estimation with the Datum size
    > requirement and never give up with the abbreviated key sort, as done
    > in 0001.  I'd leave the code touched by 0002 remain as-is.
    
    I've committed v2-0001, thanks Aleksander! Without 0002, 0001 made
    this code inconsistent with the tree by removing the assignment, so I
    left it as in master.
    
    --
    John Naylor
    Amazon Web Services