go-mysql-server
go-mysql-server copied to clipboard
Add `LazyJSONDocument`, which wraps a JSON string and only deserializes it if needed.
This is the GMS side of https://github.com/dolthub/dolt/issues/7749
This is a new JSONWrapper implementation. It isn't used by the GMS in-memory storage, but it will be used in Dolt to speed up SELECT queries that don't care about the structure of the JSON.
A big difference between this and JSONDocument is that even after it de-serializes the JSON into a go value, it continues to keep the string in memory. This is good in cases where we would want to re-serialize the JSON later without changing it. (So statements like SELECT json FROM table WHERE json->>"$.key" = "foo"; will still be faster.) But with the downside of using more memory than JSONDocument)
One detail to note is that we currently desalinize JSON prior to writing it on the wire, so that we can re-serialize it in a way that matches MySQL's output (different whitespacing.) This is expensive and I don't think is worth it.
I discussed with Max whether or not we consider it a requirement to match MySQL's wire responses exactly for JSON, and agreed that we could probably relax that requirement. With this change, casting a document to a text type will still result in the same output as MySQL, but simply displaying it in a query result won't.