Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf/5901~1
Choose a base ref
...
head repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cf/5901
Choose a head ref
  • 2 commits
  • 3 files changed
  • 3 contributors

Commits on Jul 30, 2025

  1. Allow DELETE/UPDATE on partitioned tables with foreign partitions

    Currently, DELETE or UPDATE on a partitioned table with foreign partitions
    fail with an error as below, if the FDW does not support the operation:
    
    	`ERROR: cannot delete from foreign table`
    
    This occurs because during executor initialization (ExecInitModifyTable),
    PostgreSQL scans all partitions of the target table and checks whether each one
    supports the requested operation. If any foreign partition's FDW lacks support
    for DELETE or UPDATE, the operation is rejected outright, even if that
    partition would not be affected by the query.
    
    As a result, DELETE/UPDATE operations are blocked even when they only target
    non-foreign partitions. This means the system errors out without considering
    whether foreign partitions are actually involved in the operation. Even if no
    matching rows exist in a foreign partition, the operation still fails.
    
    This commit defers the FDW check for foreign partitions from
    `ExecInitModifyTable` to `ExecDelete` and `ExecUpdate`. This change ensures
    that foreign partitions are checked only when they are actually targeted by the
    operation.
    
    However, if a DELETE or UPDATE is issued on the root partition and it includes
    foreign partitions that do not support the operation, it will still result in
    an error. This is intentional because the responsibility for managing data in
    foreign partitions lies with the user. Only after the user has removed relevant
    data from those foreign partitions will such operations on the root partition
    succeed.
    
    ** Mini repro: **
    ```
    CREATE EXTENSION file_fdw;
    CREATE SERVER file_server FOREIGN DATA WRAPPER file_fdw;
    CREATE TABLE pt (a int, b numeric) PARTITION BY RANGE(a);
    CREATE TABLE pt_part1 PARTITION OF pt FOR VALUES FROM (0) TO (10);
    INSERT INTO pt SELECT 5, 0.1;
    INSERT INTO pt SELECT 6, 0.2;
    
    CREATE FOREIGN TABLE ext (a int, b numeric) SERVER file_server OPTIONS (filename '/Users/sshirisha/workspace/postgres/src/test/regress/data/test_data_float.csv', format 'csv', delimiter ',');
    ALTER TABLE pt ATTACH PARTITION ext FOR VALUES FROM (10) TO (20);
    postgres=# SELECT * FROM pt;
     a  |  b
    ----+-----
      5 | 0.1
      6 | 0.2
     15 | 0.3
     21 | 0.4
    (4 rows)
    ```
    
    ** Before Fix: **
    ```
    postgres=# DELETE FROM pt WHERE b = 0.2;
    ERROR:  cannot delete from foreign table "ext"
    postgres=# DELETE FROM pt;
    ERROR:  cannot delete from foreign table "ext"
    
    postgres=# UPDATE pt set b = 0.5 WHERE b = 0.1;
    ERROR:  cannot update foreign table "ext"
    postgres=# UPDATE pt SET b = 0.5;
    ERROR:  cannot update foreign table "ext"
    ```
    
    ** After Fix: **
    ```
    postgres=# DELETE FROM pt WHERE b = 0.2;
    DELETE 1
    postgres=# DELETE FROM pt;
    ERROR:  cannot delete from foreign table "ext"
    
    postgres=# UPDATE pt SET b = 0.5 WHERE b = 0.1;
    UPDATE 1
    postgres=# UPDATE pt SET b = 0.5;
    ERROR:  cannot update foreign table "ext"
    ```
    
    Co-authored-by: Ashwin Agrawal <[email protected]>
    2 people authored and Commitfest Bot committed Jul 30, 2025
    Configuration menu
    Copy the full SHA
    8d9b107 View commit details
    Browse the repository at this point in the history
  2. [CF 5901] v1 - Proposal to allow DELETE/UPDATE on partitioned tables …

    …with unsupported foreign partitions
    
    This branch was automatically generated by a robot using patches from an
    email thread registered at:
    
    https://commitfest.postgresql.org/patch/5901
    
    The branch will be overwritten each time a new patch version is posted to
    the thread, and also periodically to check for bitrot caused by changes
    on the master branch.
    
    Patch(es): https://www.postgresql.org/message-id/CAP3-t0-s-O8sV8bk85QYw-ancYOMrvf+3RieS5zd_qYxYJtTKg@mail.gmail.com
    Author(s): Shirisha V
    Commitfest Bot committed Jul 30, 2025
    Configuration menu
    Copy the full SHA
    5cd9799 View commit details
    Browse the repository at this point in the history
Loading