This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-09
Channels
- # announcements (1)
- # babashka (14)
- # calva (8)
- # chlorine-clover (3)
- # clerk (6)
- # clj-kondo (27)
- # cljdoc (20)
- # clojars (6)
- # clojure (53)
- # clojure-denver (8)
- # clojure-europe (17)
- # clojure-nl (1)
- # clojure-norway (270)
- # clojure-uk (5)
- # clojurescript (35)
- # community-development (7)
- # cursive (12)
- # datalevin (3)
- # datomic (26)
- # etaoin (23)
- # exercism (1)
- # hyperfiddle (3)
- # java (14)
- # nrepl (2)
- # off-topic (12)
- # pathom (3)
- # portal (44)
- # practicalli (2)
- # reagent (7)
- # releases (1)
- # shadow-cljs (13)
- # timbre (3)
- # xtdb (4)
Is there any supported way to encourage a database datasource to use a particular index? I just wrangled with a query where I had the pattern [?e :ref-attr ?v]
and both ?e
and ?v
are bound, and it chose VAET then unified against ?e
, which was…not the right choice (4 million rows vs 1 row). My workaround was to use (datomic.api/datoms $ :aevt :ref-attr ?e ?v)
to force the index used, but wondered if there was a less hacky way
And honestly it still wasn’t great because it migrated the clause down further than I wanted
Hey @U09R86PA4, just trying to understand the scenario here. The following information would be very helpful to give me enough context to understand what's going on here: • The query you were running • https://docs.datomic.com/pro/api/query-stats.html + https://docs.datomic.com/pro/api/io-stats.html • Cardinalities of values for respective E/A (rough estimate is fine) • Schema for attributes used in the query To answer your question, boundness of your logic variables (along with other criteria) is what determines which index is consulted for answers, and you there currently isn't a way to influence which index the query engine consults. If you've encountered a scenario where the decision made by the query engine is highly insufficient, I think that's a very interesting scenario that I really want to better understand.
It’s a lot for me to put together. I can paste you the relevant stuff I still had in a buffer, it’s really quite straightforward
{:find [?wfs-idx ?story-pos ?entity-id],
:in [$ % [?type ...] [[?wfs-idx ?wfs]]],
:where [[?wfs :workflow-state/type ?type]
[(my-ns/wfs->story+pos $ ?wfs) [[?entity-id ?story-pos]]]]}
:clauses [{:clause [(ground $__in__3) [?type ...]],
:rows-in 0,
:rows-out 3,
:binds-in (),
:binds-out [?type],
:expansion 3}
{:clause [?wfs :workflow-state/type ?type],
:rows-in 3,
:rows-out 4312467,
:binds-in [?type],
:binds-out [?wfs],
:expansion 4312464}
{:clause [(ground $__in__4) [[?wfs-idx ?wfs]]],
:rows-in 4312467,
:rows-out 9,
:binds-in [?wfs],
:binds-out [?wfs ?wfs-idx]}
Oh very interesting! :bind-in [?type]
implies that the result set contained 3 rows consisting of only ?type
#{[?type] [?type] [?type]}
Do you observe different behavior if you pass ?wfs
in directly like this: :in [$ % [?type ...] ?wfs-idx ?wfs]
?
I’m not sure what you mean by “directly”, it’s already an in-var; your proposal just removes the destructuring?
You might also be able to force the query engine to bind ?wfs
early by placing a ground clause in the beginning (just to better understand if the delayed binding is what's causing the problematic join behavior).
Something like:
[(identity ?wfs) ?wfs2]
then use ?wfs2
in subsequent clauses
Obviously this wouldn't be a solution, but more to better understand what we're seeing here