8.0新特性-並行查詢innodb_parallel_read_threads

哎呀我的天吶發表於2020-04-11

原文: https://www.percona.com/blog/2019/01/23/mysql-8-0-14-a-road-to-parallel-query-execution-is-wide-open/

原文很好翻譯,直接讀好理解 8.0新特性-並行查詢innodb_parallel_read_threads

長久以來MySQL沒有並行查詢,並且在其他資料庫已經有了的情況下,MySQL終於在8.0.14版本開始有了自己的並行查詢,但使用面非常的窄,只適用於並行聚集索引的count(*) 並且只是在沒有where條件的情況下的查詢

mysql> set local innodb_parallel_read_threads=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select count(*) from ontime;
+-----------+
| count(*)  |
+-----------+
| 177920306 |
+-----------+
1 row in set (2 min 33.93 sec)
mysql> set local innodb_parallel_read_threads=DEFAULT; -- 4 is default
Query OK, 0 rows affected (0.00 sec)
mysql> select count(*) from ontime;
+-----------+
| count(*)  |
+-----------+
| 177920306 |
+-----------+
1 row in set (21.85 sec)
mysql> set local innodb_parallel_read_threads=32;
Query OK, 0 rows affected (0.00 sec)
mysql> select count(*) from ontime;
+-----------+
| count(*)  |
+-----------+
| 177920306 |
+-----------+
1 row in set (5.35 sec)


任何事情沒有一開始就完美,而是日復一日的堅持,對MySQL來說,這是一個很好的開端,併為真正的並行查詢執行開闢了一條道路。


下面是我的測試結果

mysql>set local innodb_parallel_read_threads = 1;
執行成功,耗時:8 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:2275 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:2316 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:2191 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:2196 ms.
mysql>set local innodb_parallel_read_threads = 16;
執行成功,耗時:8 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:594 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:557 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:570 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:594 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:582 ms.
mysql>set local innodb_parallel_read_threads=32;
執行成功,耗時:9 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:265 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:251 ms.
mysql>set local innodb_parallel_read_threads=64;
執行成功,耗時:9 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:340 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:363 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:306 ms.
mysql>set local innodb_parallel_read_threads=32;
執行成功,耗時:9 ms.
mysql>select count(*) from PARALLELTEST;
+--------------------+
| count(*)           |
+--------------------+
| 9175040            |
+--------------------+
返回行數:[1],耗時:276 ms.

結論:和文章中的結論一致,但是我引數設定到64的360ms 時反而比32時200多ms慢,也是符合預期的,與Oracle類似

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-2685554/,如需轉載,請註明出處,否則將追究法律責任。

相關文章