Fork me on GitHub

this is sort of related to datomic, so I thought I might find people who knew here: is it possible to statically analyze a query and always know all of the attributes that a query depends on?


No, as attrs to match can be input, dynamically built, or you can call an arbitrary function


> dynamically built can you show me what you mean by that? the other two make sense


[?e :use-attr ?attr] [?e ?attr ?v]

😲 4

got it. thank you!


[(keyword ?foo ?bar) ?attr] [?e ?attr ?v]


[(rand-int 1 1000) ?attr] [?e ?attr ?v] 😏


@lvbarbosa @favila I’m struggling with the same problem, but I want to match on multiple attributes and the matches to exclude is stored in datomic as well (not as separate input). E.g. a list of items:

 {:item/department "D1" :item/type "A"}
 {:item/department "D1" :item/type "B"}
 {:item/department "D1" :item/type "C"}
 {:item/department "D2" :item/type "B"}
 {:item/department "D3" :item/type "A"}
 {:item/department "D3" :item/type "C"}
And a list of tuples with [dep type]s to hide:
{:item/hidden [["D1" "A"] ["D3" "C"]]}
I got it working with the following query:
(d/q {:query '[:find (pull ?item [...])
               [?item :item/department ?dep]
               [?item :item/type ?type]
               [(tuple ?dep ?type) ?dep+type]
               [(q '[:find (set ?hidden)
                     :where [_ :item/hidden ?hidden]] $) [[?results]]]
               (not [(contains? ?hidden ?dep+type)])]
      :args [db]})
But I’m not sure about using the set function in the find clause of the subquery (it’s not documented). And I’m not sure if there is an easier/more performant way to do it


use distinct instead of set (honestly it might just be an alias for set)


Your query works? I don’t see how the ?hidden in your last clause is bound


I would move building the hidden set up higher. you can also issue two queries


supplying the output of one as the input to the next


this isn’t great because it can’t make use of indexes


I adjusted my actual case and typed it over, so it has an error. The ?hidden should be ?results.


Does distinct always yield a set? I assumed it would be a seq, like clojure.core/distinct.


Thanks for the feedback, I’ll try different approaches to see if there is a performance difference


consider an initial filter using the most selective part of the tuple


so that you can make use of any value indexes on item-department or item-type


alternatively, make a composite index and match against that instead


(probably a better option anyway)


hi, does someone know how to get statistics of Datomic database (total size, size by entity, index size …)?


i have a need to rename two db idents, and then repurpose their old idents as new attributes (which i know isn't recommended). i started by aliasing the old entities with their new idents, and then transacted two new attributes with the old idents as i would like any new attribute definition. one ident was repurposed successfully -- a value type of long. but the other, which was/is a reference, throws an exception: Ident :player/details cannot be used for entity 666, already used for :new-player/details . Is it possible to repurpose an ident which was previously claimed by a reference attribute?


that sounds like a uniqueness violation


does the schema of the one that didnt “repurpose” include a uniqueness attribute?


the failed repurposed ident was originally claimed by a ref attribute which was included in a unique composite tuple. i removed the unique constraint on that tuple, but i still get the same exception.


looking at the alias, and the tuple attr which refers to that alias, neither have a unique constraint


so the whole thing looks more like this: 1. :player/details, claimed by a ref attribute, aliased to :new-player/details 2. :player/details+region tuple attribute aliased to :new-player/details+region 3. unique by identity constraint removed from :new-player/details+region tuple attribute 4. transact {:db/ident :player/details :db/valueType :db.type/ref :db/cardinality :db.cardinality/one}

Ident :player/details cannot be used for entity 666, already used for :new-player/details