8000 types: MySQL compatible JSON object by dveeden · Pull Request #57843 · pingcap/tidb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

types: MySQL compatible JSON object #57843

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dveeden
Copy link
Contributor
@dveeden dveeden commented Nov 29, 2024

By changing how we order keys in a JSON object we can make TiDB more compatible with MySQL

create table t1 (id int primary key auto_increment, j JSON);
insert into t1(j) values ('{"aaa":1, "b": 1, "aa": 1}');
SELECT j, MD5(j) FROM t1;

MySQL:

mysql-9.1.0> SELECT j, MD5(j) FROM t1;
+-----------------------------+----------------------------------+
| j                           | MD5(j)                           |
+-----------------------------+----------------------------------+
| {"b": 1, "aa": 1, "aaa": 1} | bebcc335a94996f7b47af552fb432d93 |
+-----------------------------+----------------------------------+
1 row in set (0.00 sec)

TiDB, Without this PR:

mysql-8.0.11-TiDB-v8.5.0-alpha-210-gec8b81b98e> SELECT j, MD5(j) FROM t1;
+-----------------------------+----------------------------------+
| j                           | MD5(j)                           |
+-----------------------------+----------------------------------+
| {"aa": 1, "aaa": 1, "b": 1} | 34e9c9a9f71006cbe28ab9af018c830a |
+-----------------------------+----------------------------------+
1 row in set (0.00 sec)

TiDB, With this PR:

mysql-8.0.11-TiDB-v8.5.0-alpha-210-gec8b81b98e-dirty> SELECT j, MD5(j) FROM t1;
+-----------------------------+----------------------------------+
| j                           | MD5(j)                           |
+-----------------------------+----------------------------------+
| {"b": 1, "aa": 1, "aaa": 1} | bebcc335a94996f7b47af552fb432d93 |
+-----------------------------+----------------------------------+
1 row in set (0.00 sec)

What problem does this PR solve?

Issue Number: close 8000 #57842

Problem Summary:

See also pingcap/tidb-tools#830

For sync-diff-inspector it currently fails table checks for most slightly more complex JSON data as the checksums don't match. Then when export-fix-sql is set to true it will compare the actual data by doing a unmarshal/marshal on the JSON data so that comparing works as expected.

This PR makes it so that the checksum would match in a much larger set of cases, avoiding the need for comparing the values which takes more memory, CPU and network bandwidth.

The drawback of this is that this now takes more resources when outputting JSON objects. We could put this new behavior behind a variable if needed.

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

The way JSON objects are handled is made to more closely resemble the way that MySQL does this.

By changing how we order keys in a JSON object we can make TiDB more
compatible with MySQL

With this PR:

TiDB:

```
mysql-8.0.11-TiDB-v8.5.0-alpha-210-gec8b81b98e-dirty> SELECT j, MD5(j) FROM t1;
+-----------------------------+----------------------------------+
| j                           | MD5(j)                           |
+-----------------------------+----------------------------------+
| {"b": 1, "aa": 1, "aaa": 1} | bebcc335a94996f7b47af552fb432d93 |
+-----------------------------+----------------------------------+
1 row in set (0.00 sec)
```

MySQL:

```
mysql-9.1.0> SELECT j, MD5(j) FROM t1;
+-----------------------------+----------------------------------+
| j                           | MD5(j)                           |
+-----------------------------+----------------------------------+
| {"b": 1, "aa": 1, "aaa": 1} | bebcc335a94996f7b47af552fb432d93 |
+-----------------------------+----------------------------------+
1 row in set (0.00 sec)
```
@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Nov 29, 2024
Copy link
ti-chi-bot bot commented Nov 29, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 29, 2024
Copy link
ti-chi-bot bot commented Nov 29, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from dveeden, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 29, 2024
Copy link
tiprow bot commented Nov 29, 2024

Hi @dveeden. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@dveeden
Copy link
Contributor Author
dveeden commented Nov 29, 2024

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Nov 29, 2024
Copy link
ti-chi-bot bot commented Nov 29, 2024

@dveeden: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/unit-test a840873 link true /test unit-test
idc-jenkins-ci-tidb/mysql-test a840873 link true /test mysql-test
idc-jenkins-ci-tidb/check_dev a840873 link true /test check-dev
idc-jenkins-ci-tidb/check_dev_2 a840873 link true /test check-dev2

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/json do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MySQL Compatible JSON object
1 participant
0