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

Support querying MVCC information through builtin function #51683

Closed
tangenta opened this issue Mar 12, 2024 · 3 comments · Fixed by #51678
Closed

Support querying MVCC information through builtin function #51683

tangenta opened this issue Mar 12, 2024 · 3 comments · Fixed by #51678
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@tangenta
Copy link
Contributor

tangenta commented Mar 12, 2024

Enhancement

MVCC information is useful for debugging data inconsistenct issue. For now, we have HTTP API mvcc/key/... to query MVCC. However, it is not always convenient to construct a HTTP query. For example, when there are complex data types in index columns or clustered primary key columns like timestamp, datetime or even binary, query parameters cannot represent these values.

Maybe we can provide a builtin function like tidb_mvcc_info() achieve this purpose.

Note: the priviege should be considered to make sure there are no security issues.

@tangenta tangenta added the type/enhancement The issue or PR belongs to an enhancement. label Mar 12, 2024
@tangenta
Copy link
Contributor Author

@kennytm What do you think about this design?

@kennytm
Copy link
Contributor

kennytm commented Jun 14, 2024

@tangenta LGTM, but I'm not sure if the input to tidb_mvcc_info should be a hex-encoded varchar or a direct varbinary (i.e. tidb_mvcc_info(X'7480000000000000705f728000000000000001')). Maybe too late to use varbinary given how tidb_decode_key works 🤷.

@kennytm
Copy link
Contributor

kennytm commented Jun 14, 2024

BTW should these functions require some privilege check to be invoked

EDIT: No it definitely needs privilege check. Consider this scenario:

-- as root:
create user alice;
create table test.secrets (id bigint primary key, secret varchar(200) not null);
insert into test.secrets values (1, 'confidential data');
mysql> -- as alice:

mysql> select * from test.secrets; -- no privilege, good
ERROR 1142 (42000): SELECT command denied to user 'alice'@'%' for table 'secrets'

mysql> select tidb_encode_record_key('test', 'secrets', 1);  -- 🤔
+----------------------------------------------+
| tidb_encode_record_key('test', 'secrets', 1) |
+----------------------------------------------+
| 7480000000000000685f728000000000000001       |
+----------------------------------------------+
1 row in set (0.00 sec)

mysql> select tidb_mvcc_info('7480000000000000685f728000000000000001');  -- 🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔
+-------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_mvcc_info('7480000000000000685f728000000000000001')                                                                                  |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| {"info":{"writes":[{"start_ts":450462836357332993,"commit_ts":450462836357332994,"short_value":"gAABAAAAAhEAY29uZmlkZW50aWFsIGRhdGE="}]}} |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select cast(from_base64('gAABAAAAAhEAY29uZmlkZW50aWFsIGRhdGE=') as char charset latin1) a; -- 💣💣💣💣💣💣💣
+----------------------------+
| a                          |
+----------------------------+
|      confidential data  |
+----------------------------+
1 row in set (0.00 sec)

The simplest solution is probably require SUPER privilege for tidb_mvcc_info.

@ti-chi-bot ti-chi-bot bot closed this as completed in 5dae1a3 Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants