-
Notifications
You must be signed in to change notification settings - Fork 648
Update view ABI to support returning queries #3685
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
base: master
Are you sure you want to change the base?
Conversation
joshua-spacetime
left a comment
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 you update the bindings to use the new ABI?
| return Ok(Vec::new()); | ||
| } | ||
|
|
||
| // Views bypass RLS. |
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.
I would mention why here. One of the reasons being that views are module-defined and access control can always expressed procedurally if need be.
|
|
||
| for plan in plans { | ||
| // Track read sets for all tables involved in this plan. | ||
| // TODO(jsdt): This means we will rerun the view and query for any change to these tables, so we should optimize this asap. |
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.
Even if they aren't incremental at first, we should probably still track index reads so that the performance is at least on par with procedural views.
| (res, trapped) | ||
| } | ||
|
|
||
| fn run_query_for_view( |
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.
I would add a comment that the return rows have not been transformed for insert into the view's backing table.
Description of Changes
This adds some changes for how we return data from view functions. Originally, we interpreted the output of a view function as a bsatn encoding of an array of rows. Since we also want to be able to return queries from view functions, we need to be able to return different types too. At this point, this is effectively not a functional change, since we don't use the new format, and we don't actually try to parse the new format.
This introduces a new format for view returns, which is a
ViewResultHeader, potentially followed by additional data. For example, if a view were returning rows directly, it would write aViewResultHeader::RowData, followed by an array of rows. Note that we could have given that object a byte array with the rows instead of using a header an a separate object, but that would force us create an extra copy when encoding and when decoding.To make this backward compatible with existing views, we have a different way to return the new format. For v8 views, if they return a byte array, we assume it is the old format. If they return an object, we expect the
datafield of that object to be the actual return data.For wasm views, we interpret a return code of 2 to mean that it uses the new format.
On the host side, we handle this naively: we will perform the query, and we will act as though the view has a read dependency on the tables in the query. In follow up PRs we can make this more efficient.
API and ABI breaking changes
This is not a breaking change, but it does make the ABI more complicated (specifically to avoid breaking it).
Expected complexity level and risk
1.5. This should not affect the existing return style.
Testing
I've done manual testing of this with a version of the typescript bindings that returns queries.