Ask questions on the official Q&A site at https://ask.datomic.com!
Kurt Sys 2020-12-20T13:36:28.139900Z

Just wondering, what exactly is the difference between :db/ident and :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)?

kennytilton 2020-12-29T15:00:55.189300Z

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!

favila 2020-12-20T14:28:48.144900Z

Datomic’s data model is assertion/retraction of facts, represented as datoms

favila 2020-12-20T14:29:50.146500Z

Datoms look like [eid attrid value txid op] where op is true or false for assertion or retraction

favila 2020-12-20T14:31:34.148800Z

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

Kurt Sys 2020-12-20T14:32:28.149600Z

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?

Kurt Sys 2020-12-20T14:32:56.150200Z

(e.g. when querying)

favila 2020-12-20T14:33:12.150800Z

Do you know what a lookup ref is?

Kurt Sys 2020-12-20T14:33:28.151400Z


favila 2020-12-20T14:33:49.152Z

You can think of idents as fundamentally lookup refs

favila 2020-12-20T14:34:39.153500Z

The attr is implied (it’s db/ident) and the indexing is special (they are kept in peer memory and they ignore retractions)

favila 2020-12-20T14:35:01.154300Z

But it’s still looking up an eid by the value of one of its datoms

Kurt Sys 2020-12-20T14:35:23.154500Z

right! I bit like: [:db/id &lt;some ident&gt;] lookup ref?

Kurt Sys 2020-12-20T14:35:36.154800Z

no, not entirely. sorry.

Kurt Sys 2020-12-20T14:35:51.155300Z

[:db/ident &lt;some ident&gt;] resolves to a unique :db/id

favila 2020-12-20T14:36:33.156500Z

Correct, but it doesn’t have the special properties of a raw lookup

favila 2020-12-20T14:36:48.157Z

Sorry, bare keyword syntax

Kurt Sys 2020-12-20T14:37:06.157300Z

ok, cool thx. It's only just another attribute, which happens to be unique?

favila 2020-12-20T14:38:00.158500Z

Yes, but it has special lookup syntax and uses special indexes so it’s faster and can be looked up even after retraction

favila 2020-12-20T14:38:18.159Z

But fundamentally it’s a value lookup

Kurt Sys 2020-12-20T14:38:30.159600Z

allright. I get it. Thx!

favila 2020-12-20T14:39:03.160500Z

I explained ident in terms of lookup ref, but historical note idents predate lookup refs by quite a bit

favila 2020-12-20T14:39:16.161Z

For quite a while datomic did not have lookup refs

Kurt Sys 2020-12-20T14:39:34.161200Z

🙂 - ok, well, in any case, it's pretty clear now.

Kurt Sys 2020-12-20T14:39:35.161400Z


favila 2020-12-20T14:40:09.162200Z

The special indexing is also why you should be careful about creating too many idents

Kurt Sys 2020-12-20T14:41:10.162400Z

oh, ok... well, 'too many' seems a bit vague to me, but I guess for most systems, this shouldn't be a big deal?

favila 2020-12-20T14:45:19.165400Z

If you keep it to schema-level, crafted-by-hand assertions that should be fine. It just shouldn’t be asserted on data

favila 2020-12-20T14:45:55.166600Z

(Hundreds of thousands or millions, on things that may be retracted)