[query] Constraint-based algebrizing #147
Labels
No labels
A-build
A-cli
A-core
A-design
A-edn
A-ffi
A-query
A-sdk
A-sdk-android
A-sdk-ios
A-sync
A-transact
A-views
A-vocab
P-Android
P-desktop
P-iOS
bug
correctness
dependencies
dev-ergonomics
discussion
documentation
duplicate
enhancement
enquiry
good first bug
good first issue
help wanted
hygiene
in progress
invalid
question
ready
size
speed
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: greg/mentat#147
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The current algebrizer — mainly
ConjoiningClauses
— is deliberately procedural and predictable. Paired with the simple query translator, we quite directly translate Datalog into SQL.CC performs two roles: it tracks the metadata it needs to not be completely clumsy (the types deduced for variables and known bindings), and it accumulates some information that should really be part of a planner: table allocations and mappings between their columns and variables.
Again, that works fine for simple and predictable translation.
Extending this approach, however, to attain more power gets… hacky.
[:find ?x :where [?x :db/ident :foo/bar]]
).[:find ?x :where [?x :foo/age ?z][?y :foo/age ?o] [(!= ?x ?y)] [(> ?z 20)] [(< ?o 30)] [(> ?o ?z)]]
we can derive a lower bound for?o
).[:find ?x :where [?x ?y :foo/bar]]
can deduce the value of?y
in the current database from the schema alone, and[:find ?x :where [?x ?y true] [?z ?y ?z]]
can never bind a single?y
).At some point it might be worthwhile to more fully separate algebrize+translate into algebrize+plan+translate, with the algebrizing stage being primarily a constraint system used to derive something like CC.
The risk of doing so is that the planner input would be less ordered, and thus the translated output would likely be less predictable and less related to the input. Small changes to the input query could cause large changes to what we can deduce.