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

Updating non indexed field of doc with unique index fails #2510

Closed
fredcarle opened this issue Apr 9, 2024 · 0 comments · Fixed by #2511
Closed

Updating non indexed field of doc with unique index fails #2510

fredcarle opened this issue Apr 9, 2024 · 0 comments · Fixed by #2511
Assignees
Labels
bug Something isn't working priority/high
Milestone

Comments

@fredcarle
Copy link
Collaborator

fredcarle commented Apr 9, 2024

Updating unique indexed field on a given doc succeeds but updating a non indexed field of a doc with a unique index fails. The following should succeed but it fails with the error:

can not index a doc's field(s) that violates unique index. DocID: bae-b0a35b3c-486b-54fc-8736-eeff036414ef, name: Fred.
func TestUniqueIndexUpdate_UponUpdatingDocNonIndexedField_ShouldSucceed(t *testing.T) {
	test := testUtils.TestCase{
		Actions: []any{
			testUtils.SchemaUpdate{
				Schema: `
					type User {
						name: String @index(unique: true)
						age: Int
					}
				`,
			},
			testUtils.CreateDoc{
				CollectionID: 0,
				Doc: `
					{
						"name":	"Fred",
						"age":	36
					}`,
			},
			testUtils.UpdateDoc{
				CollectionID: 0,
				DocID:        0,
				Doc: `
					{
						"age":	37
					}`,
			},
		},
	}

	testUtils.ExecuteTestCase(t, test)
}

There is also a similar behaviour for composite indexes where the following should succeed but fails with the error:

can not index a doc's field(s) that violates unique index. DocID: bae-cae3deac-d371-5a1f-93b4-ede69042f79b, name: John, age: 21
func TestUniqueCompositeIndexUpdate_UponUpdatingDocWithExistingFieldValue_ShouldSucceed(t *testing.T) {
	test := testUtils.TestCase{
		Actions: []any{
			testUtils.SchemaUpdate{
				Schema: `
					type User @index(unique: true, fields: ["name", "age"]) {
						name: String 
						age: Int 
						email: String
					}
				`,
			},
			testUtils.CreateDoc{
				CollectionID: 0,
				Doc: `
					{
						"name":	"John",
						"age":	21,
						"email": "email@gmail.com"
					}`,
			},
			testUtils.UpdateDoc{
				CollectionID: 0,
				DocID:        0,
				Doc: `
					{
						"email": "another@gmail.com"
					}`,
			},
		},
	}

	testUtils.ExecuteTestCase(t, test)
}
@fredcarle fredcarle added this to the DefraDB v0.11 milestone Apr 9, 2024
@fredcarle fredcarle added the bug Something isn't working label Apr 9, 2024
@fredcarle fredcarle self-assigned this Apr 9, 2024
fredcarle added a commit that referenced this issue Apr 16, 2024
## Relevant issue(s)

Resolves #2510 

## Description

This PR adds a check to the index validation step where if the resulting
KV pair is the same on update as the previous KV pair, the outcome will
be an no-op instead of an index existing error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority/high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant