Bug #87383 Make cached Json_path objects immutable
Submitted: 10 Aug 2017 20:03 Modified: 15 Sep 2017 5:29
Reporter: Knut Anders Hatlen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:8.0.3 OS:Any
Assigned to: CPU Architecture:Any

[10 Aug 2017 20:03] Knut Anders Hatlen
Description:
Json_path_cache::get_path() returns a pointer to a non-const Json_path object in the cache. This is error-prone, as callers may modify the cached object, and if they fail to restore the original state of the object when they're done, the cache is corrupted and wrong results may be returned later.

Most of the callers were changed in bug#77785 so that they don't modify the cached objects. At the moment, there is only one caller that modifies the cached objects, and that is the JSON_SEARCH function. We should change the JSON_SEARCH function so that it doesn't modify cached path objects. Then Json_path_cache::get_path() can return a const path object, which reduces the risk of introducing bugs similar to bug#77785 when writing new code.

How to repeat:
N/A
[15 Sep 2017 5:29] Jon Stephens
Fixed in trunk. Documented in the changelog as follows:

    JSON_SEARCH() no longer performs any modification of cached
    Json_path objects, now making any needed updates to a String
    object that represents the path instead. This saves on the
    number of round trips required between the path's Json_path and
    String representation, which speeds up execution. In addition,
    the one-or-all and escape arguments to JSON_SEARCH() were
    unnecessarily cached; these arguments are no longer cached,
    which should also improve this function's execution time.

Closed.