Docs
tidb
Operation Guide
TiDBServerless
TiFlash management

How to Use TiFlash

Introduction

TiFlash is a key component of TiDB’s HTAP form. After enabling TiFlash, it can better meet the needs of users’ analytical business scenarios.

Step One: Enable TiFlash

Click the button, select the number of TiFlash nodes, confirm to enable, and ensure that the TiFlash status is “enabled”.

Step Two: Build TiFlash Copies by Table

Build TiFlash copies

ALTER TABLE table_name SET TIFLASH REPLICA count;

count represents the number of copies, 0 means delete. The count number does not exceed the number of TiFlash nodes that have been enabled.

Check table synchronization progress

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

The AVAILABLE field in the query result indicates whether the TiFlash replica of this table is available. 1 represents available, 0 represents not available. The replica status will not change after it is available. If the number of replicas is modified through the DDL command, the synchronization progress will be recalculated.
The PROGRESS field represents the synchronization progress, between 0.0~1.0, 1 represents that at least 1 replica has completed synchronization.

Step Three: Use TiFlash

After synchronization is completed, the TiDB optimizer will automatically decide whether to use TiFlash replicas based on cost estimation. Whether TiFlash replicas have been selected can be viewed through the desc or explain analyze statement, for example:

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  |
+--------------------------+---------+---------+--------------+---------------+----------------------------------------------------------------------+--------------------------------+-----------+------+
  • Official documents

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