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

expression: support decode more types through tidb_decode_key() #20382

Merged
merged 7 commits into from
Oct 15, 2020

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Oct 10, 2020

What problem does this PR solve?

Problem Summary: Before this PR, it is not possible to use tidb_decode_key() to decode some column types like datetime or decimal because of the lack of table information.

create table t (a varchar(255), b int, c datetime, primary key(a, b, c));
split table t by ('bbbb', 10, '2020-01-01');
select start_key, table_id from information_schema.tikv_region_status s, information_schema.tables t where s.table_id = t.tidb_table_id and t.table_name = 't' and is_index = 0 order by start_key;
+--------------------------------------------------------------------------------------------+----------+
| start_key                                                                                  | table_id |
+--------------------------------------------------------------------------------------------+----------+
| 7480000000000000FF3400000000000000F8                                                       | 52       |
| 7480000000000000FF345F720162626262FF00000000FB038000FF00000000000A0419FFA542000000000000FE | 52       |
+--------------------------------------------------------------------------------------------+----------+
select tidb_decode_key('7480000000000000FF345F720162626262FF00000000FB038000FF00000000000A0419FFA542000000000000FE');   
+---------------------------------------------------------------------------------------------------------------+
| tidb_decode_key('7480000000000000FF345F720162626262FF00000000FB038000FF00000000000A0419FFA542000000000000FE') |
+---------------------------------------------------------------------------------------------------------------+
| {"handle":"{bbbb, 10, 1847955789872889856}","table_id":52}                                                    |
+---------------------------------------------------------------------------------------------------------------+

We can see that '2020-01-01' is decoded to 1847955789872889856, which is not expected.

What is changed and how it works?

What's Changed:

  • For the convenience of parsing, the format of tidb_decode_key() is changed to JSON.
  • tidb_decode_key() may not idempotent anymore:
    • If the corresponding table exists, TiDB tries to fetch the column information to decode the original value.
    • If no such table found, the old decoding method is used(cannot restore the original value).
select tidb_decode_key('7480000000000000FF345F720162626262FF00000000FB038000FF00000000000A0419FFA542000000000000FE');                   
+---------------------------------------------------------------------------------------------------------------+
| tidb_decode_key('7480000000000000FF345F720162626262FF00000000FB038000FF00000000000A0419FFA542000000000000FE') |
+---------------------------------------------------------------------------------------------------------------+
| {"handle":{"a":"bbbb","b":"10","c":"2020-01-01 00:00:00"},"table_id":52}                                      |
+---------------------------------------------------------------------------------------------------------------+

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

N/A

Release note

  • No release note

@tangenta tangenta requested review from a team as code owners October 10, 2020 06:22
@tangenta tangenta requested review from XuHuaiyu and removed request for a team October 10, 2020 06:22
Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 12, 2020
Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Oct 12, 2020
ti-srebot
ti-srebot previously approved these changes Oct 12, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Oct 12, 2020
@lzmhhh123
Copy link
Contributor

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 12, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@tangenta merge failed.

@coocood
Copy link
Member

coocood commented Oct 15, 2020

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@tangenta merge failed.

@coocood
Copy link
Member

coocood commented Oct 15, 2020

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@coocood
Copy link
Member

coocood commented Oct 15, 2020

LGTM

@ti-srebot ti-srebot removed the status/LGT2 Indicates that a PR has LGTM 2. label Oct 15, 2020
@ti-srebot ti-srebot added the status/LGT3 The PR has already had 3 LGTM. label Oct 15, 2020
@coocood
Copy link
Member

coocood commented Oct 15, 2020

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@tangenta merge failed.

@coocood
Copy link
Member

coocood commented Oct 15, 2020

/run-unit-test

@tangenta tangenta merged commit d726ba6 into pingcap:master Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants