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.94.2) (envelope-from ) id 1r7WBW-005ftV-Lx for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Nov 2023 07:37:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r7WBU-00BStN-67 for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Nov 2023 07:37:36 +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.94.2) (envelope-from ) id 1r7WBT-00BStF-RN for pgsql-hackers@lists.postgresql.org; Mon, 27 Nov 2023 07:37:35 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r7WBR-008kT6-GZ for pgsql-hackers@postgresql.org; Mon, 27 Nov 2023 07:37:35 +0000 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-daf4f0e3a0fso3655974276.1 for ; Sun, 26 Nov 2023 23:37:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701070652; x=1701675452; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=W6S5yU2wfCMvtygUDW+yKs1Pz4P922J7t0RTwHoPSpo=; b=FHHgYluyrhS7bUq85RBvuGhp43PNWz1CJMTASDhfX+fqzyQjiX0E5llz7M3Of+v9Cr x6l1VWXVOJ0mszbZFWATUAa1jdkE2JP92SSdct7sShYucDjYaWNwRfV841pqXKafndIl 2muNw2Q9F6hd4KYUfZ4abNW0om6ax/qN9Z3xVoD/z/qEsp9XqF+x5fNyTLRIWqwb6ue1 HB5k8B86Miq9YbL8NE3SN1mr0oRrpu4GTHpxsAUJnGX7udCWd77hSZWYmXIr0V19Qe8i +PIQiMSFbsjdQxtiMkSNaeZskGXnRmJDUpWkYbl9dPGywTPjT0aCU0NlXl/9iWV8rXLo xk8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701070652; x=1701675452; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=W6S5yU2wfCMvtygUDW+yKs1Pz4P922J7t0RTwHoPSpo=; b=qDje+3Pka17PuTTBn9tHESB4Uc3BM8/qY1frH3dXm5cKBrOqBkzq4Nw8oP8FoyGBGP LtZFVe+xlXpVM0utdkjLZZ7ReGB0igGuE3nHot04m4SYk7cFrySG4pd6h5ITcHXwtl+9 64PawQf5bix4cwZ2rywh0m9WaLnfJ5+q6F18KmH4KwcLel4P3lTbefN+Vo9mnfq8IHUN 4vTSzE3/o/S4nN9U+AziBZ/oHRahv16WGMBfj0HTrOhJJ2Bb6BjUTkk5pnG0LxpDVoTf YdJb7pggLzs9gOneWsdAh+8UKUj7zh8ee6/NBtHQBJ7pU7fq3FCfxFXjibKoPHxGmgRL bLvQ== X-Gm-Message-State: AOJu0YwzwOPKOuj58MFEEiYj5eDRMKerw/cja7l6ebjRqFdQ2L6vujS5 l+B134zbVpYJBEjbwhfsaP5FcYIH9oQqBMBA2D8= X-Google-Smtp-Source: AGHT+IHcuzikt6goCojzweilb29ola6ly2qiCpHweCRXRcifthxMesr46NOWjiPD+jlHTP+B6j5/QzGkMlvH2jv96c8= X-Received: by 2002:a25:f806:0:b0:d85:eac0:c7d2 with SMTP id u6-20020a25f806000000b00d85eac0c7d2mr10613830ybd.6.1701070651760; Sun, 26 Nov 2023 23:37:31 -0800 (PST) MIME-Version: 1.0 References: <20230704112358.bkm6r3fxp275m4lu@alvherre.pgsql> <2b672382-c0b3-3f44-b72c-86b1077b082b@enterprisedb.com> <11f78627-a934-1f8b-084e-21ed95f2564c@enterprisedb.com> <35e7be37-0d35-d8ea-a4d5-eff84aefcc39@enterprisedb.com> <1d68ef1d-41c5-7159-c6c0-b44dad4e3148@enterprisedb.com> <12d42882-7860-9b46-7572-3b2fae6c916f@enterprisedb.com> In-Reply-To: From: Richard Guo Date: Mon, 27 Nov 2023 15:37:20 +0800 Message-ID: Subject: Re: brininsert optimization opportunity To: Soumyadeep Chakraborty Cc: Tomas Vondra , Matthias van de Meent , Alvaro Herrera , pgsql-hackers , Ashwin Agrawal Content-Type: multipart/alternative; boundary="000000000000efa72d060b1d5f79" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000efa72d060b1d5f79 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Nov 27, 2023 at 1:53=E2=80=AFPM Soumyadeep Chakraborty < soumyadeep2007@gmail.com> wrote: > On Sun, Nov 26, 2023 at 9:28=E2=80=AFPM Richard Guo > wrote: > > It seems that we have an oversight in this commit. If there is no tupl= e > > that has been inserted, we wouldn't have an available insert state in > > the clean up phase. So the Assert in brininsertcleanup() is not always > > right. For example: > > > > regression=3D# update brin_summarize set value =3D brin_summarize.value= ; > > server closed the connection unexpectedly > > I wasn't able to repro the issue on > 86b64bafc19c4c60136a4038d2a8d1e6eecc59f2. > with UPDATE/INSERT: > > This could be because since c5b7ba4e67aeb5d6f824b74f94114d99ed6e42b7, > we have moved ExecOpenIndices() > from ExecInitModifyTable() to ExecInsert(). Since we never open the > indices if nothing is > inserted, we would never attempt to close them with ExecCloseIndices() > while the ii_AmCache > is NULL (which is what causes this assertion failure). AFAICS we would also open the indices from ExecUpdate(). So if we update the table in a way that no new tuples are inserted, we will have this issue. As I showed previously, the query below crashes for me on latest master (dc9f8a7983). regression=3D# update brin_summarize set value =3D brin_summarize.value; server closed the connection unexpectedly There are other code paths that call ExecOpenIndices(), such as ExecMerge(). I believe it's not hard to create queries that trigger this Assert for those cases. Thanks Richard --000000000000efa72d060b1d5f79 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Mon, Nov 27, 2023 at 1:53=E2=80=AFPM S= oumyadeep Chakraborty <soumy= adeep2007@gmail.com> wrote:
On Sun, Nov 26, 2023 at 9:28=E2=80=AFPM Richard Guo <= guofenglinux@gm= ail.com> wrote:
> It seems that we have an oversight in this commit.=C2=A0 If there is n= o tuple
> that has been inserted, we wouldn't have an available insert state= in
> the clean up phase.=C2=A0 So the Assert in brininsertcleanup() is not = always
> right.=C2=A0 For example:
>
> regression=3D# update brin_summarize set value =3D brin_summarize.valu= e;
> server closed the connection unexpectedly

I wasn't able to repro the issue on 86b64bafc19c4c60136a4038d2a8d1e6eec= c59f2.
with UPDATE/INSERT:

This could be because since c5b7ba4e67aeb5d6f824b74f94114d99ed6e42b7,
we have moved ExecOpenIndices()
from ExecInitModifyTable() to ExecInsert(). Since we never open the
indices if nothing is
inserted, we would never attempt to close them with ExecCloseIndices()
while the ii_AmCache
is NULL (which is what causes this assertion failure).
AFAICS we would also open the indices from ExecUpdate().=C2=A0 = So if we
update the table in a way that no new tuples are inserted, we w= ill have
this issue.=C2=A0 As I showed previously, the query below crash= es for me on
latest master (dc9f8a7983).

regression=3D# update br= in_summarize set value =3D brin_summarize.value;
server closed the conne= ction unexpectedly

There are other code paths that call ExecOpenIndi= ces(), such as
ExecMerge().=C2=A0 I believe it's not hard to create = queries that trigger this
Assert for those cases.

Thanks
Richa= rd
--000000000000efa72d060b1d5f79--