Re: BUG #17774: Assert triggered on brin_minmax_multi.c - Mailing list pgsql-bugs

From Dmitry Dolgov
Subject Re: BUG #17774: Assert triggered on brin_minmax_multi.c
Date
Msg-id 20230208101618.w6vptrm66u7mddi6@ddolgov.remote.csb
Whole thread Raw
In response to Re: BUG #17774: Assert triggered on brin_minmax_multi.c  (Dmitry Dolgov <9erthalion6@gmail.com>)
List pgsql-bugs
> On Wed, Feb 08, 2023 at 11:06:58AM +0100, Dmitry Dolgov wrote:
> > On Wed, Feb 08, 2023 at 04:26:49PM +0700, John Naylor wrote:
> > On Mon, Feb 6, 2023 at 3:06 PM PG Bug reporting form <noreply@postgresql.org>
> > wrote:
> > > This assert() is not easily reproducible, but thought the backtraces may
> > be
> > > interesting.
> > >
> > > TRAP: FailedAssertion("(delta >= 0) && (delta <= 1)", File:
> > > "brin_minmax_multi.c", Line: 2393, PID: 2922100)
> >
> > > #2  0x000055e143f0ae8b in ExceptionalCondition (
> > >     conditionName=0x55e143f92604 "(delta >= 0) && (delta <= 1)",
> > >     errorType=0x55e143f91ef4 "FailedAssertion",
> > >     fileName=0x55e143f91ee0 "brin_minmax_multi.c", lineNumber=2393)
> > >     at assert.c:69
> > > No locals.
> > > #3  0x000055e1437e8972 in brin_minmax_multi_distance_inet (
> > >     fcinfo=0x7ffc448234f0) at brin_minmax_multi.c:2393
> > >         delta = -2.3283064365386963e-10
> > >         i = -1
> > >         len = 4
> > >         addra = 0x55e14ee95fc0 ""
> > >         addrb = 0x55e14ee95fe0 ""
> > >         ipa = 0x55e14d95a1e0
> > >         ipb = 0x55e149a6fdc8
> > >         lena = 0
> > >         lenb = 32
> >
> > Thanks for the report! From the stack trace we can see that it computed a
> > negative delta, coming from:
> >
> > /* Calculate the difference between the addresses. */
> > delta = 0;
> > for (i = len - 1; i >= 0; i--)
> > {
> >   unsigned char a = addra[i];
> >   unsigned char b = addrb[i];
> >
> >   delta += (float8) b - (float8) a;
> >   delta /= 256;
> > }
> > Assert((delta >= 0) && (delta <= 1));
> >
> > I wonder if it needs to be something like "delta += Abs((float8) b -
> > (float8) a);".
>
> The negative delta might be only a consequence. From what I see it's
> called from build_distances, and the idea is to find the gaps between
> the max value of the current interval and the min value of the next one,
> so they should be ordered and delta should be always positive.
>
> In fact, I've just reproduced it by randomly inserting some inets into
> the test table, let me see if I can get a stable reproducer.

Yep, this sequence reproduces the issue reliably for me:

    create table brin_test (data inet);
    create index brin_multi on brin_test using brin (data inet_minmax_multi_ops);

    insert into brin_test values('127.0.0.1/0');
    insert into brin_test values('2001:db8:3333:4444:5555:6666:7777:8888');
    insert into brin_test values('0.0.0.0/12');

    TRAP: failed Assert("(delta >= 0) && (delta <= 1)"), File: "brin_minmax_multi.c", Line: 2389, PID: 76147
    [local] INSERT(ExceptionalCondition+0x9e)[0xb432a7]
    [local] INSERT(brin_minmax_multi_distance_inet+0x409)[0x494345]
    [local] INSERT(FunctionCall2Coll+0x99)[0xb4e027]
    [local] INSERT[0x4922c8]
    [local] INSERT[0x492deb]
    [local] INSERT[0x4943a7]
    [local] INSERT(brin_form_tuple+0x231)[0x498dd4]
    [local] INSERT(brininsert+0x406)[0x48a35f]
    [...]



pgsql-bugs by date:

Previous
From: Dmitry Dolgov
Date:
Subject: Re: BUG #17774: Assert triggered on brin_minmax_multi.c
Next
From: Tom Lane
Date:
Subject: Re: BUG #17774: Assert triggered on brin_minmax_multi.c