Docs
tidb
Operation Guide
TiDB
TiFlash Management

How to Use TiFlash

Introduction

TiFlash is a key component of TiDB’s HTAP mode. With TiFlash enabled, the user’s requirements for analytic business scenarios can be better met.

Step One: Enable TiFlash

Switch to the “TiFlash” panel in the details page.

Click on the ‘Enable TiFlash’ button to open the activation window.

Confirm node specifications, costs, and then click on Purchase Now.

Step Two: Build TiFlash replicas by table

Creating TiFlash replicas.

ALTER TABLE table_name SET TIFLASH REPLICA count;

The count stands for the number of replicas, 0 means deletion. The count number should not exceed the number of active TiFlash nodes.

Viewing the table synchronization progress

SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = '<db_name>' and TABLE_NAME = '<table_name>';

In the query result, the AVAILABLE field indicates whether this table's TiFlash replica is available. 1 means available, and 0 means unavailable. The replica status won't change after it is available, unless the replica number is modified with a DDL command which would then recalculate the sync progress.
The PROGRESS field represents sync progress, ranging from 0.0 to 1.0, with 1 indicating that at least one replica has finished syncing.

Step Three: Using TiFlash

After synchronization is complete, the TiDB optimizer will automatically select whether to use TiFlash replica based on cost estimation. To verify if the TiFlash replica was selected, you can check through the desc or explain analyze command, for instance:

desc select count(*) from test.t;
+--------------------------+---------+--------------+---------------+--------------------------------+
| id                       | estRows | task         | access object | operator info                  |
+--------------------------+---------+--------------+---------------+--------------------------------+
| StreamAgg_9              | 1.00    | root         |               | funcs:count(1)->Column#4       |
| └─TableReader_17         | 1.00    | root         |               | data:TableFullScan_16          |
|   └─TableFullScan_16     | 1.00    | cop[tiflash] | table:t       | keep order:false, stats:pseudo |
+--------------------------+---------+--------------+---------------+--------------------------------+
3 rows in set (0.00 sec)
explain analyze select count(*) from test.t;
+--------------------------+---------+---------+--------------+---------------+----------------------------------------------------------------------+--------------------------------+-----------+------+
| id                       | estRows | actRows | task         | access object | execution info                                                       | operator info                  | memory    | disk |
+--------------------------+---------+---------+--------------+---------------+----------------------------------------------------------------------+--------------------------------+-----------+------+
| StreamAgg_9              | 1.00    | 1       | root         |               | time:83.8372ms, loops:2                                              | funcs:count(1)->Column#4       | 372 Bytes | N/A  |
| └─TableReader_17         | 1.00    | 1       | root         |               | time:83.7776ms, loops:2, rpc num: 1, rpc time:83.5701ms, proc keys:0 | data:TableFullScan_16          | 152 Bytes | N/A  |
|   └─TableFullScan_16     | 1.00    | 1       | cop[tiflash] | table:t       | time:43ms, loops:1                                                   | keep order:false, stats:pseudo | N/A       | N/A  |
+--------------------------+---------+---------+--------------+---------------+----------------------------------------------------------------------+--------------------------------+-----------+------+

Close TiFlash

Closing TiFlash replicas.

ALTER TABLE table_name SET TIFLASH REPLICA 0;

Closing TiFlash service.

You can simply shut down the TiFlash service by clicking on the ‘Close TiFlash’ button in the “TiFlash” panel.

  • Official Documentation

https://docs.pingcap.com/zh/tidb/v4.0/use-tiflash