I'v read the document of FLASHBACK and had a test.
MySQL [sg]> create table t(id int); [15/1806]
Query OK, 0 rows affected (0.10 sec)
MySQL [sg]> insert into t values(1);
Query OK, 1 row affected (0.03 sec)
MySQL [sg]> select * from t;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
MySQL [sg]> truncate table t;
Query OK, 0 rows affected (0.13 sec)
MySQL [sg]> flashback table t to t1;
Query OK, 0 rows affected (1.17 sec)
MySQL [sg]> select * from t1;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
MySQL [sg]> insert into t values(2);
Query OK, 1 row affected (0.01 sec)
MySQL [sg]> select * from t;
+------+
| id |
+------+
| 2 |
+------+
1 row in set (0.00 sec)
MySQL [sg]> truncate table t;
Query OK, 0 rows affected (0.12 sec)
MySQL [sg]> flashback table t to t2;
Query OK, 0 rows affected (1.19 sec)
MySQL [sg]> select * from t2;
+------+
| id |
+------+
| 2 |
+------+
1 row in set (0.01 sec)
MySQL [sg]> admin show ddl jobs where db_name='sg';
+--------+---------+------------+----------------+--------------+-----------+----------+-----------+---------------------+---------------------+--------+
| JOB_ID | DB_NAME | TABLE_NAME | JOB_TYPE | SCHEMA_STATE | SCHEMA_ID | TABLE_ID | ROW_COUNT | START_TIME | END_TIME | STATE |
+--------+---------+------------+----------------+--------------+-----------+----------+-----------+---------------------+---------------------+--------+
| 85 | sg | t2 | recover table | public | 76 | 80 | 0 | 2020-10-20 10:54:01 | 2020-10-20 10:54:02 | synced |
| 84 | sg | t | truncate table | public | 76 | 80 | 0 | 2020-10-20 10:53:47 | 2020-10-20 10:53:47 | synced |
| 82 | sg | t1 | recover table | public | 76 | 78 | 0 | 2020-10-20 10:53:22 | 2020-10-20 10:53:23 | synced |
| 81 | sg | t | truncate table | public | 76 | 78 | 0 | 2020-10-20 10:52:56 | 2020-10-20 10:52:56 | synced |
| 79 | sg | t | create table | public | 76 | 78 | 0 | 2020-10-20 10:52:18 | 2020-10-20 10:52:18 | synced |
| 77 | sg | | create schema | public | 76 | 0 | 0 | 2020-10-20 10:52:10 | 2020-10-20 10:52:10 | synced |
+--------+---------+------------+----------------+--------------+-----------+----------+-----------+---------------------+---------------------+--------+
6 rows in set (0.01 sec)
Then I have some questions:
flashback statement to restore the same deleted table multiple times, but it seems works fine in my test case. t changed through admin show ddj jobs, why the table id will change?flashback 2 times without any insertion between them, you may get the error:"Table 't' already been flashback to 't1', can't be flashback repeatedly"
flashback table t to t1 can be understood as follows:t is renamed to t1.t is newly created. When TiDB creates a new table, it also allocates a new table_id. @tangenta got it, thanks for your reply.
Most helpful comment
flashback2 times without any insertion between them, you may get the error:flashback table t to t1can be understood as follows:tis renamed tot1.tis newly created. When TiDB creates a new table, it also allocates a newtable_id.