Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#10 Error in sub-tx breaks tuplestore for cursor.

closed-fixed
pgsql_fdw (6)
5
2012-05-09
2012-04-26
Shigeru Hanada
No

pgsql_fdw seems to break tuplestore for a cursor when an error occurs in sub-transaction. We can recover from such error by rolling back to SAVEPOINT, but we can't access tuplestore any more. Second FETCH in the example below should succeed.

e.g. (pgbench_branches is a foreign table of pgsql_fdw)

postgres=# BEGIN;
BEGIN
postgres=# DECLARE c1 CURSOR FOR SELECT * FROM pgbench_branches;
DECLARE CURSOR
postgres=# SAVEPOINT s1;
SAVEPOINT
postgres=# FETCH c1;
bid | bbalance | filler
-----+----------+--------
1 | 0 |
(1 row)

postgres=# error out;
ERROR: syntax error at or near "error"
LINE 1: error out;
^
postgres=# ROLLBACK TO s1;
ROLLBACK
postgres=# FETCH c1;
ERROR: invalid tuplestore state

Discussion

  • Shigeru Hanada
    Shigeru Hanada
    2012-04-26

    • status: open --> closed-fixed
     
  • Shigeru Hanada
    Shigeru Hanada
    2012-04-26

    Fix pgsql_fdw to create tuplestore in Begin.

    If SAVEPOINT is set between DECLARE and first FETCH, and user rolls back to it after first FETCH, tuplestore is released undesirably in cleanup of the subtransaction which started at SAVEPOINT.

    We need to create tuplestore in the context of the transaction in which the query was initiated, so we moved tuplestore_begin_heap from IterateForeignScan to BeginForeignScan. This causes little overhead, but it's limited in the case when the scan is innter scan of a nested loop which has 0-row scan on outer, so such overhead seems ignorable.

    related commit: 624e0e26cc4301cd128efbc4c8cf1df1191c7c7a

     
  • Shigeru Hanada
    Shigeru Hanada
    2012-04-26

    • assigned_to: nobody --> shigeru-hanada
     
  • Shigeru Hanada
    Shigeru Hanada
    2012-04-26

    Sorry, relative commit is 9ee995d261b51aaf89656a30a86085f13f3d7773.

     
  • Shigeru Hanada
    Shigeru Hanada
    2012-04-26

    • status: closed-fixed --> open-fixed
     
  • Shigeru Hanada
    Shigeru Hanada
    2012-05-09

    • status: open-fixed --> closed-fixed