Skip to content

Name the C value feeding each column of a returned SQL row - #151

Merged
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:catalog/row-columns
Sep 30, 2026
Merged

estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:catalog/row-columns

Conversation

@estebanzimanyi

@estebanzimanyi estebanzimanyi commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

A SQL signature returning a row lists its columns, each naming the C value
that feeds it. PostgreSQL declares the columns of a function returning
record as its OUT arguments, and those of a function returning a composite
type as the members of that type. An OUT argument is no input, so it leaves
args, argDefaults and required: eDisjointPairs(tgeometry[], tgeometry[]) is
{args: [tgeometry[], tgeometry[]], ret: record, retSet: true, columns:
[i, j]}: the two arrays are its only arguments.

attach_row_sources matches each column to its C source by type, so the SQL
column order and the C parameter order need not agree. from is return, the
value or array the function returns, or an out-parameter, with element or
field inside it: valueTimeSplit rows (number, time, tnumber) read the
out-parameters value_bins and time_bins and the returned fragments,
dynTimeWarpPath rows (i, j) the fields of each returned Match, quaternion
the four elements of the returned array. A bool returned beside
out-parameters says whether there is a row and feeds no column, and a
struct a class stands for, a TBox tile, is one value and not its fields.
meta/sql-columns.json states what only the wrapper computes: the index of a
tile numbers the rows from 1 (from: ordinal), and the …Pairs wrappers add 1
to the C indices i and j to make them SQL array positions (offset: 1). A row
with a column no C value feeds, fed alike by two, or with a C value feeding
no column stops the catalog.

Why. A binding that returns the rows of a SQL function reads them from the
C call: it has to know which C value is which column, and which argument of
a record-returning signature is passed rather than returned.

Measured. Over MobilityDB 8a23781e4c, 147 SQL signatures carried by 64
functions state their columns: 37 returning record (the …Pairs kernels) and
110 returning one of 61 composite types. Of their columns, 200 read the C
return (95 the value or array whole, 74 an element plus the declared
offset, 24 a struct field, 7 an element of a fixed array), 96 an
out-parameter, and 18 the ordinal. The 37
record signatures drop their OUT arguments from args, and the 12 …Pairs
functions their sqlArity from 4, 5 or 6 to 2 or 3. The catalog is otherwise
identical to the one derived without the change.

Witness. tests/test_sqlfn_rows.py takes the OUT arguments out of args and
the members of a composite return type as columns, matches columns by type
whatever their order, reads struct fields, fixed-array elements and a
pair's elements beside an out-parameter array, applies ordinal and offset
only where declared, stops on an unfed, doubly fed or surplus source, and
validates meta/sql-columns.json against its schema. The suite floor goes
from 317 to 337.

A SQL signature returning a row lists its columns, each naming the C value
that feeds it. PostgreSQL declares the columns of a function returning
record as its OUT arguments, and those of a function returning a composite
type as the members of that type. An OUT argument is no input, so it leaves
args, argDefaults and required: eDisjointPairs(tgeometry[], tgeometry[]) is
{args: [tgeometry[], tgeometry[]], ret: record, retSet: true, columns:
[i, j]}: the two arrays are its only arguments.

attach_row_sources matches each column to its C source by type, so the SQL
column order and the C parameter order need not agree. from is return, the
value or array the function returns, or an out-parameter, with element or
field inside it: valueTimeSplit rows (number, time, tnumber) read the
out-parameters value_bins and time_bins and the returned fragments,
dynTimeWarpPath rows (i, j) the fields of each returned Match, quaternion
the four elements of the returned array. A bool returned beside
out-parameters says whether there is a row and feeds no column, and a
struct a class stands for, a TBox tile, is one value and not its fields.
meta/sql-columns.json states what only the wrapper computes: the index of a
tile numbers the rows from 1 (from: ordinal), and the …Pairs wrappers add 1
to the C indices i and j to make them SQL array positions (offset: 1). A row
with a column no C value feeds, fed alike by two, or with a C value feeding
no column stops the catalog.

Why. A binding that returns the rows of a SQL function reads them from the
C call: it has to know which C value is which column, and which argument of
a record-returning signature is passed rather than returned.

Measured. Over MobilityDB 8a23781e4c, 147 SQL signatures carried by 64
functions state their columns: 37 returning record (the …Pairs kernels) and
110 returning one of 61 composite types. Of their columns, 200 read the C
return (95 the value or array whole, 74 an element plus the declared
offset, 24 a struct field, 7 an element of a fixed array), 96 an
out-parameter, and 18 the ordinal. The 37
record signatures drop their OUT arguments from args, and the 12 …Pairs
functions their sqlArity from 4, 5 or 6 to 2 or 3. The catalog is otherwise
identical to the one derived without the change.

Witness. tests/test_sqlfn_rows.py takes the OUT arguments out of args and
the members of a composite return type as columns, matches columns by type
whatever their order, reads struct fields, fixed-array elements and a
pair's elements beside an out-parameter array, applies ordinal and offset
only where declared, stops on an unfed, doubly fed or surplus source, and
validates meta/sql-columns.json against its schema. The suite floor goes
from 317 to 337.
@estebanzimanyi
estebanzimanyi merged commit 3dc2854 into MobilityDB:master Sep 30, 2026
3 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