-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow unowned lookup_unique
vindex columns to be null
#9302
Allow unowned lookup_unique
vindex columns to be null
#9302
Conversation
null
lookup_unique
vindex columns to be null
5ee66b3
to
701bb7e
Compare
go/vt/vtgate/engine/insert.go
Outdated
// Verify keyspace ids from primary and secondary VIndexes match | ||
if len(verifyIndexes) > 0 { |
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.
My understanding of Go is not great, but I believe the verifyKsids != nil
check was always returning true
, because verifyKsids
is declared as an empty slice, not a nil slice. Using len(verifyIndexes) > 0
is more in line of the actual intention of this code.
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.
Apparently using nil
slices is preferred in Go, according to https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices. I'll make that change and push it up shortly.
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.
The changes overall looks good.
Could you please add an end to end test for it here go/test/endtoend/vtgate/lookup_test.go
?
go/vt/vtgate/engine/insert_test.go
Outdated
require.EqualError(t, err, `value must be supplied for column [c3]`) | ||
if err != nil { | ||
t.Fatal(err) | ||
} |
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.
nit:
require.NoError(t, err)
instead of if condition
@harshit-gangal Thank you for the review! ❤️ I'll try to find some time to make the requested change and add a few end to end test cases tomorrow! 👍 |
2091144
to
c560ca4
Compare
@harshit-gangal I updated the pull request to also add an end to end test case. 🙇♂️ |
5b4a8ae
to
3da8d3b
Compare
@arthurschreiber if you rebase on |
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
3da8d3b
to
f52da1e
Compare
@mattlord CI has been quite flaky for me. Could you kick off that one failing build again? 🙇♂️ |
Description
We're running into an issue when inserting data into a table that uses a secondary, unowned
lookup_unique
VIndex.When inserting data in such a table with a
NULL
value for the VIndex column, Vitess returns an error:We believe that stems from a bug in the code that processes unowned VIndexes for
INSERT
operations, as we don't see a reason why a value for these columns would be required.Example
Let's say we have two tables,
issues
andpull_requests
. Anissues
row can optionally be associated with apull_requests
row via theissues.pull_request_id
column. Bothissues
andpull_requests
are sharded byrepository_id
. An issue can only be associated to a pull request with the samerepository_id
.SQL Schema for
sharded
keyspaceVSchema for
sharded
keyspaceWhen we want to create a pull request, we first add a new
pull_requests
row, which will write a new entry to thepull_requests_id_keyspace_idx
lookup table. Then we create anissues
row with apull_request_id
value - this will cause a lookup to thepull_requests_id_keyspace_idx
lookup table to ensure that the keyspace id matches with the keyspace id generated from therepository_id
column.But when we want to create a standalone
issues
row, wherepull_requests_id
isNULL
, this will fail with the above mentioned error.Other Considerations
This change is unrelated to the
ignore_nulls
option.ignore_nulls
allowsNULL
values on the owner table of the lookup vindex, but this is not the case here. We don't want to allowNULL
values on e.g.pull_requests.id
on the owner table.Adding another option to the lookup vindex for this functionality is not required - nullability of the column is fully handled by the underlying database schema (in the example above, the
issues.pull_request_id
column itself defines whether it can containNULL
values or not).Writing a
NULL
value to an unowned, non-unique lookup Vindex (lookup
/consistent_lookup
) was possible even without the fix - due to the nature of the bug this only affectedlookup_unique
,consistent_lookup_unique
and other non-reversible single column vindexes.Related Issue(s)
N/A
Checklist