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

Add documentation for "Clause order of advanced query" #60

Open
cnrpman opened this issue Jan 11, 2023 · 0 comments
Open

Add documentation for "Clause order of advanced query" #60

cnrpman opened this issue Jan 11, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@cnrpman
Copy link
Collaborator

cnrpman commented Jan 11, 2023

A main blame of query issue is actually about clause order of queries.
We should setup a FAQ on the forum https://discuss.logseq.com/c/faq/6 to help saving the communication cost of the process. Then make it to the document.

References:
https://docs.logseq.com/#/page/advanced%20queries
https://docs.datomic.com/on-prem/query/query-executing.html#clause-order
https://github.com/logseq/logseq/blob/d0af76d513407f660946d9c957cf2786f430e2a2/deps/db/src/logseq/db/rules.cljc#L26-L62

The clauses are executed sequentially.
If you mention a binding in a clause that is not mentioned at all in the previous section,
it will do a full-text search, which will be very slow
So you should try to use up the input in the first order, and keep the conditions small
To narrow the scope step by step

For example, if the input is ?cn:

[?b :block/page ?p] ;; This clause has no constraints, so don't put it here
[?cd :block/name ?cn]
[?b :block/path-refs ?cd]
(not [?b :block/page ?cd])

should be changed to
[?cd :block/name ?cn]
[?b :block/path-refs ?cd]
(not [?b :block/page ?cd])
[?b :block/page ?p] ;; wait for the previous clause to narrow down, then execute the unqualified clause

@cnrpman cnrpman added the documentation Improvements or additions to documentation label Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Development

No branches or pull requests

1 participant