+-----------------------------------------------+------+------+ 1 row in set (0.00 sec) 

According to the output of JSON_STORAGE_SIZE() , the JSON document inserted into the column takes up 47 bytes. We also checked the amount of space freed by any previous partial updates of the column using JSON_STORAGE_FREE() ; since no updates have yet been performed, this is 0, as expected. 

Next we perform an UPDATE  on the table that should result in a partial update of the document stored in jcol , and then test the result as shown here: 

mysql> UPDATE jtable SET jcol = -> JSON_SET(jcol, "$.b", "a"); Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT -> jcol, -> JSON_STORAGE_SIZE(jcol) AS Size, -> JSON_STORAGE_FREE(jcol) AS Free -> FROM jtable; +--------------------------------------------+------+------+ | jcol | Size | Free | +--------------------------------------------+------+------+ | {"a": 1000, "b": "a", "c": "[1, 3, 5, 7]"} | 47 | 3 | +--------------------------------------------+------+------+ 1 row in set (0.00 sec) 

The value returned by JSON_STORAGE_FREE()  in the previous query indicates that a partial update of the JSON document was performed, and that this freed 3 bytes of space used to store it. The result returned by JSON_STORAGE_SIZE()  is unchanged by the partial update. 

Partial updates are supported for updates using JSON_SET() , JSON_REPLACE() , or JSON_REMOVE() . The direct assignment of a value to a JSON  column cannot be partially updated; following such an update, JSON_STORAGE_SIZE()  always shows the storage used for the newly-set value: 

mysql> UPDATE jtable mysql> SET jcol = ’{"a": 4.55, "b": "wxyz", "c": "[true, false]"}’; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT -> jcol, -> JSON_STORAGE_SIZE(jcol) AS Size, -> JSON_STORAGE_FREE(jcol) AS Free -> FROM jtable; +------------------------------------------------+------+------+ | jcol | Size | Free | +------------------------------------------------+------+------+ | {"a": 4.55, "b": "wxyz", "c": "[true, false]"} | 56 | 0 | +------------------------------------------------+------+------+ 1 row in set (0.00 sec) 

A JSON user variable cannot be partially updated. This means that this function always shows the space currently used to store a JSON document in a user variable: 

mysql> SET @j = ’[100, "sakila", [1, 3, 5], 425.05]’; Query OK, 0 rows affected (0.00 sec) mysql> SELECT @j, JSON_STORAGE_SIZE(@j) AS Size; +------------------------------------+------+ | @j | Size | +------------------------------------+------+ | [100, "sakila", [1, 3, 5], 425.05] | 45 | 

