Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pPhV5-0004lD-GI for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Feb 2023 10:16:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pPhV4-0006J0-9k for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Feb 2023 10:16:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1pPhV3-0006IQ-Vj for pgsql-bugs@lists.postgresql.org; Wed, 08 Feb 2023 10:16:26 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1pPhUz-0004aW-0Q for pgsql-bugs@lists.postgresql.org; Wed, 08 Feb 2023 10:16:24 +0000 Received: by mail-ej1-x62a.google.com with SMTP id ml19so50140730ejb.0 for ; Wed, 08 Feb 2023 02:16:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=R+WRhRfP67B5fe5HgU9WASPnogUPYuqkFkLz9RasiPc=; b=aMuV4CdWQrPDhnQ/FUKK+kK5eJ0BDEUhel0xN+yf++Ej0hppTwBCvSCpiQ/mNs831R A12AlGcJytg8LT2/fFfg9/b956VUp7hRCWj1KJAp6kjak2RPhlQiJiLEnp7hQFTIHK7A Gk1nphpecxoFhHl+76lVHG/qh2R/YXF1HAK3AxC9+Q3in+nIJYv4Azald5PBkmD5FSju y5bJFHlTvDGfx3VPXoMrsd2WaqD2LoivvIV17dbXdAntEMQyPIFYzDlR/5SFvp4Ol+sn LLRElc7hsJjo+RsqmIoq7ICEgeqvQACm987zKmBddg8Xi84FGOAfCvN5k7xpuY9wCHOo Bv6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=R+WRhRfP67B5fe5HgU9WASPnogUPYuqkFkLz9RasiPc=; b=gw2lRvoxNAIJXmk2rZQpPckXNqQAjZEb5OBuEAkQf8fP8KgTnlgz6RMb5+2AMMtJz1 j1JggwCiuHxi4utwxQpbQRSUlAN2uf6+muNz2cmwIO2E0kLW5VziIn383m6PIRRLsJrB SIIaHZBGm/6mrJ/HWSs4L1De9emTjdYz+uGxdJczFRrNvEKAn7idX37WfS5tPewqG1PZ I/YN4pdDe0N5kwwZN+Ul8p2CJNsRkEGgcpoYi4/30bIeuBath2Bfx2ZX8/GCdUKT/sIE Glw02t2y3+9OewjMYaFR0ElVukbMfuWfO47ZACuf6XpGJhBmvAWOOnzamzBgscSJ/nrf bICg== X-Gm-Message-State: AO0yUKX1Zbahl8gKOsfjT0kLIVu6FmGF2qfX0HYUp0bNAt81mlOMtVkF zaS8p8nLWAIb6Y7yDZA8EAN833d9VCs= X-Google-Smtp-Source: AK7set/qxJtK8PL/hXty2rHuKkqH+R23TcAirhLCdO4kVCrsdTHEa+JhMl3JfC5vxJXA5PHaBeK/hA== X-Received: by 2002:a17:907:6d8a:b0:887:9a32:9a2 with SMTP id sb10-20020a1709076d8a00b008879a3209a2mr9455515ejc.0.1675851379572; Wed, 08 Feb 2023 02:16:19 -0800 (PST) Received: from ddolgov.remote.csb (dslb-178-012-041-046.178.012.pools.vodafone-ip.de. [178.12.41.46]) by smtp.gmail.com with ESMTPSA id kb18-20020a1709070f9200b0088ef3c38a52sm8224631ejc.19.2023.02.08.02.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 02:16:19 -0800 (PST) Date: Wed, 8 Feb 2023 11:16:18 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: John Naylor Cc: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17774: Assert triggered on brin_minmax_multi.c Message-ID: <20230208101618.w6vptrm66u7mddi6@ddolgov.remote.csb> References: <17774-c6f3e36dd4471e67@postgresql.org> <20230208100658.mz2kkeruoma6iqtw@ddolgov.remote.csb> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230208100658.mz2kkeruoma6iqtw@ddolgov.remote.csb> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > 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 > > 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] [...]