-
Notifications
You must be signed in to change notification settings - Fork 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
Support for optimized UUID storage in the API #932
Comments
Okay, I've read the article and I'm not convinced at all.
Yeah you could try to implement UUID support in the PHP-CRUD-API, but I would skip the binary UUID. There is no need for UTF-8: UUIDs consist of 7 bit ASCII characters and the characters are always 1 byte, therefor the
Well, I'm not sure, what did you try so far? Did you consider generating the UUID(v4) client side? See also this comment |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@mevdschee, the matter to me is how to store uuids more than where to generate them. If what the article says is right and storing the uuid as bin(16) is that much better option than storing it as varchar, there would be the problem of converting it from binary to char in get requests and viceversa in others, and I would do that in beforeHandler and afterHandler functions. |
@mevdschee so doesn't matter (at the moment) whether I auto generate a UUIDv1 in mysql or a UUIDv4 client side, I would like to eventually get in response a masked json showing the string version of them. |
I doubt it. The difference is a 16 byte vs 36 byte in index size (and not 16 vs 144 byte) and you are introducing complexity because of a hearsay performance improvement. I'm not a fan of such "optimizations".
You introduce a lot of computation and complexity while you could just generate uuidv4 client side and store it as-is in the right collation (as an optimization) in a char(36) field. I'm skeptical about the advantage of the binary storage. If you want an ultra efficient API, then there are many points of improvement: PHP is not the fastest language, the number of roundtrips and http(s) overhead cause unnecessary load in applications, etc.. etc..
My advice is that if you need an efficient random primary key, choose BIGINT and generate it client side. |
ok I'll work on it and do some test.
what would be the equivalent for beforeHandler function? I don't know how to get output so I'm struggling trying to debug it. |
Yes, but not necessarily with RequestFactory, you can also return
try: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Well.. I don't think your approach is feasible in Middleware, as you also need to modify filter and comparison behavior (I did a short hacking session to modify the JsonMiddleware, but I failed). Either this should be handled the way binary fields are handled (binary fields are represented as base64 strings) or it should be left to the client (as I already suggested). Supporting UUID as char(36) seems not that bad to me, nor using random unsigned bigint as primary key. I'm not convinced we should pursue this feature. |
This would require a way to indentify columns that have a UUID 'type'. This could be any unsigned bigint or any binary 16 char field, but that seems a bit 'magic' to me (as it is with boolean types as well). We would then have to make this configurable to overcome that obstacle. Anyway.. I think it is a lot of work for (at best) a performance improvement, as the functionality is already there. |
this article seems to give a valid and performant option to use uuids as primary keys.
So I would let mysql generate uuids on post, then convert bin2uuid/uuid2bin respectively in customization.afterHandler for get requests and customization.beforeHandler for put/patch/delete.
Does it seem to be reasonable?
How would I implement it in beforeHandler/afterHandler functions?
The text was updated successfully, but these errors were encountered: