datalevin

sundbp 2026-02-12T16:31:59.053079Z

You're making great progress on datalevin lately - fantastic work!

2
prnc 2026-02-12T18:16:08.986069Z

Given a connection conn open with (d/get-conn ...), is using (d/search ...) API supported? E.g. via (d/search (-> conn deref .store .search-engines (get "datalevin")) "query") or is that not meant to be accessed like this and should be considered internal/impl.? Of course one can search via (fulltext ...) built in, in a datalog query, I’m just curious if (d/search ...) should be used like this?

Huahai 2026-02-12T18:17:14.322199Z

search is for standalone search engine, not for Datalog DB.

Huahai 2026-02-12T18:19:35.121119Z

It's not meant to be accessed like that. With WAL mode, that access path wouldn't even work correctly, because there will be in-memory overlay.

prnc 2026-02-12T18:20:00.885749Z

OK, I thought so, thanks for confirming!

jumraiya 2026-02-12T20:10:27.658749Z

I can't seem to run a query where I have inputs for the outer query and subquery. This gives an error cannot parse binding . Is this expected?

(d/q
 '[:find ?b
   :in $ ?a
   :where
   [(q
     [:find ?b
      :in $ ?a
      :where
      [?a :attr-2 ?b]]
     $ ?a)
    ?b]]
 [[1 :attr 2]] 1)

Huahai 2026-03-01T06:35:55.151029Z

Master branch has a fix.

jumraiya 2026-02-21T15:35:52.116149Z

https://github.com/datalevin/datalevin/issues/354

šŸ‘ 1
Huahai 2026-02-21T22:09:12.794839Z

thx

jumraiya 2026-02-13T11:48:51.802019Z

Thanks, the reason I was trying to use a sub query was to get the max value of an attribute and use it in the outer query.

Huahai 2026-02-13T15:48:28.636489Z

By max value, you mean the whole DB max of the attribute, or max under the query condition?

Huahai 2026-02-13T16:07:30.377999Z

If it is the former, it's better to pass that max value in as a parameter, if it is the later, or-join or not-join

jumraiya 2026-02-13T21:00:41.192549Z

The latter, so let's say I have two attributes for an entity :category , :score and given a category I want to find the entity with the max score how can I do that in an or-join? It was my impression aggregate functions only work in a query. This is what I had

[:find ?e
[?e :category "cat"]
[(d/q [:find (max ?score) .
    :in $
    :where 
     [?ev :fire/category "cat"]
     [?ev :score ?score]] $) 
     ?score]
[?e :score ?score]]

Huahai 2026-02-13T21:29:54.860819Z

this query can be solved with not-join:

[:find ?e .
   :where
   [?e :category "cat"]
   [?e :score ?score]
   (not-join [?score]
     [?other :category "cat"]
     [?other :score ?other-score]
     [(> ?other-score ?score)])]

Huahai 2026-02-13T21:30:37.737169Z

This reads as: "find ?e with category "cat" and score ?score, such that no other entity with the same category has a strictly greater score."

Huahai 2026-02-13T21:32:37.125949Z

This will be much much more efficient than nested q.

jumraiya 2026-02-13T21:41:00.904579Z

I see, thank you

jumraiya 2026-02-13T22:03:43.645289Z

I was experimenting around with this and found that putting this logic inside a rule triggers a parsing error, I will try to find the root cause.

(d/q
 '[:find ?e
   :in $ %
   :where
   (entity-by-category ?e "cat")]
 db
 '[[(entity-by-category ?e ?cat)
    [?e :category ?cat]
    [?e :score ?score]
    (not-join [?score ?cat]
              [?other :category ?cat]
              [?other :score ?other-score]
              [(> ?other-score ?score)])]])

Huahai 2026-02-14T05:48:06.964339Z

file a GitHub issue if it is a bug.

Huahai 2026-02-13T04:05:31.657689Z

In general, I would not write nested q like this. q is treated as a regular query function that is invoked for every tuple. It will have horrible performance. Subquery behavior can be had with or-join or not-join

Huahai 2026-02-13T04:08:43.098329Z

As to this one, you can try it in datascript/datomic, if this works in them, file a GitHub issue, we can fix it.