Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add builtin function json_storage_size #15248

Merged
merged 2 commits into from
Mar 15, 2020

Conversation

stoksc
Copy link
Contributor

@stoksc stoksc commented Mar 10, 2020

What problem does this PR solve?

close #14488

What is changed and how it works?

Add a builtin function for json_storage_size. My only concern is if the length of the marshaled json is correct as the storage size.

Tests

Added unit tests, as well as this local manual test:

tidb> CREATE TABLE jtable (jcol JSON);
Query OK, 0 rows affected (0.01 sec)

tidb> INSERT INTO jtable VALUES  ('{"a": 1000, "b": "wxyz", "c": "[1, 3, 5, 7]"}');
Query OK, 1 row affected (0.01 sec)

tidb> select jcol, JSON_STORAGE_SIZE(jcol) as size from jtable;
+-----------------------------------------------+------+
| jcol                                          | size |
+-----------------------------------------------+------+
| {"a": 1000, "b": "wxyz", "c": "[1, 3, 5, 7]"} |   45 |
+-----------------------------------------------+------+
1 row in set (0.00 sec)

tidb> UPDATE jtable SET jcol = 
    ->     JSON_SET(jcol, "$.b", "a");
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

tidb> select jcol, JSON_STORAGE_SIZE(jcol) as size from jtable;
+--------------------------------------------+------+
| jcol                                       | size |
+--------------------------------------------+------+
| {"a": 1000, "b": "a", "c": "[1, 3, 5, 7]"} |   42 |
+--------------------------------------------+------+
1 row in set (0.00 sec)

@stoksc stoksc requested a review from a team as a code owner March 10, 2020 01:12
@ghost ghost requested review from qw4990 and SunRunAway and removed request for a team March 10, 2020 01:12
@sre-bot sre-bot added the contribution This PR is from a community contributor. label Mar 10, 2020
@CLAassistant
Copy link

CLAassistant commented Mar 10, 2020

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@8d35779). Click here to learn what that means.
The diff coverage is 76.1904%.

@@             Coverage Diff             @@
##             master     #15248   +/-   ##
===========================================
  Coverage          ?   80.2706%           
===========================================
  Files             ?        503           
  Lines             ?     132554           
  Branches          ?          0           
===========================================
  Hits              ?     106402           
  Misses            ?      17748           
  Partials          ?       8404

@qw4990
Copy link
Contributor

qw4990 commented Mar 10, 2020

@stoksc Thanks for your contribution, we will review this PR soon~

@wjhuang2016
Copy link
Member

Thanks, could you add some tests like https://dev.mysql.com/doc/refman/8.0/en/json-utility-functions.html#function_json-storage-size?
That is, check the result of json_storage_size after partial updating it.

@stoksc
Copy link
Contributor Author

stoksc commented Mar 10, 2020

Added it to the above tests section.

Copy link
Member

@wjhuang2016 wjhuang2016 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wjhuang2016 wjhuang2016 added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 13, 2020
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 15, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 15, 2020

Your auto merge job has been accepted, waiting for 14920

@sre-bot
Copy link
Contributor

sre-bot commented Mar 15, 2020

/run-all-tests

@sre-bot sre-bot merged commit f58d9ff into pingcap:master Mar 15, 2020
@stoksc stoksc deleted the json_storage_size branch March 15, 2020 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support the JSON function JSON_STORAGE_SIZE
6 participants