tiflash 问题请教

请教个问题哈,我们现在 tiflash 是否支持从 tikv 上取部分数据,然后再去 tiflash 上做 join 呢?

1 个赞

现在应该是不支持

二选一,应该是不支持的。不过一个语句join的两个表,可以一个走tikv,一个走tiflash吧,然后再tidb里join :yum:

tiflash用不了行存数据。所以原因还是存储紧张?可以考虑将tiflash副本放到s3上。

https://docs.pingcap.com/zh/tidb/stable/tiflash-disaggregated-and-s3#tiflash-存算分离架构与-s3-支持

不行

CREATE TABLE users (
    id INT PRIMARY KEY,
    name VARCHAR(255),
    city VARCHAR(255)
);

CREATE TABLE orders (
    id INT PRIMARY KEY,
    user_id INT,
    amount DECIMAL(10, 2),
    KEY idx_user_id (user_id)
);


INSERT INTO users (id, name, city) VALUES
(1, 'Alice', 'Beijing'),
(2, 'Bob', 'Shanghai'),
(3, 'Charlie', 'Guangzhou');

INSERT INTO orders (id, user_id, amount) VALUES
(1, 1, 100.00),
(2, 2, 200.00),
(3, 3, 300.00);

SELECT /*+ read_from_storage(tiflash[u]) */
u.name, o.amount
FROM users u
JOIN orders o ON u.id = o.user_id
where u.id=1;



(root@127.0.0.1) [test]>select * from information_schema.tiflash_replica;
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | REPLICA_COUNT | LOCATION_LABELS | AVAILABLE | PROGRESS |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| test         | t11        |      111 |             1 |                 |         1 |        1 |
| test         | users      |      190 |             1 |                 |         1 |        1 |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
2 rows in set (0.01 sec)

(root@127.0.0.1) [test]>set tidb_enforce_mpp=ON;
Query OK, 0 rows affected (0.00 sec)

(root@127.0.0.1) [test]>explain SELECT /*+ read_from_storage(tiflash[u]) */ u.name, o.amount FROM users u JOIN orders o ON u.id = o.user_id where u.id=1;
+--------------------------------------+---------+--------------+-------------------------------------+---------------------------------------------------------------------+
| id                                   | estRows | task         | access object                       | operator info                                                       |
+--------------------------------------+---------+--------------+-------------------------------------+---------------------------------------------------------------------+
| Projection_10                        | 0.00    | root         |                                     | test.users.name, test.orders.amount                                 |
| └─HashJoin_12                        | 0.00    | root         |                                     | CARTESIAN inner join                                                |
|   ├─IndexLookUp_18(Build)            | 0.00    | root         |                                     |                                                                     |
|   │ ├─IndexRangeScan_16(Build)       | 0.00    | cop[tikv]    | table:o, index:idx_user_id(user_id) | range:[1,1], keep order:false, stats:partial[user_id:unInitialized] |
|   │ └─TableRowIDScan_17(Probe)       | 0.00    | cop[tikv]    | table:o                             | keep order:false, stats:partial[user_id:unInitialized]              |
|   └─TableReader_21(Probe)            | 1.00    | root         |                                     | data:TableRangeScan_20                                              |
|     └─TableRangeScan_20              | 1.00    | cop[tiflash] | table:u                             | range:[1,1], keep order:false, stats:pseudo                         |
+--------------------------------------+---------+--------------+-------------------------------------+---------------------------------------------------------------------+
7 rows in set, 1 warning (0.01 sec)

(root@127.0.0.1) [test]>show warnings;
+---------+------+----------------------------------------------------------------------------------+
| Level   | Code | Message                                                                          |
+---------+------+----------------------------------------------------------------------------------+
| Warning | 1105 | MPP mode may be blocked because there aren't tiflash replicas of table `orders`. |
+---------+------+----------------------------------------------------------------------------------+
1 row in set (0.00 sec)
2 个赞