Skip to content

Give a function the SQL surface of every wrapper it backs - #83

Merged
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:fix/sqlfn-all-claimed-wrappers
Aug 14, 2026
Merged

Give a function the SQL surface of every wrapper it backs#83
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:fix/sqlfn-all-claimed-wrappers

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

A MEOS function often backs several PostgreSQL wrappers, and each wrapper
registers its own CREATE FUNCTION overloads. sqlSignatures read only the
first of them, so every sibling wrapper's overloads were dropped.

Four shapes of that loss:

one MEOS function its wrappers what was kept
ea_dwithin_tgeo_tgeo Edwithin_tgeo_tgeo, Adwithin_tgeo_tgeo eDwithin only
intspan_shift_scale Numspan_shift, Numspan_scale, Numspan_shift_scale shift only
set_as_wkb Set_send, Set_as_wkb *_send only
nad_tgeo_stbox NAD_tgeo_stbox, NAD_stbox_tgeo the temporal-first order only

The last one is why a commuted overload could not be represented at all.
nearestApproachDistance(stbox, tgeompoint) is a second wrapper over the one
nad_tgeo_stbox, so even a correct @csqlfn #NAD_tgeo_stbox() #NAD_stbox_tgeo()
had nowhere to land — the catalog would still have carried only the first order,
and a binding projecting sqlSignatures could never emit the swapped one
without hand-writing the swap itself.

The surface is now the union over every wrapper the function claims, with each
wrapper scope-filtered on its own and the result de-duplicated. sqlfn, sqlop
and mdbC keep naming the primary wrapper, unchanged.

Two things follow from it:

  • A wrapper is shared whenever two functions name it, in whatever position,
    so the claimant gathering no longer stops at the first. That brings
    Temporal_scale_time — claimed second by all four of its claimants — under
    the scope check for the first time; it is generic over Temporal * like the
    two siblings already declared beside it, and is declared the same way.
  • PostgreSQL accepts the function attributes in any order.
    aTouches(tcbuffer, cbuffer) is the one place MobilityDB writes SUPPORT
    before the body rather than after it, and that parsed as the return type
    boolean SUPPORT tspatial_supportfn. Only the type is kept now.

Measured

Derived from MobilityDB 071d4c80de, both sides in the same run:

  • 5537 functions, unchanged
  • sqlSignatures 8234 → 9027: 111 functions gain 793 overloads, none loses any
  • sqlfn, sqlop, mdbC: unchanged on every function
  • sqlArityMax rises on 42 (a second wrapper's wider overload), sqlArity falls
    on temporal_from_wkb (Temporal_from_wkb takes one argument where
    Temporal_recv takes three)
  • sqlReturnType changes on two: tbox_out gains asText beside tbox_out
    and so reports both, and atouches_tcbuffer_cbuffer loses the SUPPORT clause
    from its type

tests/test_sqlfn_wrappers.py covers the commuted pair, both halves of an
ever/always pair, the arity widening, the attribute-before-body return type, and
that the primary wrapper still names the function. Three of its six cases fail
against the previous parser.

Suite: 214 passed, 15 skipped. Two failures in test_family and
test_struct_layout are pre-existing — they reproduce unchanged on a catalog
generated by master's parser from the same MobilityDB commit, and come from
parsing source-tree headers (approximate struct layouts) rather than installed
ones.

Not in this change

The commuted wrappers still need MEOS to name them. 79 PostgreSQL wrappers that
carry an @sqlfn are the argument-swap of a wrapper some MEOS function claims,
yet no MEOS function claims them — 171 SQL overloads, NAD_stbox_tgeo among
them. Some are tag repointing (tdisjoint_geo_tcbuffer exists and tags
#Tdisjoint_tcbuffer_geo()); others have no MEOS symbol at all and want the
one-line swap wrapper the spatial-relationship grid already uses. Both are
MobilityDB-side; this change is what makes their result representable.

A MEOS function often backs several PostgreSQL wrappers, each registering its
own CREATE FUNCTION overloads: the ever/always pair over one `ea_*` kernel, the
shift/scale/shiftScale trio over one `*_shift_scale`, send and asBinary over one
`*_as_wkb`, and the argument-commuted form of an asymmetric operation
(`NAD_stbox_tgeo` beside `NAD_tgeo_stbox`, both over `nad_tgeo_stbox`).

`sqlSignatures` read only the first of them, so every sibling wrapper's
overloads were dropped — the always half of each ever/always pair, two thirds of
each shift/scale trio, and any commuted argument order. Take the union over all
of them instead, scope-filtering each wrapper on its own and de-duplicating.

A wrapper is shared whenever two functions name it, in whatever position, so
gather the claimants of every wrapper rather than of the first alone; that
brings `Temporal_scale_time` under the scope check, and its generic claimant is
declared alongside its two siblings.

PostgreSQL also accepts the function attributes in any order, and
`aTouches(tcbuffer, cbuffer)` writes SUPPORT before the body, which parsed as
the return type `boolean SUPPORT tspatial_supportfn`. Keep only the type.

Deriving from MobilityDB 071d4c80de leaves the 5537 functions unchanged and
takes sqlSignatures from 8234 to 9027: 111 functions gain 793 overloads and none
loses any.
@estebanzimanyi
estebanzimanyi merged commit df3ea2e into MobilityDB:master Aug 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant