{"id":19325078,"url":"https://github.com/spatie/uuid-mysql-performance","last_synced_at":"2025-10-06T13:49:54.941Z","repository":{"id":66126109,"uuid":"110809663","full_name":"spatie/uuid-mysql-performance","owner":"spatie","description":"This repo contains a bunch of crude benchmark tests to test the performance of MySQL queries with UUIDs in various scenarios","archived":false,"fork":false,"pushed_at":"2022-03-09T16:22:01.000Z","size":29,"stargazers_count":41,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T20:47:09.873Z","etag":null,"topics":["benchmark","database","mysql"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-11-15T09:02:48.000Z","updated_at":"2024-10-03T09:37:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"27881b90-8224-4cf8-9b9c-cfc9e2b3a097","html_url":"https://github.com/spatie/uuid-mysql-performance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/spatie/uuid-mysql-performance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fuuid-mysql-performance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fuuid-mysql-performance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fuuid-mysql-performance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fuuid-mysql-performance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/uuid-mysql-performance/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fuuid-mysql-performance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278621837,"owners_count":26017253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","database","mysql"],"created_at":"2024-11-10T02:08:49.132Z","updated_at":"2025-10-06T13:49:54.929Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1\" /\u003e](https://supportukrainenow.org)\n\n# UUID performance tests\n\nThis playground provides a bunch of crude benchmark tests to test the performance of MySQL queries with UUIDs in various scenarios.\n\nRead more about it here: [http://mysqlserverteam.com/storing-uuid-values-in-mysql-tables/](http://mysqlserverteam.com/storing-uuid-values-in-mysql-tables/).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/uuid-mysql-performance.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/uuid-mysql-performance)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Setup\n\nPlease run `composer install` and setup a local MySQL database. Than copy `.env.exmaple` to `.env` and fill in your credentials in `.env`.\n\nNote that you can set a few configuration parameters in `.env` to manipulate the benchmark results.\n\n### First run\n\n`console.php` is used to run the benchmarks, the first time around, you'll want to run the benchmark command with the `--table` option.\nThis option will drop the current tables and start over again. \nBe aware that adding the `--table` option may cause the benchmark to take a lot longer to finish, depending on the amount of rows you're adding.\n\n## Benchmarks\n\nRun the benchmarks with the following command. You'll probably want to keep the memory_limit option, if you're setting a higher `FLUSH_QUERY_AMOUNT`.\nThis can improve the speed at which the benchmarks are run.\n\n```\nphp -d memory_limit=-1 console.php benchmark [--table]\n```\n\n### The `Normal ID` benchmark\n\nThis is the baseline benchmark, executing `SELECT` queries based on a normal `AUTO_INCREMENT` id.\n\n### The `Binary UUID` benchmark\n\nThis benchmark will run `SELECT` queries on a table with a binary encoded `UUID` field as its primary key. \nIt's input is a normal `UUID` which is encoded in the query to its binary variant.\n\nThis benchmark seems to be the closest in performance to the `Normal ID` benchmark, with less then 500k records in a table.\n\n```\n- Normal ID:\n    Average of 0.056232ms over 10000 iterations.\n- Binary UUID:\n    Average of 0.078953ms over 10000 iterations.\n- Optimised UUID:\n    Average of 0.08929ms over 10000 iterations.\n```\n\n*Results when querying a small amount of records (~10k).*\n\n### The `Optimised UUID` and `Optimised UUID from text`\n\nThese benchmarks query an optimised table containing a bit-shuffled version of a `UUID`.\nShuffling the bits results in better performance compared to the normal `Binary UUID` approach, only when there's \na lot of records in a table (\u003e500k on my local machine).\n\nThe `Optimised UUID from text` benchmark is differs from the `Optimised UUID` in its input method. \n`Optimised UUID from text` represents the way client input would be sent to your backend application. \n\nComparing results, there's no difference between the two.\n\n```\n- Binary UUID:\n    Average of 0.192199ms over 10000 iterations.\n- Optimised UUID:\n    Average of 0.120646ms over 10000 iterations.\n- Optimised UUID from text:\n    Average of 0.109521ms over 10000 iterations.\n```\n\n*The difference between `Binary UUID` and `Optimised UUID` when querying a big dataset of ~500k records.*\n\n### The `Textual UUID` benchmark\n\nThis benchmark represents the normal approach to `UUID`s, storing them as `VARCHAR(36)`. \nYou'll immediately notice that this benchmark is much slower than the others, even with small amounts of data.\n\n```\n- Normal ID:\n    Average of 0.072008ms over 10000 iterations.\n- Binary UUID:\n    Average of 0.113014ms over 10000 iterations.\n- Optimised UUID:\n    Average of 0.11051ms over 10000 iterations.\n- Optimised UUID from text:\n    Average of 0.105908ms over 10000 iterations.\n- Textual UUID:\n    Average of 96.298254ms over 100 iterations.\n```\n\n*VARCHAR `UUID`s are slow.*\n\n## Conclusions\n\nThese are by no means accurate benchmarks when measuring the actual performance of queries. \nThey do however allow for a relative comparison between each approach. \n\nIt is clear that querying a `UUID` stored as a `VARCHAR(36)` is painfully slow compared to the other ways of storing them.\nThere's little to no difference between `Binary UUID` and `Optimised UUID` when querying smaller tables.\n\nThe question we wanted answering was how we could store a large amount of data (\u003e500k) the best way, when using `UUID`s.\nFor us, this benchmark answered that question.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fuuid-mysql-performance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fuuid-mysql-performance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fuuid-mysql-performance/lists"}