Fork me on GitHub
#xtdb
<
2022-09-07
>
Mikko Harju11:09:00

Question re: datalog – Is there a possiblity to do and matching to an input collection? :in [[?entity-id ...]] matches entries as or – I can just map with gensym and conj those entries to the query but I was just wondering have I misunderstood something? 🙂

Mikko Harju11:09:08

This is how it works like I expected – is there an easier way?

refset15:09:18

Hey @U32ST9GR5 I can't recall ever tackling a problem exactly this shape before, but I actually think your query generation is the only sane way to do this whilst working with the index and query engine mechanics (vs. pulling out collection values and calling clojure.set/subset? predicates, or whatever)

refset15:09:28

I think your query can be simplified though - this pattern isn't need: [?user :xt/id ?user-id] because the thing in the ID position is the ID. So ?user and ?user-id will be the exact same thing. Similarly for your [~skill-ent :xt/id ~skill-id] - it shouldn't be needed. Reducing clauses should also boost performance as the query engine won't otherwise attempt to algebraically simplify such things

👍 1
refset15:09:14

I suppose it's most similar to the Suduko-solver-in-XT-Datalog I wrote once (yet to publish as a blog post...), inspired by the general approach here http://conway.rutgers.edu/~ccshan/wiki/blog/posts/Sudoku_in_SQL/ - I did get it working, but it took me down a rabbit hole reflecting on pros/cons vs SMT solvers / core.logic / etc.

😎 1
Mikko Harju16:09:38

Thanks!

🙏 1
refset22:09:51

(a little less ramble-y than my Sudoku gist / draft blog post!)

👍 1
tatut07:09:55

could a [(subset? $ ?user :core/skill skills-set-in-parameter)] type of predicate be made efficiently in user land?

tatut07:09:54

a custom predicate function would need to consider all users afaict

refset08:09:23

Yep that could work as a way of hiding the complexity behind an abstraction, I think, good suggestion

tatut08:09:54

one could of course make a preprocessor that “compiles” a subset check into separate where clauses for each value in the set