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 subject filters in schema relation delete to force use of the index #2131

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

josephschorr
Copy link
Member

This should allow for much faster queries under the transaction

@github-actions github-actions bot added the area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) label Nov 12, 2024
@@ -11,64 +11,305 @@ import (
"github.com/authzed/spicedb/pkg/datastore"
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
"github.com/authzed/spicedb/pkg/schemadsl/input"
"github.com/authzed/spicedb/pkg/tuple"
)

func TestApplySchemaChanges(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are missing a test with wildcards


subjectSelectors := make([]datastore.SubjectsSelector, 0, len(previousRelation.TypeInformation.AllowedDirectRelations))
for _, allowedType := range previousRelation.TypeInformation.AllowedDirectRelations {
if allowedType.GetRelation() != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this worked by happenstance, but the ellipsis was not being handled correctly, as it's not modeled as empty string at this level of the stack, but ....

There is also no explicit handling of wildcards, but my understanding is that's modeled as an userset_object_id = *, but userset_relation = "", so it ended up falling in ellipsis branch, which would generate the wrong SubjectRelationFilter.

I've force-pushed the changes, let me know what you think

This should allow for much faster queries under the transaction. We
observed some customers reporting timeouts when writting a new
schema and dropping a relation because it ended up in full table
scans.
Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I force pushed the changes, if you think they look fine, we can approve this.

We have some examples on how to test for Datastore API calls selecting specific indexes, I'd suggest adding a test to make sure this does not regress, but also confirm that what we wanted to achieve actually is happening.

@vroldanbet vroldanbet marked this pull request as ready for review November 13, 2024 18:00
@vroldanbet vroldanbet requested a review from a team as a code owner November 13, 2024 18:00
@vroldanbet vroldanbet added this pull request to the merge queue Nov 13, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 13, 2024
@josephschorr josephschorr added this pull request to the merge queue Nov 13, 2024
Merged via the queue into authzed:main with commit d1a7873 Nov 13, 2024
22 checks passed
@josephschorr josephschorr deleted the relation-remove-filters branch November 13, 2024 18:30
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants