Skip to content

Update on postgres impl is inefficient #988

Description

@thockin

Edit: This was originally about updates being non-atomic but I was wrong.

There does still seem to be a significant opportunity to optimize.

I am not a pgsql expert, so please correct me if I am wrong.

Jet Chiang (@supreme-gg-gg)

Roughly, it looks like:

Query:
          SELECT proto FROM actors
          WHERE atespace = $1 AND name = $2
          FOR UPDATE`, atespace, name

Unmarshal
call mutate(oldVal)
validate
Marshal

Query:
          UPDATE actors
          SET version = $1, proto = $2
          WHERE atespace = $3 AND name = $4`,
          dbActor.GetMetadata().GetVersion(), protoBytes, atespace, name

I am not a PGSQL expert but I thought "FOR UPDATE" requires a txn. Also gemini says not to use "FOR UPDATE" but "FOR NO KEY UPDATE". IIUC, also: row-locks are not auto-released, so we need to handle a crash mid-txn.

I assumed I would find something more like:

UPDATE actors
          SET version = $5, proto = $6
          WHERE atespace = $1 AND name = $2 AND uid = $3 AND version = $4,
          atespace, name, expectUid, expectVersion, newVersion, protoBytes

...and then check that it affected exactly 1 row.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/apiUser-facing API changesarea/storagekind/bugSomething isn't working / bugfixesprio/P1Important but not critical

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions