pramsey / pgsql-ogr-fdw

PostgreSQL foreign data wrapper for OGR
MIT License
239 stars 34 forks source link

PG 14: ogrExecForeignDelete: ERROR: cannot find 'fid' column in table 'bytea_fdw' #234

Closed df7cb closed 2 years ago

df7cb commented 2 years ago

I originally posted this in #152, but it's really a separate issue.

On Debian, the regression tests fail the delete from bytea_fdw test with PG 14 (10..13 are ok):

10:58:38 **** regression.diffs ****
10:58:38 diff -U3 /tmp/autopkgtest.hS6MBA/tree/expected/pgsql.out /tmp/autopkgtest.hS6MBA/tree/results/pgsql.out
10:58:38 --- /tmp/autopkgtest.hS6MBA/tree/expected/pgsql.out    2021-06-25 08:58:37.138682292 +0000
10:58:38 +++ /tmp/autopkgtest.hS6MBA/tree/results/pgsql.out 2021-06-25 08:58:38.086673109 +0000
10:58:38 @@ -179,6 +179,7 @@
10:58:38  DELETE FROM bytea_fdw 
10:58:38    WHERE fid = 4;
10:58:38  DEBUG:  OGR SQL: (fid = 4)
10:58:38 +ERROR:  cannot find 'fid' column in table 'bytea_fdw'
10:58:38    
10:58:38  SELECT a.fid, a.name, b.name 
10:58:38    FROM bytea_local a 
10:58:38 @@ -189,6 +190,7 @@
10:58:38     1 | Jim    | Jim
10:58:38     2 | Marvin | Marvin
10:58:38     3 |        | 
10:58:38 -(3 rows)
10:58:38 +   4 | Maggie | Maggie
10:58:38 +(4 rows)
10:58:38  

I tried poking around in the source and got as far as getting rid of ERROR: cannot find 'fid' column in table 'bytea_fdw' using this patch:

--- a/ogr_fdw.c
+++ b/ogr_fdw.c
@@ -2804,7 +2804,7 @@ ogrExecForeignDelete(EState* estate,
                      TupleTableSlot* planSlot)
 {
        OgrFdwModifyState* modstate = rinfo->ri_FdwState;
-       TupleDesc td = planSlot->tts_tupleDescriptor;
+       TupleDesc td = slot->tts_tupleDescriptor;
        Relation rel = rinfo->ri_RelationDesc;
        Oid foreigntableid = RelationGetRelid(rel);
        int fid_column;

... but then the deleted row is still visible by the SELECT afterwards. (Replacing the other mentions of planSlot in that function by slot as well makes things segfault in PG13+.)

At the moment Debian is working around this by patching the expected output file to include the faulty output, but that's of course not a fix, and makes the tests fail with PG10..13 instead.

Could someone with more FDW knowledge please look here?

pramsey commented 2 years ago

This looks similar to issue #231 fixed here,

https://github.com/pramsey/pgsql-ogr-fdw/commit/376351712e9e89e0e0f18a4cf4fb35683368e748

Is it manifesting on the latest source?

df7cb commented 2 years ago

Oh right, it is indeed fixed there. Thanks!

I've opened #235 since the build is broken for PG 10+11 now. With that, things look fine everywhere.

Could you tag a new release with all the fixes?

pramsey commented 2 years ago

Thank you!

pramsey commented 2 years ago

Tagged. https://github.com/pramsey/pgsql-ogr-fdw/releases/tag/v1.1.2

df7cb commented 2 years ago

Thanks!