A number of BRIN opclasses seems to broken / missing the MERGE procedure

Tomas Vondra tomas at vondra.me
Sat Jan 4 05:53:34 PST 2025


Hi,

Over at the pgsql-bugs mailing list we got a report [1] of a failure
during a parallel build of a BRIN index on "geom" column.

The reason is fairly simple - the brin_geometry_inclusion_ops_2d opclass
is defined with these procedures:

select amprocnum, amproc from pg_amproc
 where amprocfamily
   = (select oid from pg_opclass
       where opcname = 'brin_geometry_inclusion_ops_2d');

 amprocnum |             amproc
-----------+---------------------------------
         1 | brin_inclusion_opcinfo
         2 | geom2d_brin_inclusion_add_value
         3 | brin_inclusion_consistent
         4 | brin_inclusion_union
(4 rows)

That is, it's missing the MERGE procedure (procnum=11), which is however
expected to exists (ans is required since the very beginning, when BRIN
was introduced in 9.5).

This happens to mostly work for non-parallel builds and updates, because
the opclass overrides the ADD_VALUE procedure, and this custom version
does not rely on the MERGE (it does the type-specific merge directly).

But that does not mean it's quite safe - it's not too hard to trigger
exactly the same kind of crash through the UNION proc, which the opclass
does not override.

In short, with two sessions:

    S1: desummarize range 0
    SELECT brin_desummarize_range('random_points_geom_idx', 0);

    S1: summarize range 0, breakpoint on brin_can_do_samepage_update
                           (in summarize_range)
    SELECT brin_summarize_range('random_points_geom_idx', 0);

    S2: insert a tuple into range 0
    INSERT INTO random_points SELECT ST_MakePoint(1000, 1000);

    S1: continue execution

I suppose the opclass could override brin_inclusion_union() in much the
same way, but at that point maybe it'd be better to just not treat this
as an inclusion opclass at all, and instead make it independent.

Or instead add the MERGE, and go back to using brin_inclusion_add_value
(I haven't checked why exactly the opclass has a custom ADD_VALUE proc,
maybe there are trouble with brin_inclusion_add_value).

Also, this is not the only opclass with such issues - amvalidate()
reports a bunch of issues (attached).


regards


[1]
https://www.postgresql.org/message-id/fb6d9a35-6c8e-4869-af80-0a4944a793a4%40tu-dortmund.de

-- 
Tomas Vondra
-------------- next part --------------
INFO:  operator family "gist_geometry_ops_2d" of access method gist contains function geometry_gist_consistent_2d(internal,geometry,integer) with wrong signature for support number 1
INFO:  operator family "gist_geometry_ops_2d" of access method gist contains function geometry_gist_union_2d(bytea,internal) with wrong signature for support number 2
INFO:  operator family "gist_geometry_ops_2d" of access method gist contains function geometry_gist_same_2d(geometry,geometry,internal) with wrong signature for support number 7
INFO:  operator family "gist_geometry_ops_2d" of access method gist contains function geometry_gist_distance_2d(internal,geometry,integer) with wrong signature for support number 8
INFO:  operator family "gist_geometry_ops_nd" of access method gist contains function geometry_gist_consistent_nd(internal,geometry,integer) with wrong signature for support number 1
INFO:  operator family "gist_geometry_ops_nd" of access method gist contains function geometry_gist_union_nd(bytea,internal) with wrong signature for support number 2
INFO:  operator family "gist_geometry_ops_nd" of access method gist contains function geometry_gist_same_nd(geometry,geometry,internal) with wrong signature for support number 7
INFO:  operator family "gist_geometry_ops_nd" of access method gist contains function geometry_gist_distance_nd(internal,geometry,integer) with wrong signature for support number 8
INFO:  operator family "gist_geography_ops" of access method gist contains function geography_gist_consistent(internal,geography,integer) with wrong signature for support number 1
INFO:  operator family "gist_geography_ops" of access method gist contains function geography_gist_union(bytea,internal) with wrong signature for support number 2
INFO:  operator family "gist_geography_ops" of access method gist contains function geography_gist_same(box2d,box2d,internal) with wrong signature for support number 7
INFO:  operator family "gist_geography_ops" of access method gist contains function geography_gist_distance(internal,geography,integer) with wrong signature for support number 8
INFO:  operator family "brin_geography_inclusion_ops" of access method brin is missing support function(s) for types gidx and gidx
INFO:  operator family "brin_geometry_inclusion_ops_2d" of access method brin is missing support function(s) for types box2df and box2df
INFO:  operator family "brin_geometry_inclusion_ops_3d" of access method brin is missing support function(s) for types gidx and gidx
INFO:  operator family "brin_geometry_inclusion_ops_4d" of access method brin is missing support function(s) for types gidx and gidx
INFO:  SP-GiST leaf data type box2df does not match declared type geometry
INFO:  operator family "spgist_geometry_ops_2d" of access method spgist contains function geometry_spgist_compress_2d(internal) with wrong signature for support number 6
INFO:  SP-GiST leaf data type box3d does not match declared type geometry
INFO:  operator family "spgist_geometry_ops_3d" of access method spgist contains function geometry_spgist_compress_3d(internal) with wrong signature for support number 6
INFO:  SP-GiST leaf data type gidx does not match declared type geometry
INFO:  operator family "spgist_geometry_ops_nd" of access method spgist contains function geometry_spgist_compress_nd(internal) with wrong signature for support number 6
INFO:  SP-GiST leaf data type gidx does not match declared type geography
INFO:  operator family "spgist_geography_ops_nd" of access method spgist contains function geography_spgist_compress_nd(internal) with wrong signature for support number 6


More information about the postgis-devel mailing list