Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Why we spent the last month eliminating Postgres substransactions (about.gitlab.com)
15 points by quantumwoke on Sept 30, 2021 | hide | past | favorite | 2 comments


The motivating example for this seems to be completely broken:

    --- Start a transaction
    BEGIN
    SAVEPOINT active_record_1
    --- Look up the account
    SELECT * FROM credit_accounts WHERE customer_id = 1
    --- Insert the account; this may fail due to a duplicate constraint
    INSERT INTO credit_accounts (customer_id) VALUES (1)
    --- Abort this by rolling back
    ROLLBACK TO active_record_1
    --- Retry here: Start a new subtransaction
    SAVEPOINT active_record_2
    --- Find the newly-created account
    SELECT * FROM credit_accounts WHERE customer_id = 1
    --- Save the data
    RELEASE SAVEPOINT active_record_2
    COMMIT
The second SELECT will never see the newly added row because it's still operating against the same snapshot as the outer transaction, so the use of subtransactions is completely pointless?


Excellently written article!




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: