您好,登錄后才能下訂單哦!
MySQL 8.0新特性中并行查詢innodb及并行讀取線程是怎樣的,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
長久以來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類似
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。