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 1r7dwJ-00672s-7w for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Nov 2023 15:54:27 +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 1r7dwH-00EhIX-R7 for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Nov 2023 15:54:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r7dwH-00EhI5-Fw for pgsql-hackers@lists.postgresql.org; Mon, 27 Nov 2023 15:54:25 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r7dwE-007cj6-6h for pgsql-hackers@postgresql.org; Mon, 27 Nov 2023 15:54:23 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-54b0e553979so3420969a12.2 for ; Mon, 27 Nov 2023 07:54:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1701100460; x=1701705260; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=9y+ICrVAoZdbsNResFQ24w0TwWbR0OmGh+OcFFZ51Cw=; b=mctOqfG7vWVnRp2rtQA2fyNLVzI/50FL+0jXuPro9gHNwws40pMffG/LdsIfqJyEW4 6veJBDJmsNawG0GahgW3u/6ZYQ5Mddik1PT3Fx/vP4ORRB6yzAsUow53riVzl+2Ufs2t OlhBaRQFgqZaVUg9I2ge7Icx9uRbM7e96llH1l+JtX4H9JQBJplwtVleKSl7/98ieBV9 dag/BQJIZkJU2klflLI8v996ZDIjpFrfIK9gnYoem1S5BDh01NK+VKuP824RKjJ/aY2t oMHH0BJsJjmSS1pPVVyATZnvJ208g7m6xyGkW2ibIMVgjVW2vy4GkngYhahJY6nRiVxa +y7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701100460; x=1701705260; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9y+ICrVAoZdbsNResFQ24w0TwWbR0OmGh+OcFFZ51Cw=; b=aKUusZ92grg1SxX36BuCTA7T4pFJ+6pzCxmNkA9HqiNouSnX07FwH4gbe/na29nUeu uQYS7K/zN87qbTVfei8AXMRakuSKcYQ4OTTPacCJUqNmeMRf42c1HQeAclqSaQBlmWQ3 WOA+H/YovCEUt+ScZD7czOmyQI0asXR+W2lMy8LAEJdT3+/QeUJ9wdzE1koYmUFVXLNq yLoDAmLoKrNR1ishVjNusFXnXbMHbNH5IfJT51fCcvh1aP48EAee5GUJP8A0Y4xY3n8s z+EJb1qDOSooBWZDYaB9j0RDW0suSHyLSBlcRP/Xy0gMxdZSrYdNenpEEqdr3VSZde5j LrtQ== X-Gm-Message-State: AOJu0YwT2qa4Op/1Ok0zBWMeQzBKkikoeWkibrEn7Pm/D1jxG5NdVrzP g2/l5UX+BwaulJixe0Jk2axsBg== X-Google-Smtp-Source: AGHT+IHclR63MG6eSfup6Y9W7IyJKrfT/ifq50fWcUzedKvTlguo/lhZUQX/+OV1O/zIx8ql8RbJMQ== X-Received: by 2002:aa7:d94d:0:b0:54b:3a0:279f with SMTP id l13-20020aa7d94d000000b0054b03a0279fmr7745742eds.13.1701100460564; Mon, 27 Nov 2023 07:54:20 -0800 (PST) Received: from [10.137.0.17] (srv1.mobissw.com. [89.235.0.226]) by smtp.gmail.com with ESMTPSA id g22-20020a056402115600b0054887e27dc8sm5281788edw.62.2023.11.27.07.54.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Nov 2023 07:54:20 -0800 (PST) Message-ID: <0a45e27b-d55d-f46b-5954-2824c9834d2a@enterprisedb.com> Date: Mon, 27 Nov 2023 16:54:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: brininsert optimization opportunity Content-Language: en-US From: Tomas Vondra To: Richard Guo , Soumyadeep Chakraborty Cc: Matthias van de Meent , Alvaro Herrera , pgsql-hackers , Ashwin Agrawal References: <20230704112358.bkm6r3fxp275m4lu@alvherre.pgsql> <35e7be37-0d35-d8ea-a4d5-eff84aefcc39@enterprisedb.com> <1d68ef1d-41c5-7159-c6c0-b44dad4e3148@enterprisedb.com> <12d42882-7860-9b46-7572-3b2fae6c916f@enterprisedb.com> <4b436ddb-39a5-fad5-5486-f8f971dcaaf6@enterprisedb.com> In-Reply-To: <4b436ddb-39a5-fad5-5486-f8f971dcaaf6@enterprisedb.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/27/23 11:34, Tomas Vondra wrote: > > > On 11/27/23 08:37, Richard Guo wrote: >> >> On Mon, Nov 27, 2023 at 1:53 PM Soumyadeep Chakraborty >> > wrote: >> >> On Sun, Nov 26, 2023 at 9:28 PM Richard Guo > > wrote: >> > It seems that we have an oversight in this commit.  If there is no >> tuple >> > 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=# update brin_summarize set value = 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=# update brin_summarize set value = 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. >> > > FWIW I can readily reproduce it like this: > > drop table t; > create table t (a int); > insert into t values (1); > create index on t using brin (a); > update t set a = a; > > I however wonder if maybe we should do the check in index_insert_cleanup > and not in the AM callback. That seems simpler / better, because the AM > callbacks then can't make this mistake. > I did it this way (check in index_insert_cleanup) and pushed. Thanks for the report! regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company