Re: BRIN index creation on geometry column causes crash
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Tobias Wendorff <tobias.wendorff@tu-dortmund.de>, Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-01-03T00:15:06Z
Lists: pgsql-bugs
On Fri, 3 Jan 2025 at 11:02, Tobias Wendorff
<tobias.wendorff@tu-dortmund.de> wrote:
>
> ```sql
> DROP TABLE IF EXISTS random_points;
> CREATE TABLE random_points AS
> SELECT ST_MakePoint(0, 0) AS geom FROM generate_series(1, 130_561);
> CREATE INDEX ON random_points USING brin(geom);
> ```
> ### Actual behavior
> The server terminates abruptly during index creation with the following
> error:
> ```
> server closed the connection unexpectedly
Thanks for the report. That's certainly a bug.
What seems to be going on is that the following code in
brin_inclusion_union() looks for the function for the PROCNUM_MERGE
strategy but cannot find it, and not finding it shouldn't result in a
crash. The code does:
finfo = inclusion_get_procinfo(bdesc, attno, PROCNUM_MERGE);
Assert(finfo != NULL);
I built with Asserts enabled and that Assert triggers for me.
The other strategy types seem to check for NULLs with:
finfo = inclusion_get_procinfo(bdesc, attno, PROCNUM_MERGEABLE);
if (finfo != NULL &&
It seems, going by the following comment that PROCNUM_MERGE isn't
optional, which probably explains about the lack of NULL check for
that strategy, however, I don't see any code anywhere which checks to
make sure it exists before we get to this point.
#define PROCNUM_MERGE 11 /* required */
I see PostGIS sets this up with the following:
CREATE OPERATOR CLASS brin_geography_inclusion_ops
DEFAULT FOR TYPE geography
USING brin AS
FUNCTION 1 brin_inclusion_opcinfo(internal),
FUNCTION 2 geog_brin_inclusion_add_value(internal,
internal, internal, internal),
FUNCTION 3 brin_inclusion_consistent(internal,
internal, internal),
FUNCTION 4 brin_inclusion_union(internal, internal, internal),
OPERATOR 3 &&(geography, geography),
OPERATOR 3 &&(geography, gidx),
OPERATOR 3 &&(gidx, geography),
OPERATOR 3 &&(gidx, gidx),
STORAGE gidx;
I've copied in Álvaro, as he knows this code much better than I do.
David
Commits
-
BRIN: be more strict about required support procs
- f5b4a0b49e0b 13.21 landed
- e0d8f49a3fee 16.9 landed
- ade976f8b481 17.5 landed
- 5d8c58800494 15.13 landed
- 5144e1f8fdde 14.18 landed
- 17ce344f86f1 18.0 landed