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 1tiAPJ-00CH8K-Bl for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Feb 2025 10:55:53 +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 1tiAPG-008XR4-U9 for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Feb 2025 10:55:51 +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 1tiAPG-008XPq-3H for pgsql-bugs@lists.postgresql.org; Wed, 12 Feb 2025 10:55:51 +0000 Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tiAPE-000Okn-0C for pgsql-bugs@lists.postgresql.org; Wed, 12 Feb 2025 10:55:49 +0000 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id ED67411401D9; Wed, 12 Feb 2025 05:55:46 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Wed, 12 Feb 2025 05:55:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1739357746; x=1739444146; bh=m v1hijWx/BYKV4oS67jBiO65Mvz99kYNLcb+VWbGac0=; b=z3sbklREYVC1h0U1d bkI+oVMWIbPZR99vmYc6ODuOBzNQb+xKcfolCxk0iBn5YnIYGABQOPLlmfRVsZYQ fR4b1Ba2Ev86G1ZB7Ax6b/G3bsZm6wHA5tHEFAafcXCd+tE58yWXryvzP/yxuigs K0ASxfz6k5/RuhlbGM4XCFwa4D9mIgOLsZerB26+4MMiLeOOFr+CxPCakjRlpcmZ BvOqEYtgCvMebUHtcRlMWWYG7NFH9OV+zisCCa1LN2TaPCDGwgTR903y6jIOa+7Y JACuFWNNau4io0t8CCrj7QiRYSTntK1iSTzEjFJdCEgTjhTDqee6tkKhEu2e+ORu oBDvw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegfeeilecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfgjsehmkeerredttdej necuhfhrohhmpemllhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvh hhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpeeijedvudeggeefleelheff ieehlefhudeuffdtheeguedujeduvdegteffhfffueenucffohhmrghinhepvghnthgvrh hprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspg hrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphhgshhqlhdq sghughhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehtoh gsihgrshdrfigvnhguohhrfhhfsehtuhdqughorhhtmhhunhgurdguvgdprhgtphhtthho pehtohhmrghssehvohhnughrrgdrmhgv X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Feb 2025 05:55:45 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1739357743; bh=W/5LhXSnbDMt15Ildk2MQQ4Y9k4wLNf96wXGQ6tc474=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=NYisDHC6VNva3p8W+4Y7zaij707TluDqwAATtV+gH/tTKFfNgqiNxpvXKOmEsodHk LcUF/Bmma7NfYy3OUNxrhjHcuLBoAGA6ccULHHcl0OPVP6ezj+3GekJ5o/zxn+MJ9E InzOd4vpFI1HXu2GLNToSkIn43QymzOGQhT4/YCG0l4veqpGZW35H3QmbeSimk315Y IeCARqSQQncQTYAevGA2NWIBwO1x8ZF6UJD0lLz+VBgWG+3OfLg0VrXEXBCS+ilrFf c6++7NaIInTJBpZ2QOBio8G9U0FjhTgU2KbAwV++fyITJvMNr+zFR+p8CbG6qElvEx NRSr61hd8u/xw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id D106C6D; Wed, 12 Feb 2025 11:55:43 +0100 (CET) Date: Wed, 12 Feb 2025 11:55:43 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Tomas Vondra Cc: Tobias Wendorff , pgsql-bugs@lists.postgresql.org Subject: Re: BRIN index creation on geometry column causes crash Message-ID: <202502121055.ufgofvji2kuv@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="3wzbj3zscr6r7fvh" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9b346570-675c-47a5-ab2b-131bcc80988b@vondra.me> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --3wzbj3zscr6r7fvh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2025-Jan-03, Tomas Vondra wrote: > Reproduced, but I belive this is actually a long-standing PostGIS bug. > The exact place where it crashes is here: > > /* Finally, merge B to A. */ > finfo = inclusion_get_procinfo(bdesc, attno, PROCNUM_MERGE); > Assert(finfo != NULL); > result = FunctionCall2Coll(finfo, colloid, ...); > > With asserts, it fails on the assert, i.e. finfo is NULL. This means the > opfamily is missing the "MERGE" support procedure, which is however > required (from the very beginning of BRIN in 9.5). Hmm, I completely agree that this is a PostGIS bug, but at the same time I think it's wrong for Postgres not to verify that the support function exists, so that we can throw an error instead of crashing. I think the most expedient way to implement this is to add a "missing_ok" argument to the various "foo_get_procinfo" functions, and make to pass it true only in cases where the usage of the return value already admit that it could be a null pointer (meaning it's really an optional support proc). This should avoid further crashes with invalidly defined opclasses; see attached POC patch. The user is still in a bad place, because for instance if it's autovacuum that tries to do the range merging, then vacuuming will fail but people may not notice for months unless they're paying careful attention to the server logs. Crashing is good (tm) because now a bunch of people are aware that the opclass is broken. My next question is why didn't brinvalidate detect this problem. Is it just that nobody ran 'amvalidate' on the opclass, or is it that brinvalidate does not know that it needs to require the merge proc? But I'll leave that for later. Now, in writing this patch I noticed that both brin_bloom.c and brin_minmax_multi.c seem to have cargo-culted the idea that support procs can be optional; both of them have a single support proc (PROCNUM_HASH and PROCNUM_DISTANCE, respectively) which is not optional; so the "extra_proc_missing" stuff seems unnecessary for them. And therefore the new missing_ok support I introduce in this patch would also be unnecessary. As far as I can tell, there are no ABI concerns about removing opaque->extra_proc_missing[] from both these opclass scaffolds (and reintroducing it later, if we determine that we do need optional support procs in those scaffolds after all.) -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Saca el libro que tu religión considere como el indicado para encontrar la oración que traiga paz a tu alma. Luego rebootea el computador y ve si funciona" (Carlos Duclós) --3wzbj3zscr6r7fvh Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v1-0001-BRIN-be-stricter-about-required-support-procs.patch"