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

backport: support 'ALTER TABLE t1 CHARACTER SET = ...' clause #1670

Closed
Tracked by #1661
hustjieke opened this issue May 5, 2023 · 5 comments
Closed
Tracked by #1661

backport: support 'ALTER TABLE t1 CHARACTER SET = ...' clause #1670

hustjieke opened this issue May 5, 2023 · 5 comments
Assignees
Labels
A-feature feature with good idea A-porting back port code from 5.7/8.0 C-stonedb-8.0 associated with stonedb 8.0

Comments

@hustjieke
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

previous working issue: #848
commit id: cf1c98c

Describe the solution you'd like

Describe alternatives you've considered

Additional context

@hustjieke hustjieke added A-feature feature with good idea C-stonedb-8.0 associated with stonedb 8.0 A-porting back port code from 5.7/8.0 labels May 5, 2023
@hustjieke hustjieke added this to the StoneDB_8.0_v1.0.2 milestone May 5, 2023
@hustjieke hustjieke self-assigned this May 8, 2023
@hustjieke hustjieke moved this from Todo to In Progress in StoneDB for MySQL 8.0 May 8, 2023
@hustjieke
Copy link
Collaborator Author

After backport, no data selected in mtr issue848.test

mysql> select hex(c_char),hex(c_varchar),hex(c_text) from t1; 
Empty set (0.00 sec)

actually the result should be:

mysql> select hex(c_char),hex(c_varchar),hex(c_text) from t1; 
+-------------+----------------+-------------+
| hex(c_char) | hex(c_varchar) | hex(c_text) |
+-------------+----------------+-------------+
| D6D0B9FA    | D5E3BDAD       | BABCD6DD    |
+-------------+----------------+-------------+
1 row in set (0.00 sec)

@hustjieke
Copy link
Collaborator Author

After backport, no data selected in mtr issue848.test

mysql> select hex(c_char),hex(c_varchar),hex(c_text) from t1; 
Empty set (0.00 sec)

actually the result should be:

mysql> select hex(c_char),hex(c_varchar),hex(c_text) from t1; 
+-------------+----------------+-------------+
| hex(c_char) | hex(c_varchar) | hex(c_text) |
+-------------+----------------+-------------+
| D6D0B9FA    | D5E3BDAD       | BABCD6DD    |
+-------------+----------------+-------------+
1 row in set (0.00 sec)

Simplify sql:

mysql> CREATE TABLE `t1` (   `c_char` char(10) DEFAULT NULL COMMENT 'char') ENGINE=TIANMU DEFAULT CHARSET=GBK;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t1 values(x'D6D0B9FA');
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+--------+
| c_char |
+--------+
| 中国   |
+--------+
1 row in set (0.00 sec)

mysql> ALTER TABLE t1 MODIFY c_char char(10) CHARACTER SET UTF8MB4;
Query OK, 1 row affected (0.06 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from t1;
Empty set (0.00 sec)

@hustjieke
Copy link
Collaborator Author

After alter table t1, the commit version changed to 0

In 8.0, the data version missed after alter table ...:

$:/github/stonedb/build/install8/data/test# ls t1.tianmu/columns/0/v/
0000000000000000----->1. create table t1....
$:/github/stonedb/build/install8/data/test# ls t1.tianmu/columns/0/v/
6459a9c40000272a----->2. insert into t1 values....
$:/github/stonedb/build/install8/data/test# ls t1.tianmu/columns/0/v/
0000000000000000----->3. alter table t1 ....

In 5.7, data version is reserved

root@stonedb-gaoriyao:/github/stonedb/build/install57/data/test# ls t1.tianmu/columns/0/v/
0000000000000000----->1. create table t1....
root@stonedb-gaoriyao:/github/stonedb/build/install57/data/test# ls t1.tianmu/columns/0/v/
6458ee7d00002712----->2. insert into t1 values....
root@stonedb-gaoriyao:/github/stonedb/build/install57/data/test# ls t1.tianmu/columns/0/v/
0000000000000000  6458ee7d00002713----->3. alter table t1 ....

@hustjieke
Copy link
Collaborator Author

mysql> CREATE TABLE t1 ( c_char char(10) DEFAULT NULL COMMENT 'char') ENGINE=TIANMU DEFAULT CHARSET=GBK;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t1 values(x'D6D0B9FA');
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+--------+
| c_char |
+--------+
| 中国 |
+--------+
1 row in set (0.00 sec)

mysql> ALTER TABLE t1 MODIFY c_char char(10) CHARACTER SET UTF8MB4;
Query OK, 1 row affected (0.06 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from t1;
Empty set (0.00 sec)

After debug, I found txn not commited, the commit logic had been skiped:

void Engine::CommitTx(THD *thd, bool all) {
  TIANMU_LOG(LogCtl_Level::INFO, "commit txn");

  // fix bug: issue759, in file sql_trunction.cc and function end_transaction(), will call CommitTx() twice
  // skip for first time, called in trans_commit_stmt(), thd->server_status = SERVER_STATUS_IN_TRANS and all = false
  // then called in trans_commit_implicit(), thd->server_status will be set "~SERVER_STATUS_IN_TRANS", and all = true
  // tianmu truncate table in 5.7 is ok, 8.0 has this problem.
  if ((thd->lex->sql_command == SQLCOM_TRUNCATE) && (thd->server_status & SERVER_STATUS_IN_TRANS)) {
    return;
  }
  if (all || !thd_test_options(thd, OPTION_NOT_AUTOCOMMIT)) {------> condition is false
    GetTx(thd)->Commit(thd);
  }
  ClearTx(thd);
}

@hustjieke
Copy link
Collaborator Author

The bug is similar to #759, just like the comment said:

  // fix bug: issue759, in file sql_trunction.cc and function end_transaction(), will call CommitTx() twice
  // skip for first time, called in trans_commit_stmt(), thd->server_status = SERVER_STATUS_IN_TRANS and all = false
  // then called in trans_commit_implicit(), thd->server_status will be set "~SERVER_STATUS_IN_TRANS", and all = true
  // tianmu truncate table in 5.7 is ok, 8.0 has this problem.

hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue May 9, 2023
[summary]
1. backport code
2. fix no txn version for table not commited by transaction.
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue May 9, 2023
mergify bot pushed a commit that referenced this issue May 10, 2023
[summary]
1. backport code
2. fix no txn version for table not commited by transaction.
@github-project-automation github-project-automation bot moved this from In Progress to Done in StoneDB for MySQL 8.0 May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-feature feature with good idea A-porting back port code from 5.7/8.0 C-stonedb-8.0 associated with stonedb 8.0
Projects
Development

No branches or pull requests

2 participants