-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
Uuid v7 generated in wrong order #536
Comments
Another wrong generations: id, created_at
|
And one more example (this ids use in messages table), messages sorted by "id", since in theory uuid v7 should be monotonically increasing Therefore, because of this bug, sometimes the wrong order of messages appears in correspondence id, created_at
|
|
@j-fulbright According to the Since the second record was created at I did take a look at the UUIDs themselves, though, and I can tell the second one was created after the first one (if the timestamp is to be believed): > $u1 = Ramsey\Uuid\Uuid::fromString('019108f6-25a7-70cb-80b0-b50530e83edd')
= Ramsey\Uuid\Lazy\LazyUuidFromString {#27275
uuid: "019108f6-25a7-70cb-80b0-b50530e83edd",
}
> $u2 = Ramsey\Uuid\Uuid::fromString('019108f6-2749-70c0-9786-6feea192b2f8')
= Ramsey\Uuid\Lazy\LazyUuidFromString {#13450
uuid: "019108f6-2749-70c0-9786-6feea192b2f8",
}
> $u1->getDateTime()->format('Y-m-d H:i:s.u')
= "2024-07-31 13:23:54.919000"
> $u2->getDateTime()->format('Y-m-d H:i:s.u')
= "2024-07-31 13:23:55.337000" I wouldn't expect the timestamps to match with the Nevertheless, when you ran this query, did you sort the results by When compared, the first UUID is definitely less than the second UUID: > $u1->compareTo($u2)
= -1 So, it should sort in that order, accordingly. |
Addendum: unless you specify an In this case, if you did Hope this helps! |
@ramsey I am 100% sure the query or the result there, that was just what was passed on to me from one of our developers. I do know that using the exact same code and switching to Symfony, everything was properly being populated/created. They used: $dateTime is createdAt that is passed into Carbon with milliseconds etc. |
Hello, I came across a strange case where the library generated uuid v7 incorrectly in time.
Here example of table
id = Uuid::uuid7()->toString()
andcreated_at (server datetime)
, sorted by id (asc)id, created_at
018d7fca-3ae5-7306-a040-204628e43dc9, 2024-02-06T18:59:36.000000Z
018d7fdc-0ba8-7006-8047-41a572a695c6, 2024-02-06T19:19:03.000000Z
018d8030-0dab-7206-a042-31238ed9cb48, 2024-02-06T20:50:49.000000Z
018d8041-7c1b-7106-8043-6c5e69c8fbbd, 2024-02-06T21:09:51.000000Z
01a6ce4c-5a19-7006-b045-197ad8210718, 2024-02-06T19:19:54.000000Z
For some reason,
ID=01a6ce4c-5a19-7006-b045-197ad8210718
was generated incorrectlyThe text was updated successfully, but these errors were encountered: