## Module 2: Using Time to Live (TTL)

In this module, participants will create three tables, with the first two tables configured with TTL (Time to Live) attributes, while the third table will not have a TTL attribute configured. Subsequently, the `tiup bench` tool will be used to insert one row of random data into each of the three tables every second. For information on using the TiUP bench component, please refer to: <https://docs.pingcap.com/tidb/stable/tiup-bench/>. Participants will observe whether the data in the three tables is automatically deleted according to the configured lifecycle, as well as how to enable or disable the TTL feature online. Finally, the impact of the FLASHBACK TABLE feature on the TTL attributes of the tables will be tested.

### Step 1. Connect to the TiUP control machine

+ Open two SSH connections to your lab virtual machine, by clicking:
  + [Terminal 1](ssh://monitor1-ssh#1)
  + [Terminal 2](ssh://monitor1-ssh#2)

+ You will now have two active terminal sessions.

### Step 2. Create Tables

+ On [Terminal 1](ssh://monitor1-ssh#1), connect to the TiDB server instance.

  ```bash
  mysql -h ${HOST_DB1_PRIVATE_IP} --port 4000 -u root
  ```

  ```output
  mysql> 
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1),create the tables `tbl_ttl_1`, `tbl_ttl_2`, and `tbl_ttl_3` under the `test` schema, and understand the DDL statements used to create these tables.

  ```sql
  DROP TABLE IF EXISTS test.tbl_ttl_1;
  CREATE TABLE test.tbl_ttl_1 (
  `ID` bigint PRIMARY KEY AUTO_RANDOM,
  `pState` varchar (100) NOT NULL,
  `cState` tinyint (4) DEFAULT NULL,
  `created_at` DATETIME,
  `updated_at` DATETIME,
  `txt` varchar(64) DEFAULT 'TTLTEST',
  KEY `pcStateIndex` (`pState`, `cState`)
  ) PRE_SPLIT_REGIONS=4, TTL = `created_at` + INTERVAL 1 MINUTE;

  DROP TABLE IF EXISTS test.tbl_ttl_2;
  CREATE TABLE test.tbl_ttl_2 (
  `ID` bigint PRIMARY KEY AUTO_RANDOM,
  `pState` varchar (100) NOT NULL,
  `cState` tinyint (4) DEFAULT NULL,
  `created_at` DATETIME,
  `updated_at` DATETIME,
  `expire_at` DATETIME AS( IF (cState=1, created_at + INTERVAL 1 MINUTE, created_at + INTERVAL 2 DAY) ),
  `txt` varchar(64) DEFAULT 'TTLTEST',
  KEY `pcStateIndex` (`pState`, `cState`)
  ) PRE_SPLIT_REGIONS=4, TTL = `expire_at` + INTERVAL 0 MINUTE;

  DROP TABLE IF EXISTS test.tbl_ttl_3;
  CREATE TABLE test.tbl_ttl_3 (
  `ID` bigint PRIMARY KEY AUTO_RANDOM,
  `pState` varchar (100) NOT NULL,
  `cState` tinyint (4) DEFAULT NULL,
  `created_at` DATETIME,
  `updated_at` DATETIME,
  `txt` varchar(64) DEFAULT 'TTLTEST',
  KEY `pcStateIndex` (`pState`, `cState`)
  ) PRE_SPLIT_REGIONS=4;
  ```

  ```output
  mysql> CREATE TABLE test.tbl_ttl_1 (
      -> `ID` bigint PRIMARY KEY AUTO_RANDOM,
      -> `pState` varchar (100) NOT NULL,
      -> `cState` tinyint (4) DEFAULT NULL,
      -> `created_at` DATETIME,
      -> `updated_at` DATETIME,
      -> `txt` varchar(64) DEFAULT 'TTLTEST',
      -> KEY `pcStateIndex` (`pState`, `cState`)
      -> ) PRE_SPLIT_REGIONS=4, TTL = `created_at` + INTERVAL 1 MINUTE;
  Query OK, 0 rows affected, 2 warnings (0.07 sec)

  mysql> 
  mysql> DROP TABLE IF EXISTS test.tbl_ttl_2;
  Query OK, 0 rows affected, 1 warning (0.00 sec)

  mysql> CREATE TABLE test.tbl_ttl_2 (
      -> `ID` bigint PRIMARY KEY AUTO_RANDOM,
      -> `pState` varchar (100) NOT NULL,
      -> `cState` tinyint (4) DEFAULT NULL,
      -> `created_at` DATETIME,
      -> `updated_at` DATETIME,
      -> `expire_at` DATETIME AS( IF (cState=1, created_at + INTERVAL 1 MINUTE, created_at + INTERVAL 2 DAY) ),
      -> `txt` varchar(64) DEFAULT 'TTLTEST',
      -> KEY `pcStateIndex` (`pState`, `cState`)
      -> ) PRE_SPLIT_REGIONS=4, TTL = `expire_at` + INTERVAL 0 MINUTE;
  Query OK, 0 rows affected, 2 warnings (0.07 sec)

  mysql> 
  mysql> DROP TABLE IF EXISTS test.tbl_ttl_3;
  Query OK, 0 rows affected, 1 warning (0.00 sec)

  mysql> CREATE TABLE test.tbl_ttl_3 (
      -> `ID` bigint PRIMARY KEY AUTO_RANDOM,
      -> `pState` varchar (100) NOT NULL,
      -> `cState` tinyint (4) DEFAULT NULL,
      -> `created_at` DATETIME,
      -> `updated_at` DATETIME,
      -> `txt` varchar(64) DEFAULT 'TTLTEST',
      -> KEY `pcStateIndex` (`pState`, `cState`)
      -> ) PRE_SPLIT_REGIONS=4;
  Query OK, 0 rows affected, 2 warnings (0.06 sec)
  ```

+ The DDL statements used to create the tables reveal the following:
  + The expiration time for data in table `test.tbl_ttl_1` is one minute added to the timestamp in the `created_at` column.
  + For table `test.tbl_ttl_2`, the expiration time for data is one minute added to the `created_at` column when the value of column `cState` is `1`; otherwise, it is two days added to the `created_at` column.
  + Table `test.tbl_ttl_3` does not have a TTL attribute set.

+ On [Terminal 2](ssh://monitor1-ssh#2), use the `tiup bench` tool to insert 1,000 rows of random data into the tables `test.tbl_ttl_1`, `test.tbl_ttl_2`, and `test.tbl_ttl_3`. For information on using the TiUP bench component, please refer to: <https://docs.pingcap.com/tidb/stable/tiup-bench/>.

  ```bash
  cat > tbl_ttl_insert_1.sql <<EOF
  INSERT INTO test.tbl_ttl_1 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  INSERT INTO test.tbl_ttl_2(pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  INSERT INTO test.tbl_ttl_3 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  EOF
  export PATH="$PATH:/home/ec2-user/.tiup/bin"
  tiup bench rawsql run -H ${HOST_DB1_PRIVATE_IP} -P 4000 --count 1000 --threads 1 --query-files tbl_ttl_insert_1.sql
  ```

  ```output
  [ec2-user@ip-10-90-4-53 ~]$ cat > tbl_ttl_insert_1.sql <<EOF
  > INSERT INTO test.tbl_ttl_1 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  > INSERT INTO test.tbl_ttl_2(pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  > INSERT INTO test.tbl_ttl_3 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  > EOF
  [ec2-user@ip-10-90-4-53 ~]$ export PATH="$PATH:/home/ec2-user/.tiup/bin"
  [ec2-user@ip-10-90-4-53 ~]$ tiup bench rawsql run -H ${HOST_DB1_PRIVATE_IP} -P 4000 --count 1000 --threads 1 --query-files tbl_ttl_insert_1.sql
  Starting component bench: /home/ec2-user/.tiup/components/bench/v1.12.0/tiup-bench rawsql run -H 10.90.1.183 -P 4000 --count 1000 --threads 1 --query-files tbl_ttl_insert_1.sql
  Finished
  [Summary] TBL_TTL_INSERT_1: 0.01s
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), check the data volume in the three tables. For table `test.tbl_ttl_2`, only check the number of rows where the value of column `cstate` is `1`, which corresponds to the data with an expiration time of one minute. Note: The output results may vary.

  ```sql
  SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  ```

  ```output
  mysql> SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  +----------+
  | COUNT(*) |
  +----------+
  |     1000 |
  +----------+
  1 row in set (0.00 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |      505 |
  +----------+
  1 row in set (0.01 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |     1000 |
  +----------+
  1 row in set (0.00 sec)
  ```

### Step 3. Setting the TTL Attributes for Tables

+ On [Terminal 1](ssh://monitor1-ssh#1), you can view the current TTL task information through the system tables `information_schema.tables` and `mysql.tidb_ttl_table_status`. The `mysql.tidb_ttl_table_status` table contains information about the last executed and currently executing TTL tasks for all tables with TTL attribute.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  *************************** 1. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_2
                        table_id: 112
                parent_table_id: 112
                table_statistics: NULL
                    last_job_id: NULL
            last_job_start_time: NULL
            last_job_finish_time: NULL
            last_job_ttl_expire: NULL
                last_job_summary: NULL
                  current_job_id: 1ab86f3817964e41a0ef90209a57b23a
            current_job_owner_id: 84823e1f-e42a-4dc8-bc6e-e4fdaf2ba114
          current_job_owner_addr: NULL
      current_job_owner_hb_time: 2025-09-07 10:36:40
          current_job_start_time: 2025-09-07 10:33:14
          current_job_ttl_expire: 2025-09-07 10:33:14
              current_job_state: NULL
              current_job_status: running
  current_job_status_update_time: 2025-09-07 10:33:14
  1 row in set (0.02 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), the first execution may only output information for one table, but after several repeated executions, information for two tables will appear. Note: Since table `test.tbl_ttl_3` does not have a TTL attribute configured, it will not appear in the output results. Note: It may take 3 to 5 minutes to produce the expected results, so please be patient. Alternatively, you can proceed with the following operations, which will not affect the subsequent steps.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  *************************** 1. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_1
                        table_id: 110
                parent_table_id: 110
                table_statistics: NULL
                    last_job_id: NULL
            last_job_start_time: NULL
            last_job_finish_time: NULL
            last_job_ttl_expire: NULL
                last_job_summary: NULL
                  current_job_id: 9e46c3c8dc3c4be8992a9d4cb856363a
            current_job_owner_id: 84823e1f-e42a-4dc8-bc6e-e4fdaf2ba114
          current_job_owner_addr: NULL
      current_job_owner_hb_time: 2025-09-07 10:37:20
          current_job_start_time: 2025-09-07 10:37:18
          current_job_ttl_expire: 2025-09-07 10:36:18
              current_job_state: NULL
              current_job_status: running
  current_job_status_update_time: 2025-09-07 10:37:18
  *************************** 2. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_2
                        table_id: 112
                parent_table_id: 112
                table_statistics: NULL
                    last_job_id: NULL
            last_job_start_time: NULL
            last_job_finish_time: NULL
            last_job_ttl_expire: NULL
                last_job_summary: NULL
                  current_job_id: 1ab86f3817964e41a0ef90209a57b23a
            current_job_owner_id: 84823e1f-e42a-4dc8-bc6e-e4fdaf2ba114
          current_job_owner_addr: NULL
      current_job_owner_hb_time: 2025-09-07 10:37:20
          current_job_start_time: 2025-09-07 10:33:14
          current_job_ttl_expire: 2025-09-07 10:33:14
              current_job_state: NULL
              current_job_status: running
  current_job_status_update_time: 2025-09-07 10:33:14
  2 rows in set (0.02 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), upon checking the DDL statements for tables `test.tbl_ttl_1` and `test.tbl_ttl_2`, it is found that the default value for the TTL attribute `TTL_JOB_INTERVAL` is set to `1h`, indicating that the background cleanup task for TTL is executed once every hour.

  ```sql
  SHOW CREATE TABLE test.tbl_ttl_1\G
  SHOW CREATE TABLE test.tbl_ttl_2\G
  ```

  ```output
  mysql> SHOW CREATE TABLE test.tbl_ttl_1\G
  *************************** 1. row ***************************
        Table: tbl_ttl_1
  Create Table: CREATE TABLE `tbl_ttl_1` (
    `ID` bigint NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
    `pState` varchar(100) NOT NULL,
    `cState` tinyint DEFAULT NULL,
    `created_at` datetime DEFAULT NULL,
    `updated_at` datetime DEFAULT NULL,
    `txt` varchar(64) DEFAULT 'TTLTEST',
    PRIMARY KEY (`ID`) /*T![clustered_index] CLUSTERED */,
    KEY `pcStateIndex` (`pState`,`cState`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=30001 */ /*T! PRE_SPLIT_REGIONS=4 */ /*T![ttl] TTL=`created_at` + INTERVAL 1 MINUTE */ /*T![ttl] TTL_ENABLE='ON' */ /*T![ttl] TTL_JOB_INTERVAL='1h' */
  1 row in set (0.00 sec)
  mysql> SHOW CREATE TABLE test.tbl_ttl_2\G
  *************************** 1. row ***************************
        Table: tbl_ttl_2
  Create Table: CREATE TABLE `tbl_ttl_2` (
    `ID` bigint NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
    `pState` varchar(100) NOT NULL,
    `cState` tinyint DEFAULT NULL,
    `created_at` datetime DEFAULT NULL,
    `updated_at` datetime DEFAULT NULL,
    `expire_at` datetime GENERATED ALWAYS AS (if(`cState` = 1, date_add(`created_at`, interval 1 minute), date_add(`created_at`, interval 2 day))) VIRTUAL,
    `txt` varchar(64) DEFAULT 'TTLTEST',
    PRIMARY KEY (`ID`) /*T![clustered_index] CLUSTERED */,
    KEY `pcStateIndex` (`pState`,`cState`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=30001 */ /*T! PRE_SPLIT_REGIONS=4 */ /*T![ttl] TTL=`expire_at` + INTERVAL 0 MINUTE */ /*T![ttl] TTL_ENABLE='ON' */ /*T![ttl] TTL_JOB_INTERVAL='1h' */
  1 row in set (0.00 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), use the following statement to set the TTL background cleanup task to execute every minute. The command for table `test.tbl_ttl_3` will fail because it does not have the TTL configuration enabled.

  ```sql
  ALTER TABLE test.tbl_ttl_1 TTL_JOB_INTERVAL = '1m';
  ALTER TABLE test.tbl_ttl_2 TTL_JOB_INTERVAL = '1m';
  ALTER TABLE test.tbl_ttl_3 TTL_JOB_INTERVAL = '1m';
  ```

  ```output
  mysql> ALTER TABLE test.tbl_ttl_1 TTL_JOB_INTERVAL = '1m';
  Query OK, 0 rows affected (0.06 sec)

  mysql> ALTER TABLE test.tbl_ttl_2 TTL_JOB_INTERVAL = '1m';
  Query OK, 0 rows affected (0.06 sec)

  mysql> ALTER TABLE test.tbl_ttl_3 TTL_JOB_INTERVAL = '1m';
  ERROR 8150 (HY000): Cannot set TTL_JOB_INTERVAL on a table without TTL config
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), check the data volume in the three tables. For table `test.tbl_ttl_2`, only check the number of rows where the value of column `cstate` is `1`, which corresponds to the expiration time being one minute added to the value in the `created_at` column. Note：The output may differ from the results below due to different timings of TTL background execution, but you can see that the data in tables `test.tbl_ttl_1` and `test.tbl_ttl_2` has started to be cleaned by TTL.

  ```sql
  SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  ```

  ```output
  mysql> SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  +----------+
  | COUNT(*) |
  +----------+
  |      699 |
  +----------+
  1 row in set (0.00 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |      289 |
  +----------+
  1 row in set (0.00 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |     1000 |
  +----------+
  1 row in set (0.00 sec)
  ```

+ If you execute the same query again after an interval of one minute, you will find that the data volume in the table has decreased again, indicating that the TTL task is being executed. Note：The output may differ from the results below due to different timings of TTL background execution, but you can see that the data in tables `test.tbl_ttl_1` and `test.tbl_ttl_2` has started to be cleaned by TTL.

  ```sql
  SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  ```

  ```output
  mysql> SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  +----------+
  | COUNT(*) |
  +----------+
  |      510 |
  +----------+
  1 row in set (0.01 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |      191 |
  +----------+
  1 row in set (0.00 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |     1000 |
  +----------+
  1 row in set (0.00 sec)
  ```

### Step 4. Adding the TTL Attributes to Tables

+ On [Terminal 1](ssh://monitor1-ssh#1), configure the TTL attributes for table `test.tbl_ttl_3`, setting the data expiration time to one minute added to the value in the `created_at` column, and set the TTL background cleanup task to execute every minute.

  ```sql
  ALTER TABLE test.tbl_ttl_3 TTL = `created_at` + INTERVAL 1 MINUTE;
  ALTER TABLE test.tbl_ttl_3 TTL_JOB_INTERVAL = '1m';
  ```

  ```output
  mysql> ALTER TABLE test.tbl_ttl_3 TTL = `created_at` + INTERVAL 1 MINUTE;
  Query OK, 0 rows affected (0.06 sec)
  mysql> ALTER TABLE test.tbl_ttl_3 TTL_JOB_INTERVAL = '1m';
  Query OK, 0 rows affected (0.52 sec)
  ```

### Step 5. Periodically Inserting Data into Tables

+ On [Terminal 2](ssh://monitor1-ssh#2), use the `tiup bench` tool to periodically insert one row of random data into tables `tbl_ttl_1`, `tbl_ttl_2`, and `tbl_ttl_3`, with an interval of one second for a total of 3600 cycles.

  ```bash
  cat > tbl_ttl_insert_2.sql <<EOF
  INSERT INTO test.tbl_ttl_1 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  INSERT INTO test.tbl_ttl_2(pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  INSERT INTO test.tbl_ttl_3 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  SELECT SLEEP(1);
  EOF
  export PATH="$PATH:/home/ec2-user/.tiup/bin"
  tiup bench rawsql run -H ${HOST_DB1_PRIVATE_IP} -P 4000 --count 3600 --threads 1 --query-files tbl_ttl_insert_2.sql
  ```

  ```output
  [ec2-user@ip-10-90-4-151 ~]$ cat > tbl_ttl_insert_2.sql <<EOF
  > INSERT INTO test.tbl_ttl_1 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  > INSERT INTO test.tbl_ttl_2(pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  > INSERT INTO test.tbl_ttl_3 (pState, cState, created_at, updated_at) VALUES (ELT(1 + FLOOR(RAND() * 9), 's1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's0'), 1 + FLOOR(RAND() * 2), NOW(), NOW());
  > SELECT SLEEP(1);
  > EOF
  [ec2-user@ip-10-90-4-151 ~]$ export PATH="$PATH:/home/ec2-user/.tiup/bin"
  [ec2-user@ip-10-90-4-151 ~]$ tiup bench rawsql run -H ${HOST_DB1_PRIVATE_IP} -P 4000 --count 3600 --threads 1 --query-files tbl_ttl_insert_2.sql
  Starting component bench: /home/ec2-user/.tiup/components/bench/v1.12.0/tiup-bench rawsql run -H 10.90.2.64 -P 4000 --count 3600 --threads 1 --query-files tbl_ttl_insert_2.sql
  [Current] TBL_TTL_INSERT_2: 1.01s
  [Current] TBL_TTL_INSERT_2: 1.01s
  [Current] TBL_TTL_INSERT_2: 1.01s
  [Current] TBL_TTL_INSERT_2: 1.01s
  ...
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1),check the data volume in the three tables. For table `test.tbl_ttl_2`, only check the number of rows where the value of column `cstate` is `1`, which corresponds to an expiration time of one minute added to the value in the `created_at` column. You will observe that the data volume in the table begins to increase.

  ```sql
  SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  ```

  ```output
  mysql> SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  +----------+
  | COUNT(*) |
  +----------+
  |      220 |
  +----------+
  1 row in set (0.01 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |      118 |
  +----------+
  1 row in set (0.00 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |      220 |
  +----------+
  1 row in set (0.00 sec)
  ```

### Step 6. Disabling and Enabling the TTL Attributes in TiDB

+ On [Terminal 1](ssh://monitor1-ssh#1), set the global variable `tidb_ttl_job_enable` to `OFF`.

  ```sql
  SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  SET GLOBAL tidb_ttl_job_enable='OFF';
  SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  ```

  ```output
  mysql> SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  +---------------------+-------+
  | Variable_name       | Value |
  +---------------------+-------+
  | tidb_ttl_job_enable | ON    |
  +---------------------+-------+
  1 row in set (0.00 sec)

  mysql> SET GLOBAL tidb_ttl_job_enable='OFF';
  Query OK, 0 rows affected (0.02 sec)

  mysql> SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  +---------------------+-------+
  | Variable_name       | Value |
  +---------------------+-------+
  | tidb_ttl_job_enable | OFF   |
  +---------------------+-------+
  1 row in set (0.00 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), use the system tables `information_schema.tables` and `mysql.tidb_ttl_table_status` to view the current TTL task information. It will be found that there are no TTL tasks running on the three tables. Note: It may take 3 to 5 minutes to produce the expected results, so please be patient. Alternatively, you can proceed with the following operations, which will not affect the subsequent steps.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  *************************** 1. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_1
                        table_id: 110
                parent_table_id: 110
                table_statistics: NULL
                    last_job_id: 85188517dd1342cb980eab52b9a77475
            last_job_start_time: 2025-09-07 10:51:01
            last_job_finish_time: 2025-09-07 10:53:10
            last_job_ttl_expire: 2025-09-07 10:50:01
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":16,"scheduled_scan_task":16,"finished_scan_task":16}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  *************************** 2. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_2
                        table_id: 112
                parent_table_id: 112
                table_statistics: NULL
                    last_job_id: a25399e2b753437b8987c2ea5c1a6369
            last_job_start_time: 2025-09-07 10:53:02
            last_job_finish_time: 2025-09-07 10:55:19
            last_job_ttl_expire: 2025-09-07 10:53:02
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":0,"scheduled_scan_task":0,"finished_scan_task":0,"scan_task_err":"tidb_ttl_job_enable turned off"}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  *************************** 3. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_3
                        table_id: 114
                parent_table_id: 114
                table_statistics: NULL
                    last_job_id: 22b7914f44ca4243b09e97e18cbb80d0
            last_job_start_time: 2025-09-07 10:47:57
            last_job_finish_time: 2025-09-07 10:51:10
            last_job_ttl_expire: 2025-09-07 10:46:57
                last_job_summary: {"total_rows":1000,"success_rows":1000,"error_rows":0,"total_scan_task":16,"scheduled_scan_task":16,"finished_scan_task":16}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  3 rows in set (0.02 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), set the global variable `tidb_ttl_job_enable` to `ON`.

  ```sql
  SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  SET GLOBAL tidb_ttl_job_enable='ON';
  SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  ```

  ```output
  mysql> SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  +---------------------+-------+
  | Variable_name       | Value |
  +---------------------+-------+
  | tidb_ttl_job_enable | OFF   |
  +---------------------+-------+
  1 row in set (0.00 sec)

  mysql> SET GLOBAL tidb_ttl_job_enable='ON';
  Query OK, 0 rows affected (0.01 sec)

  mysql> SHOW GLOBAL VARIABLES LIKE 'tidb_ttl_job_enable';
  +---------------------+-------+
  | Variable_name       | Value |
  +---------------------+-------+
  | tidb_ttl_job_enable | ON    |
  +---------------------+-------+
  1 row in set (0.00 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), again, use the system tables `information_schema.tables` and `mysql.tidb_ttl_table_status` to view the current TTL task information. After executing this several times, you will find that the TTL tasks have restarted on the tables. Note: It may take 3 to 5 minutes to produce the expected results, so please be patient. Alternatively, you can proceed with the following operations, which will not affect the subsequent steps.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  *************************** 1. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_1
                        table_id: 110
                parent_table_id: 110
                table_statistics: NULL
                    last_job_id: 85188517dd1342cb980eab52b9a77475
            last_job_start_time: 2025-09-07 10:51:01
            last_job_finish_time: 2025-09-07 10:53:10
            last_job_ttl_expire: 2025-09-07 10:50:01
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":16,"scheduled_scan_task":16,"finished_scan_task":16}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  *************************** 2. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_2
                        table_id: 112
                parent_table_id: 112
                table_statistics: NULL
                    last_job_id: a25399e2b753437b8987c2ea5c1a6369
            last_job_start_time: 2025-09-07 10:53:02
            last_job_finish_time: 2025-09-07 10:55:19
            last_job_ttl_expire: 2025-09-07 10:53:02
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":0,"scheduled_scan_task":0,"finished_scan_task":0,"scan_task_err":"tidb_ttl_job_enable turned off"}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  *************************** 3. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_3
                        table_id: 114
                parent_table_id: 114
                table_statistics: NULL
                    last_job_id: 22b7914f44ca4243b09e97e18cbb80d0
            last_job_start_time: 2025-09-07 10:47:57
            last_job_finish_time: 2025-09-07 10:51:10
            last_job_ttl_expire: 2025-09-07 10:46:57
                last_job_summary: {"total_rows":1000,"success_rows":1000,"error_rows":0,"total_scan_task":16,"scheduled_scan_task":16,"finished_scan_task":16}
                  current_job_id: 2722bcbe1fe544839ccaa6c1d31d7e10
            current_job_owner_id: 84823e1f-e42a-4dc8-bc6e-e4fdaf2ba114
          current_job_owner_addr: NULL
      current_job_owner_hb_time: 2025-09-07 11:02:50
          current_job_start_time: 2025-09-07 11:01:18
          current_job_ttl_expire: 2025-09-07 11:00:18
              current_job_state: NULL
              current_job_status: running
  current_job_status_update_time: 2025-09-07 11:01:18
  3 rows in set (0.02 sec)
  ```

### Step 7. Disabling and Enabling the TTL Attributes of Tables

+ On [Terminal 1](ssh://monitor1-ssh#1), set the `TTL_ENABLE` attribute of tables `test.tbl_ttl_2` and `test.tbl_ttl_3` to `OFF`, and remove all TTL attributes from table `test.tbl_ttl_1`.

  ```sql
  ALTER TABLE test.tbl_ttl_2 TTL_ENABLE = 'OFF';
  ALTER TABLE test.tbl_ttl_3 TTL_ENABLE = 'OFF';
  ALTER TABLE test.tbl_ttl_1 REMOVE TTL;
  ```

  ```output
  mysql> ALTER TABLE test.tbl_ttl_2 TTL_ENABLE = 'OFF';
  Query OK, 0 rows affected (0.06 sec)

  mysql> ALTER TABLE test.tbl_ttl_3 TTL_ENABLE = 'OFF';
  Query OK, 0 rows affected (0.06 sec)

  mysql> ALTER TABLE test.tbl_ttl_1 REMOVE TTL;
  Query OK, 0 rows affected (0.07 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), use the system tables `information_schema.tables` and `mysql.tidb_ttl_table_status` to view the current TTL task information. After executing this several times, the results will be empty. Note: It may take 3 to 5 minutes to produce the expected results, so please be patient. Alternatively, you can proceed with the following operations, which will not affect the subsequent steps.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  *************************** 1. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_1
                        table_id: 116
                parent_table_id: 116
                table_statistics: NULL
                    last_job_id: 2b6d5038ff0547f3a3fc757c3249fdce
            last_job_start_time: 2025-09-07 06:21:27
            last_job_finish_time: 2025-09-07 06:22:28
            last_job_ttl_expire: 2025-09-07 06:20:27
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":0,"scheduled_scan_task":0,"finished_scan_task":0,"scan_task_err":"TTL table has been removed or the TTL on this table has been stopped"}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  *************************** 2. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_2
                        table_id: 118
                parent_table_id: 118
                table_statistics: NULL
                    last_job_id: f37814e4203846d0b6529041dd3457d3
            last_job_start_time: 2025-09-07 05:56:43
            last_job_finish_time: 2025-09-07 06:00:09
            last_job_ttl_expire: 2025-09-07 05:56:43
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":16,"scheduled_scan_task":16,"finished_scan_task":16}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  *************************** 3. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_3
                        table_id: 120
                parent_table_id: 120
                table_statistics: NULL
                    last_job_id: 2daa646b1eed4c49a101a4d3df1515a1
            last_job_start_time: 2025-09-07 06:19:03
            last_job_finish_time: 2025-09-07 06:21:19
            last_job_ttl_expire: 2025-09-07 06:18:03
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":0,"scheduled_scan_task":0,"finished_scan_task":0,"scan_task_err":"TTL table has been removed or the TTL on this table has been stopped"}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  3 rows in set (0.02 sec)
  ```

+ After 3 to 5 minutes, the query results will still be empty.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  Empty set (0.02 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), set the `TTL_ENABLE` attribute of tables `test.tbl_ttl_1`, `test.tbl_ttl_2`, and `test.tbl_ttl_3` to `ON`. The command for table `test.tbl_ttl_1` will fail because all TTL attributes for that table have been removed.

  ```sql
  ALTER TABLE test.tbl_ttl_2 TTL_ENABLE = 'ON';
  ALTER TABLE test.tbl_ttl_3 TTL_ENABLE = 'ON';
  ALTER TABLE test.tbl_ttl_1 TTL_ENABLE = 'ON';
  ```

  ```output
  mysql> ALTER TABLE test.tbl_ttl_2 TTL_ENABLE = 'ON';
  Query OK, 0 rows affected (0.51 sec)

  mysql> ALTER TABLE test.tbl_ttl_3 TTL_ENABLE = 'ON';
  Query OK, 0 rows affected (0.51 sec)

  mysql> ALTER TABLE test.tbl_ttl_1 TTL_ENABLE = 'ON';
  ERROR 8150 (HY000): Cannot set TTL_ENABLE on a table without TTL config
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), use the system tables `information_schema.tables` and `mysql.tidb_ttl_table_status` to view the current TTL task information. After executing this several times, it will be found that the TTL tasks have restarted on tables `test.tbl_ttl_2` and `test.tbl_ttl_3`. Note: It may take 3 to 5 minutes to produce the expected results, so please be patient. Alternatively, you can proceed with the following operations, which will not affect the subsequent steps.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  *************************** 1. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_2
                        table_id: 118
                parent_table_id: 118
                table_statistics: NULL
                    last_job_id: aef75a31eb844b70862d37abe1445837
            last_job_start_time: 2025-09-07 06:46:34
            last_job_finish_time: 2025-09-07 06:46:39
            last_job_ttl_expire: 2025-09-07 06:46:34
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":1,"scheduled_scan_task":1,"finished_scan_task":1}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  *************************** 2. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_3
                        table_id: 120
                parent_table_id: 120
                table_statistics: NULL
                    last_job_id: c3b0bda2789c4c2580e8a4a1c29b3f46
            last_job_start_time: 2025-09-07 06:45:55
            last_job_finish_time: 2025-09-07 06:46:09
            last_job_ttl_expire: 2025-09-07 06:44:55
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":1,"scheduled_scan_task":1,"finished_scan_task":1}
                  current_job_id: be5877fc6b724882aef1ebd289f29545
            current_job_owner_id: 52b4aed5-367c-45d9-b421-29b9772061d1
          current_job_owner_addr: NULL
      current_job_owner_hb_time: 2025-09-07 06:46:59
          current_job_start_time: 2025-09-07 06:46:55
          current_job_ttl_expire: 2025-09-07 06:45:55
              current_job_state: NULL
              current_job_status: running
  current_job_status_update_time: 2025-09-07 06:46:55
  2 rows in set (0.02 sec)
  ```

### Step 8. Observing the Impact of FLASHBACK TABLE on Table TTL Attributes

+ On [Terminal 1](ssh://monitor1-ssh#1), first, delete table `test.tbl_ttl_2` and run it. Then, run the command to check the amount of data in tables `test.tbl_ttl_1`, `test.tbl_ttl_2`, and `test.tbl_ttl_3`. The result shows that table `test.tbl_ttl_2` no longer exists.

  ```sql
  DROP TABLE test.tbl_ttl_2;
  SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  ```

  ```output
  mysql> DROP TABLE test.tbl_ttl_2;
  Query OK, 0 rows affected (0.51 sec)
  mysql> SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  +----------+
  | COUNT(*) |
  +----------+
  |     3581 |
  +----------+
  1 row in set (0.01 sec)

  ERROR 1146 (42S02): Table 'test.tbl_ttl_2' doesn't exist
  +----------+
  | COUNT(*) |
  +----------+
  |      172 |
  +----------+
  1 row in set (0.01 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), execute the `FLASHBACK TABLE` command for the recently deleted table `test.tbl_ttl_2`.

  ```sql
  FLASHBACK TABLE test.tbl_ttl_2;
  ```

  ```output
  mysql> FLASHBACK TABLE test.tbl_ttl_2;
  Query OK, 0 rows affected (0.52 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), check the data volume in the three tables again. For table `test.tbl_ttl_2`, only check the number of rows where the value of column `cstate` is `1`, which corresponds to an expiration time of one minute added to the value in the `created_at` column. You will find that table `test.tbl_ttl_2` has been restored.

  ```sql
  SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  ```

  ```output
  mysql> SELECT COUNT(*) FROM test.tbl_ttl_1;SELECT COUNT(*) FROM test.tbl_ttl_2 WHERE cState=1;SELECT COUNT(*) FROM test.tbl_ttl_3;
  +----------+
  | COUNT(*) |
  +----------+
  |     3581 |
  +----------+
  1 row in set (0.01 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |      101 |
  +----------+
  1 row in set (0.01 sec)

  +----------+
  | COUNT(*) |
  +----------+
  |       54 |
  +----------+
  1 row in set (0.01 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), examine the definition of table `test.tbl_ttl_2` and find that after the `FLASHBACK TABLE`, the TTL attribute `TTL_ENABLE` is set to 'OFF', indicating that the TTL attributes for this table have been automatically disabled.

  ```sql
  SHOW CREATE TABLE test.tbl_ttl_2\G
  ```

  ```output
  mysql> SHOW CREATE TABLE test.tbl_ttl_2\G
  *************************** 1. row ***************************
        Table: tbl_ttl_2
  Create Table: CREATE TABLE `tbl_ttl_2` (
    `ID` bigint NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
    `pState` varchar(100) NOT NULL,
    `cState` tinyint DEFAULT NULL,
    `created_at` datetime DEFAULT NULL,
    `updated_at` datetime DEFAULT NULL,
    `expire_at` datetime GENERATED ALWAYS AS (if(`cState` = 1, date_add(`created_at`, interval 1 minute), date_add(`created_at`, interval 2 day))) VIRTUAL,
    `txt` varchar(64) DEFAULT 'TTLTEST',
    PRIMARY KEY (`ID`) /*T![clustered_index] CLUSTERED */,
    KEY `pcStateIndex` (`pState`,`cState`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=30001 */ /*T! PRE_SPLIT_REGIONS=4 */ /*T![ttl] TTL=`expire_at` + INTERVAL 0 MINUTE */ /*T![ttl] TTL_ENABLE='OFF' */ /*T![ttl] TTL_JOB_INTERVAL='1m' */
  1 row in set (0.01 sec)
  ```

+ On [Terminal 1](ssh://monitor1-ssh#1), use the system tables `information_schema.tables` and `mysql.tidb_ttl_table_status` to view the current TTL task information. After executing this several times, it will be found that only the TTL task on table `test.tbl_ttl_3` is currently running. Note: It may take 3 to 5 minutes to produce the expected results, so please be patient. Alternatively, you can proceed with the following operations, which will not affect the subsequent steps.

  ```sql
  SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  ```

  ```output
  mysql> SELECT A.TABLE_SCHEMA, A.TABLE_NAME, B.* FROM information_schema.tables A, mysql.tidb_ttl_table_status B WHERE A.tidb_table_ID=B.table_id\G
  *************************** 1. row ***************************
                    TABLE_SCHEMA: test
                      TABLE_NAME: tbl_ttl_3
                        table_id: 120
                parent_table_id: 120
                table_statistics: NULL
                    last_job_id: e0b4af3e300841758dfa3f470dafad18
            last_job_start_time: 2025-09-07 06:54:55
            last_job_finish_time: 2025-09-07 06:55:09
            last_job_ttl_expire: 2025-09-07 06:53:55
                last_job_summary: {"total_rows":0,"success_rows":0,"error_rows":0,"total_scan_task":1,"scheduled_scan_task":1,"finished_scan_task":1}
                  current_job_id: NULL
            current_job_owner_id: NULL
          current_job_owner_addr: NULL
      current_job_owner_hb_time: NULL
          current_job_start_time: NULL
          current_job_ttl_expire: NULL
              current_job_state: NULL
              current_job_status: NULL
  current_job_status_update_time: NULL
  1 row in set (0.02 sec)
  ```

### Step 9. Cleanup Data

+ On [Terminal 1](ssh://monitor1-ssh#1), drop tables `tbl_ttl_1`, `tbl_ttl_2`, and `tbl_ttl_3` under the `test` schema.

  ```sql
  DROP TABLE test.tbl_ttl_1;
  DROP TABLE test.tbl_ttl_2;
  DROP TABLE test.tbl_ttl_3;
  ```

  ```output
  mysql> DROP TABLE test.tbl_ttl_1;
  Query OK, 0 rows affected (0.52 sec)

  mysql> DROP TABLE test.tbl_ttl_2;
  Query OK, 0 rows affected (0.52 sec)

  mysql> DROP TABLE test.tbl_ttl_3;
  Query OK, 0 rows affected (0.51 sec)
  ```

+ This is the end of Module 2.
