Skip to content

PgRelation::heap_relation should have a heap_relation_with_lock alternative #2140

Description

@ccleve

PgRelation has this code in it:

    pub fn heap_relation(&self) -> Option<PgRelation> {
        // SAFETY: we know self.boxed and its members are correct as we created it
        let rd_index: PgBox<pg_sys::FormData_pg_index> =
            unsafe { PgBox::from_pg(self.boxed.rd_index) };
        if rd_index.is_null() {
            None
        } else {
            Some(unsafe { PgRelation::open(rd_index.indrelid) })
        }
    }

PgRelation::open() does not lock the heaprel, which means that if you use it for anything and another process tries to modify it, you might get a race condition. Am I understanding this correctly?

Would it not make more sense to replace the PgRelation::open() line with:

Some(unsafe{PgRelation::with_lock(rd_index.indrelid, self.lockmode)})

I hesitate to submit a PR in case I've missed something here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions