Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not move datoms which create variables used in functions/not-join which are inside or-join #1

Open
nikolayandr opened this issue Jan 6, 2021 · 3 comments

Comments

@nikolayandr
Copy link

nikolayandr commented Jan 6, 2021

Hi, sorry that I'm informing about issue instead to provide a solution, I just start to use this library in the java project which builds datalog queries from SQL dialect so Clojure is something very new for me :) Let me describe the cases when optimized queries became not executable by the datomic:

Original query:

[:find ?Root
:in ?typeName
:where
 [?Root :typeName ?typeName]
 (or-join [?Root] [(missing? ?Root :attribute)])
 ]

Optimized query is:

[:find ?Root
:in ?typeName
:where
 (or-join [(missing? ?Root :attribute)])
 [?Root :typeName ?typeName]
 ]

On attempt to execute such query Datomic says:
:db.error/insufficient-binding [?Root] not bound in expression clause: [(missing? $ ?Root :attribute)]

Similar situation is for a case when not-join is used within or-join
Original query:

[:find ?Root
:in ?typeName
:where
 [?Root :typeName ?typeName]
 (or-join
  [?Root]
  (not-join
    [?Root]
    [?Root :attribute _]
  )
 )
 ]

Optimized query is:

[:find ?Root
:in ?typeName
:where
 (or-join
  [?Root]
  (not-join
    [?Root]
    [?Root :attribute _]
  )
 )
 [?Root :typeName ?typeName]
 ]
@nikolayandr
Copy link
Author

But makes sense to mention for the case not-join within or-join that if there is condition within or-join which populates ?Root then [?Root :typeName ?typeName] can be put at the bellow of total query, so the next optimized query will be executed

[:find ?Root
:in ?typeName
:where
 (or-join
  [?Root]
  (not-join
    [?Root]
    [?Root :attribute _]
  )
 [?Root :attr ?value]
 )
 [?Root :typeName ?typeName]
 ]

@nikolayandr nikolayandr changed the title Do not move datoms which create variables used in functions or not-join which is inside or-join Do not move datoms which create variables used in functions/not-join which are inside or-join Jan 6, 2021
@nikolayandr
Copy link
Author

UPD: Sorry, I did mistake about functions, main condition to reproduce issue: a function should be within or-join

@benkamphaus
Copy link
Contributor

Thanks for the examples and good to see others are looking at using the library! Will reproduce and determine best resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants