-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: extract k/v operations from insert/update/delete #6211
Conversation
cc @knz @RaduBerinde |
I like this refactoring very much! Agreed on modeling update on PK change as delete+insert. Reviewed 4 of 4 files at r1. sql/delete.go, line 161 [r1] (raw file): Comments from Reviewable |
Awesome, this is great! I have various comments and I want to make another pass in more detail but the overall structure looks great. I definitely agree on modeling a PK UPDATE as a delete + insert! Review status: all files reviewed at latest revision, 14 unresolved discussions, some commit checks failed. sql/delete.go, line 161 [r1] (raw file): sql/rowwriter.go, line 32 [r1] (raw file): sql/rowwriter.go, line 35 [r1] (raw file): sql/rowwriter.go, line 94 [r1] (raw file): sql/rowwriter.go, line 96 [r1] (raw file): sql/rowwriter.go, line 107 [r1] (raw file): sql/rowwriter.go, line 114 [r1] (raw file): sql/rowwriter.go, line 142 [r1] (raw file): sql/rowwriter.go, line 224 [r1] (raw file): sql/rowwriter.go, line 227 [r1] (raw file): sql/rowwriter.go, line 288 [r1] (raw file): sql/rowwriter.go, line 319 [r1] (raw file): sql/rowwriter.go, line 437 [r1] (raw file): sql/rowwriter.go, line 452 [r1] (raw file): Also, I just noticed the receiver, all these should take a pointer receiver or we may be making full copies of these structs every time! Applies to rowUpdater and rowInserter as well. Comments from Reviewable |
Thanks for the review! RFAL Review status: 0 of 4 files reviewed at latest revision, 14 unresolved discussions, some commit checks pending. sql/delete.go, line 161 [r1] (raw file): sql/rowwriter.go, line 32 [r1] (raw file): sql/rowwriter.go, line 35 [r1] (raw file): sql/rowwriter.go, line 94 [r1] (raw file): sql/rowwriter.go, line 96 [r1] (raw file): sql/rowwriter.go, line 107 [r1] (raw file): sql/rowwriter.go, line 114 [r1] (raw file): sql/rowwriter.go, line 142 [r1] (raw file): sql/rowwriter.go, line 224 [r1] (raw file): sql/rowwriter.go, line 227 [r1] (raw file): sql/rowwriter.go, line 288 [r1] (raw file): sql/rowwriter.go, line 319 [r1] (raw file): sql/rowwriter.go, line 437 [r1] (raw file): I realize I should have been way more clear about the role I saw of this commit. It's mostly setting up the structure and trying to change as little as possible otherwise. REPLACE is going to build on this, and I'm hoping it'll help me see some parts of this that are still not clear. Which component is responsible for deciding which columns have to be provided (and sharing colIDtoRowIndex) is part of that. sql/rowwriter.go, line 452 [r1] (raw file): (Argh, I was trying to reduce allocations. Copying the struct shouldn't be that expensive, but I forgot it would do that for every row while the alloc only happens once per statement.) Comments from Reviewable |
Reviewed 4 of 4 files at r1, 4 of 4 files at r2. sql/rowwriter.go, line 288 [r1] (raw file): sql/rowwriter.go, line 437 [r1] (raw file): sql/rowwriter.go, line 452 [r1] (raw file): Anyway, I doubt it would matter. sql/rowwriter.go, line 55 [r2] (raw file): sql/rowwriter.go, line 122 [r2] (raw file): sql/rowwriter.go, line 129 [r2] (raw file): sql/rowwriter.go, line 133 [r2] (raw file): sql/rowwriter.go, line 251 [r2] (raw file):
Comments from Reviewable |
8f43eff
to
6a75969
Compare
Separates the mapping between table rows/indexes and key/values for the mutative operations. This will be useful immediately for implementing UPSERT and eventually for TableWriter. I tried to keep this as pure a refactor as I could, but it was a lot simpler to model an UPDATE with a PK change as a delete followed by an update (instead of migrating the mess I committed before). I'm still not clear which component decides which columns are required, but I think the additionally complexity that UPSERT/REPLACE adds will make it more obvious one way or another. Once that happens it should be more obvious how to handle all these colIDtoRowIndex maps.
Review status: 0 of 4 files reviewed at latest revision, 9 unresolved discussions, all commit checks successful. sql/rowwriter.go, line 288 [r1] (raw file): sql/rowwriter.go, line 55 [r2] (raw file): sql/rowwriter.go, line 122 [r2] (raw file): sql/rowwriter.go, line 129 [r2] (raw file): sql/rowwriter.go, line 133 [r2] (raw file): sql/rowwriter.go, line 251 [r2] (raw file): This code review has convinced me that the colIDtoRowIndex map is a bit of a maintenance nightmare. I'm going to make a pointed effort to fix it up somehow in the next commit Comments from Reviewable |
Separates the mapping between table rows/indexes and key/values for the
mutative operations. This will be useful immediately for implementing UPSERT and
eventually for TableWriter.
I tried to keep this as pure a refactor as I could, but it was a lot simpler
to model an UPDATE with a PK change as a delete followed by an update (instead
of migrating the mess I committed before).
This change is