原文很好翻译,直接读好理解
长久以来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 defaultQuery 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. |

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70015609/viewspace-2883533/ ,如需转载,请注明出处,否则将追究法律责任。