-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
feat: use gen_random_uuid() for CockroachDB INSERTs #807
Conversation
Approval given :) You can run the tests locally using
|
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.
This looks very nice already! Do we have a test showing that the ID is generated correctly for Cockroach? I do believe that such tests exist, but it would be good to have proof that we don't introduce regressions :)
} | ||
txlog(logging.SQL, c, query, model.Value) | ||
stmt, err := c.Store.PrepareNamed(query) | ||
rows, err := c.Store.NamedQueryContext(model.ctx, query, model.Value) |
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.
Good point, it makes no sense to use prepared statements if they're not cached.
cf82f4b
to
4d9ddfc
Compare
ready for review :) |
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.
Hi @alnr,
Thank you for your PR.
Before reviewing the main topic of this PR, please remove changes regarding testing configurations (database.yml and docker-compose.yml). I don't think they are parts of the topic of this PR. Changing the supported database version should have more consideration around other conditions and may not be a part of this feature PR.
Please keep PR as simple as possible with a single point of interest.
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.
LGTM!
Hi @alnr, I am just wondering. What could be the cons and pros of using Personally, I prefer to use application-side actions (spending the application server's CPU) rather than offloading CPU tasks to the database side since the application is more flexible to spread out (scaling) than controlling database load unless the action should be taken on the database side for integrity or similar things. Also for the main topic of this PR, it is easier to maintain the code if we use the same generic method in the generic dialect. Could you please explain your idea and/or considerations?
Do you have any data regarding this? Having the real or test data here would be great! |
Pros:
Cons:
After this change, we burn a lot fewer CPU cycles anyway, because the DB does not have to verify the uniqueness constraint on the primary key. Checking that constraint takes approximately infinity times more time than generating a UUID. |
Not sure what's going on with that failing test 🤷 |
Don't worry. The short test on the Windows machine is failing many times, and I don't think it is related to your PR. We need to make it better but actually, the Windows environment is too hard. :-) For the main topic, I quickly researched the Cockroach's resources and I found the followings:
It seems like we can take another approach for this, not for right now but for later:
I think this approach will make Pop simple without losing the database side performance. Any ideas or suggestions will help us greatly!
Yeah, could be in a global cluster across the universe 😆 |
Thanks for merging! Honestly I would keep the code as-is for now. Not everyone uses fizz to create schemas. Regarding the empty UUID value: I don't think allowing null UUIDs makes sense for the ID (primary key) column. It makes a lot of sense for other columns, of course, but that's not where this optimization is most useful anyway. |
Yes, for now. and... CREATE TABLE movr.max_schema.vehicles (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
type movr.max_schema.vtype,
creation_time TIMESTAMPTZ,
available BOOL,
last_location STRING
); The function or method to create an auto key can be different by database engines, but we can make the There are also related issues (opposite actually) for the integer ID that cannot be preserved when if the user sets |
Using the
gen_random_uuid()
builtin can significantly speed up inserts because the primary key uniqueness constraint check is elided.I've also fixed up code where there was a prepared statement being created for just one query, which is super inefficient.
I'm kinda having trouble running the tests locally, so I'd appreciate a workflow approval too. @aeneasr @sio4 👍