Add binds for affected IDs in compiled rules #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After every write, pine has to rerun all rules from the model to ensure consistency. These rules run over the entire database, sometimes causing some queries to run for too long against what should be a simple write.
This commit adds a mechanism to help with this issue by narrowing the set of rows that each rule should touch to those rows that were actually changed.
Implementing this mechanism safely is doable and not necessarily complex code-wise, but requires a deep modifications from the current architecture. This commit adds a restricted form instead where we only narrow the rows of the root table that were changed. If any other table was changed then narrowing is a no op.
It can be proved that this is always safe as long as the root table is selected from only once and the rule is positive ("It is necessary that each ...").
The implementation here adds a single binding into the rule's SQL query which can be bound by pine for each rule where an opportunity to use this optimization arises.
The implementation itself is simple: count how many times the root table is selected from and if it is selected from exactly one, then add a narrowing constraint in the form of:
Where
$1
will be bound to either'{}'
, which disables narrowing, or to a list of IDs that were affected by the write.This initial implementation can be extended in the future.
Change-type: major
Signed-off-by: Carol Schulze [email protected]