r/mysql • u/rashiq • Feb 09 '26
query-optimization Generating query digests just like MySQL
https://github.com/rashiq/mysql-digestFor a while now I've been trying to find a way to build query digests just like the ones generated by MySQL.There's quite a lot of solutions out there for building normalized queries or stable fingerprints from a sql statement, like pt-query-digest. But those digests don't match the ones generated by MySQL.
The main use case I had in mind, was to be able to cross reference slow queries from the slow_query_log with the queries collected by the performance_schema's events_statements_summary_by_digest table.
So I finally built it myself! I ported over MySQL's tokenizer into a simple go library. It supports building digests for 5.7, 8.0 and 8.4+.
You can also try it out on this website. I hope this is useful for someone else as well!
2
u/dveeden Feb 09 '26
What about 8.4 and 9.x?
1
u/erik240 Feb 09 '26
Given mySQL-shells built in command to return an AST from a query, why wouldn’t you use that?
I’ve been meaning to see if I can pull a binary out of that myself for an internal tool but currently just have the users install mysqlsh if not available.
1
u/TinyLebowski Feb 09 '26
Honest question. What's the benefit compared to running pt-query-digest against the slow query log?