Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

[tx] Interpret transact input with set semantics, like Datomic #532

@rnewman

Description

@rnewman

Consider simple input like this:

[:db/add "foo" :thing/unique "x"]
[:db/add "foo" :thing/v 92]
[:db/add "bar" :thing/unique "x"]
[:db/add "bar" :thing/s true]

"foo" and "bar" are intended to be temporary IDs for the same entity. However, if that entity does not already exist in the store — that is, if a search with :thing/unique "x" returns no results — a new entid will be allocated for each, and insertion will fail.

.t [{:db/ident :thing/unique :db/valueType :db.type/string :db/cardinality :db.cardinality/one :db/unique :db.unique/identity :db/index true}]
.t [{:db/ident :thing/v :db/valueType :db.type/long :db/cardinality :db.cardinality/many}]
.t [{:db/ident :thing/s :db/valueType :db.type/boolean :db/cardinality :db.cardinality/one}]
.t [[:db/add "foo" :thing/unique "x"]
[:db/add "foo" :thing/v 92]
[:db/add "bar" :thing/unique "x"]
[:db/add "bar" :thing/s true]]
Error(MentatError(DbError(Msg("Could not update datoms: failed to add datoms not already present"))), State { next_error: Some(SqliteFailure(Error { code: ConstraintViolation, extended_code: 2067 }, Some("UNIQUE constraint failed: datoms.a, datoms.value_type_tag, datoms.v"))), backtrace: None }).

Fixing this means deducing equivalence between a graph of related tempids, so that only a single entid is allocated for equivalent entity placeholders. This is what the transactor does when it handles upserts, so it might be best to fix it there, perhaps by inserting collections of datoms grouped by tempid-entity in order that other tempid searches can succeed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions