点击上方“IT那活儿”公众号--专注于企业全栈运维技术分享,不管IT什么活儿,干就完了!!!
每次查询读取大量的行,但是仅需要少量的列; 宽表,即每个表包含着大量的列; 查询通过一张或多张小表关联一张大表,并对大表上的列做聚合。
每次查询可以只读取需要的列,减少了 I/O 资源的使用; 同列数据类型相同,相较于行存可以获得更高的压缩比; 整体的 I/O 减少,令内存的使用更加高效。
列式存储可以很方便地按批处理字段,充分利用 CPU Cache 取得更好的局部性; 利用向量化处理指令并行处理部分计算。

mysql> CREATE TABLE customers (
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> name VARCHAR(100),
-> email VARCHAR(100),
-> created_at DATETIME
-> ) ;
Query OK, 0 rows affected (0.71 sec)
mysql> CREATE TABLE orders (
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> customer_id INT,
-> product_id INT,
-> quantity INT,
-> price DECIMAL(10, 2),
-> timestamp DATETIME
-> ) ;
Query OK, 0 rows affected (0.46 sec)
mysql> CREATE TABLE products (
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> name VARCHAR(100),
-> category VARCHAR(100),
-> price DECIMAL(10, 2)
-> ) ;
Query OK, 0 rows affected (0.56 sec)
-- 顾客表插入100万行数据
mysql> INSERT INTO customers (name, email, created_at)
-> SELECT
-> CONCAT('Customer', seq),
-> CONCAT('customer', seq, '@example.com'),
-> NOW()
-> FROM
-> (SELECT seq FROM seq_1_to_1000000) s;
Query OK, 1000000 rows affected (11.96 sec)
Records: 1000000 Duplicates: 0 Warnings: 0
-- 产品表插入1000行数据
mysql> INSERT INTO products (name, category, price)
-> SELECT
-> CONCAT('Product', seq),
-> CONCAT('Category', FLOOR(RAND()*(10-1+1))+1),
-> ROUND(RAND()*(1000-1+1), 2)
-> FROM
-> (SELECT seq FROM seq_1_to_1000) s;
Query OK, 1000 rows affected (0.91 sec)
Records: 1000 Duplicates: 0 Warnings: 0
mysql>


mysql> ALTER TABLE test.customers SET TIFLASH REPLICA 1;
Query OK, 0 rows affected, 1 warning (0.87 sec)
mysql> ALTER TABLE test.orders SET TIFLASH REPLICA 1;
Query OK, 0 rows affected, 1 warning (1.65 sec)
mysql> ALTER TABLE test.products SET TIFLASH REPLICA 1;
Query OK, 0 rows affected, 1 warning (0.85 sec)
查看表同步进度:
mysql> SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = 'test' and TABLE_NAME = 'customers';
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | REPLICA_COUNT | LOCATION_LABELS | AVAILABLE | PROGRESS |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| test | customers | 123 | 2 | | 0 | 0 |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
1 row in set (0.64 sec)
mysql> SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = 'test' and TABLE_NAME = 'orders';
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | REPLICA_COUNT | LOCATION_LABELS | AVAILABLE | PROGRESS |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| test | orders | 134 | 2 | | 0 | 0 |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
1 row in set (0.49 sec)
mysql> SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = 'test' and TABLE_NAME = 'products';
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | REPLICA_COUNT | LOCATION_LABELS | AVAILABLE | PROGRESS |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| test | products | 128 | 2 | | 0 | 0 |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
1 row in set (0.52 sec)
mysql> SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = 'test' and TABLE_NAME = 'customers';
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | REPLICA_COUNT | LOCATION_LABELS | AVAILABLE | PROGRESS |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| test | customers | 123 | 2 | | 1 | 1 |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
1 row in set (1.94 sec)
mysql> SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = 'test' and TABLE_NAME = 'products';
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | REPLICA_COUNT | LOCATION_LABELS | AVAILABLE | PROGRESS |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| test | products | 128 | 2 | | 1 | 1 |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
1 row in set (0.77 sec)
mysql> SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = 'test' and TABLE_NAME = 'orders';
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_ID | REPLICA_COUNT | LOCATION_LABELS | AVAILABLE | PROGRESS |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
| test | orders | 134 | 2 | | 1 | 1 |
+--------------+------------+----------+---------------+-----------------+-----------+----------+
1 row in set (0.66 sec)



本文作者:韦宝军(上海新炬中北团队)
本文来源:“IT那活儿”公众号

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




