-
Notifications
You must be signed in to change notification settings - Fork 3
support root collection column references #75
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
Conversation
// TODO: This selection illustrates that we end up looking up the relationship twice (once | ||
// with the key `class_students`, and then with the key `class_students_0`). This is | ||
// because the queries on the two relationships have different scope names. The query would | ||
// work with just one lookup. Can we do that optimization? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a ticket for this TODO as well please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, I filed https://hasurahq.atlassian.net/browse/MDB-164
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Supports root collection column references correctly. We were using
$$ROOT
which just refers to the current collection. Root references actually reference the collection of the nearest query up the tree in the query request. The query plan that we produce from a query request is structured differently, and hasQuery
values in positions where the request doesn't. So this PR introduces a "scope" concept in the query plan to capture the intended reference scopes from the request.A couple of notes here on how the MongoDB expressions are evaluated:
The special variable
$$ROOT
refers to the "current document" being processed by the pipeline. When we look up a relation we use a$lookup
stage which has it's own pipeline. If we reference$$ROOT
inside if the$lookup
pipeline then it resolves to documents in the related collection - the one we are looking up.On the other hand the
$lookup
stage also accepts alet
map to bind variables. When we reference$$ROOT
in a variable assignment in thislet
map it references the collection we are joining from, not the collection we are joining to. And then the variable bound in thelet
map is in scope in the$lookup
pipeline.MDB-6