Just wondering, what exactly is the difference between
:db/id in Datomic? Is it like:
db/id is the 'internal id', and
:db/ident is an 'external id' (which should be something that makes sense to humans)?
Hey, @favila. I am a Datomic noob myself, so caveat lector, but this same ident vs id threw me as well. I did some digging/learning and came up with this epiphany: Datomic is a symbolic database, just as Lisp is a symboic language. The :db/ident attribute is how "symbols" are created. Importantly, these ident/symbols are the only things guaranteed by a future Datomic export/import mechanism. I had thought :db/ids would be that, but no, and that makes sense if idents/symbols have object identity. And <gasp> this is why we do not want to make "too many", just as in Lisp we are careful about loading up the symbol space. Final tip: one fun thing to do is create a new database and then examine the contents. We see Datomic is also a self-hosted DB, creating the primordial idents over a sequence of early transactions, including the ident :db/ident itself. Fun stuff!
Datomic’s data model is assertion/retraction of facts, represented as datoms
Datoms look like [eid attrid value txid op] where op is true or false for assertion or retraction
That’s what’s actually in the db.
:db/id in a map projection is representing the eid that is common to all the datoms projected into the map
yeah, that's how far I got right now... But we can use a
:db/ident instead of
:db/id , with
:db/ident a more readable id?
(e.g. when querying)
Do you know what a lookup ref is?
You can think of idents as fundamentally lookup refs
The attr is implied (it’s db/ident) and the indexing is special (they are kept in peer memory and they ignore retractions)
But it’s still looking up an eid by the value of one of its datoms
right! I bit like:
[:db/id <some ident>] lookup ref?
no, not entirely. sorry.
[:db/ident <some ident>] resolves to a unique
Correct, but it doesn’t have the special properties of a raw lookup
Sorry, bare keyword syntax
ok, cool thx. It's only just another attribute, which happens to be unique?
Yes, but it has special lookup syntax and uses special indexes so it’s faster and can be looked up even after retraction
But fundamentally it’s a value lookup
allright. I get it. Thx!
I explained ident in terms of lookup ref, but historical note idents predate lookup refs by quite a bit
For quite a while datomic did not have lookup refs
🙂 - ok, well, in any case, it's pretty clear now.
The special indexing is also why you should be careful about creating too many idents
oh, ok... well, 'too many' seems a bit vague to me, but I guess for most systems, this shouldn't be a big deal?
If you keep it to schema-level, crafted-by-hand assertions that should be fine. It just shouldn’t be asserted on data
(Hundreds of thousands or millions, on things that may be retracted)