tds_fdw
tds_fdw copied to clipboard
Segmentation fault selecting geometry columns via foreign table
Issue report
I've imported a foreign table that has geometry
columns. If I execute a select with any geometry columns included, a segmentation fault occurs. Selecting without any geometry columns work as expected.
Operating system
Using Amazon Aurora PostgreSQL.
Version of tds_fdw
2.0.2
Version of PostgreSQL
PostgreSQL 14.4 on aarch64-unknown-linux-gnu, compiled by aarch64-unknown-linux-gnu-gcc (GCC) 7.4.0, 64-bit
Version of FreeTDS
Unknown.
Logs
2022-12-09 20:40:37 UTC::@:[491]:LOG: server process (PID 559) was terminated by signal 11: Segmentation fault
2022-12-09 20:40:37 UTC::@:[491]:DETAIL: Failed process was running: SELECT * FROM env."TableNameHere" WHERE "PKColumn" = '12345';
2022-12-09 20:40:37 UTC::@:[491]:LOG: terminating any other active server processes
2022-12-09 20:40:37 UTC::@:[491]:FATAL: Can't handle storage runtime process crash
2022-12-09 20:40:37 UTC::@:[491]:LOG: database system is shut down
Sentences, data structures, data
The actual object names have been replaced.
Schema import:
IMPORT FOREIGN SCHEMA "ENV" FROM SERVER foreign_server_here INTO env;
Example query:
SELECT "PKColumn", "ColumnWithGeometry"
FROM env."TableNameHere"
WHERE "PKColumn" = '12345';
Structure in PostgreSQL:
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_name = 'TableNameHere';
table_name | column_name | data_type |
---|---|---|
TableNameHere | PKColumn | character varying |
TableNameHere | ColumnWithGeometry | text |
Structure in SQL Server:
CREATE TABLE [ENV].[TableNameHere] (
[PKColumn] varchar,
[ColumnWithGeometry] geometry
);
To make this work, I think we would need to do a couple things at minimum:
- For
IMPORT FOREIGN SCHEMA
, we need a mapping from SQL Server'sgeometry
type to a specific PostgreSQL type in thetdsImportSqlServerSchema()
function - https://github.com/tds-fdw/tds_fdw/blob/16f3fc5cf97bc661021b076f5df3be97c151a42b/src/tds_fdw.c#L3226 - For
SELECT
, we would also need a conversion from SQL Server'sgeometry
type to a specific PostgreSQL type in thetdsIterateForeignScan()
function - https://github.com/tds-fdw/tds_fdw/blob/16f3fc5cf97bc661021b076f5df3be97c151a42b/src/tds_fdw.c#L1793
Other changes might also be required.