datomic

frankitox 2025-10-16T18:51:39.369729Z

Hello 👋 I have a schema to which I'd like to add a lot of :db/index true to improve query performance. I'm assuming this will trigger a job to add the entities to the AVET index. How can I monitor how long this job takes? I'm hesitant of transacting all the :db/index true in one go

favila 2025-10-20T13:45:48.809479Z

You generally only add an index if you need it. Do you need it? Do you lookup or seek entities by value or have queries where the first clause is a range of values?

frankitox 2025-10-20T13:53:16.824999Z

Thanks for answers! I like sync-schema because it could give me a basic idea of how long the database is being stressed. About the real need for indexes, I thought of just adding it for as many attributes as I can, mostly out of lazyness. I'll do some basic research on the queries via with-redefs 🤔 .

favila 2025-10-20T13:59:03.699669Z

why with-redefs?

frankitox 2025-10-20T14:01:05.685199Z

Mostly to collect some queries in an atom and inspect them (hooking into d/q )

favila 2025-10-20T14:09:05.897789Z

do you not have access to the code of these queries? or are the queries dynamic?

frankitox 2025-10-20T14:46:10.632519Z

I do have access. I rather do that because I can browse around the most relevant parts of the website and see what queries are hit. Also yes, some queries are dynamic

Lambda/Sierra 2025-10-18T18:29:25.943329Z

You can call https://docs.datomic.com/schema/schema-change.html#adding-an-avet-index-to-an-attribute to wait until a new index is ready.

Lambda/Sierra 2025-10-18T18:31:06.000259Z

You might also want to watch the metrics on the transactor while indexing to make sure it's not overwhelmed.

frankitox 2025-10-27T14:21:38.615409Z

> You generally only add an index if you need it. Do you need it? Do you lookup or seek entities by value or have queries where the first clause is a range of values? @favila I was just reading this https://building.nubank.com/optimizing-datomic-queries/ and noticed this query:

{:query '{:find  [?album-name ?year]
          :in    [$ ?artist-name]
          :where [[?artist :artist/name ?artist-name]
                  [?release :release/artists ?artist]
                  [?release :release/year ?year]
                  [(< ?year 1970)]
                  [?release :release/name ?album-name]]}
 :args  [db "John Lennon"]}
In it, it makes initial sense to use :db/index true for :artist/name . Would you also gain in performance by using it with :release/artists?

favila 2025-10-27T16:41:46.958599Z

not for this query; [?release :release/artists ?artist] where ?artists is bound will only ever use VAET; AVET provides no benefit and wouldn't even be consulted.

frankitox 2025-10-27T16:52:00.589529Z

Oh, right! Thanks 🙏

favila 2025-10-27T16:53:05.301519Z

even the :release/year clause doesn't use AVET

frankitox 2025-10-27T16:57:11.694439Z

Well, that one may use EAVT, I guess? 🤔

favila 2025-10-27T16:57:57.751069Z

datalog query prefers AEVT over EAVT

👍 1
ghadi 2025-10-16T22:05:34.205249Z

"a lot of db/index" may not make sense

ghadi 2025-10-16T22:06:05.995369Z

you should paste the output of q with :query-stats true and :io-stats, if possible

ghadi 2025-10-16T22:06:46.623569Z

it's probable that adding only one attr index matters

frankitox 2025-10-17T03:34:46.870879Z

> "a lot of db/index" may not make sense I mean I'll add to a lot of attributes of the schema :db/index true. Does that make sense? 🤔 I found that we are barely using :db/index and the https://docs.datomic.com/indexes/index-model.html#usage-notes state > Attributes that are going to be queried by value need to be marked as :db/index true or :db/unique.