Fork me on GitHub
#datalevin
<
2022-06-16
>
mokr08:06:25

Hi, does Datalevin support a query limit to get e.g. just 10 results? I’ve been trying the map-args version of q as suggested https://ask.datomic.com/index.php/446/ability-to-limit-the-number-of-results-from-query?show=533#a533 , but can’t get it to work. I see that that map-args variant of q is in fact mentioned in the https://docs.datomic.com/on-prem/query/query.html#pattern-inputs linked in Datalevins doc string for q, but is it actually supported? Simple experiment with map-args:

(def my-query '[:find [?email ...]
                  :where
                  [_ :user/email ?email]])

  ;; OK
  (d/q my-query @db/conn)

  ;;NOK: Execution error... Cannot parse :find ...
  (d/q {:query my-query
        :args  [@db/conn]})

Huahai09:06:19

Query in the map form should be fine, as the vector query is turned into a map anyway. However, I don’t think limit is currently supported. You can file an issue. We work through the issues whenever we can.

mokr10:06:56

OK, thanks. Should the {:query … :args […]} syntax itself work? Based on the Datomic example I was hoping for something like this where find is still in vector form, but wrapped in a map:

(d/q {:query   '[:find [?email ...]
                 :where
                 [_ :user/email ?email]]
      :args    [@db/conn]
      :limit   10
      :offset  20
      :timeout 60000})
Disregarding missing support for :limit (and possibly :offset and :timeout) at the moment.

Huahai11:06:27

the supported map is for the query itself

Huahai11:06:45

This format you are showing is probably not the version of Datomic on-prem that Datascript was modeled against. However, I think these are superficial differences that reflect how Datomic is specifically implemented. I would probably put these features in the query itself to have a more consistent and simpler query API. We refer people to Datomic’s documentation for we have not had the time to write our own, so people shouldn’t expect the same API. Good documentation will be available when we reach 1.0.

Huahai11:06:02

in any case, file an issue and we will get to them eventually. Right now, my priority is to finish the query engine rewrite, so I can feel comfortable promoting this project.

mokr11:06:57

Thanks for the clarification. I’ll file an issue in the next few days. For now I just limited the result with take and I think that will work just fine.

Huahai11:06:56

I suspect “take” is how datomic is implementing the limit, hence these things are at a layer outside the query.

Huahai11:06:25

Ideally, these should be part of the query, so query engines can optimize them better.

Huahai11:06:36

In my opinion, Datalevin’s query engine has more potential to optimize things, since it follows a traditional database architecture.

Huahai12:06:56

Not heeding the lessons of an half century of database research has its pitfalls.

👍 1
baibhavbista12:07:30

@U0A74MRCJ on the basis of this thread and the datalevin API, it seems query timeout is not supported at the moment, right? If yes, and in case you would want a PR for this, do you have any pointers as to how one would go about adding it?

Huahai20:07:56

I don’t have nay pointers. You can propose some approaches.