MySQL 8.0新特性中并行查詢innodb及并行讀取線程是怎樣的,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)蕪湖免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了1000多家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
長(zhǎng)久以來(lái)MySQL沒(méi)有并行查詢,并且在其他數(shù)據(jù)庫(kù)已經(jīng)有了的情況下,MySQL終于在8.0.14版本開(kāi)始有了自己的并行查詢,但使用面非常的窄,只適用于并行聚集索引的count(*) 并且只是在沒(méi)有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)
任何事情沒(méi)有一開(kāi)始就完美,而是日復(fù)一日的堅(jiān)持,對(duì)MySQL來(lái)說(shuō),這是一個(gè)很好的開(kāi)端,并為真正的并行查詢執(zhí)行開(kāi)辟了一條道路。
下面是我的測(cè)試結(jié)果
mysql>set local innodb_parallel_read_threads = 1; 執(zhí)行成功,耗時(shí):8 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):2275 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):2316 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):2191 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):2196 ms. mysql>set local innodb_parallel_read_threads = 16; 執(zhí)行成功,耗時(shí):8 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):594 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):557 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):570 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):594 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):582 ms. mysql>set local innodb_parallel_read_threads=32; 執(zhí)行成功,耗時(shí):9 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):265 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):251 ms. mysql>set local innodb_parallel_read_threads=64; 執(zhí)行成功,耗時(shí):9 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):340 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):363 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):306 ms. mysql>set local innodb_parallel_read_threads=32; 執(zhí)行成功,耗時(shí):9 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時(shí):276 ms.
和文章中的結(jié)論一致,但是我參數(shù)設(shè)置到64的360ms 時(shí)反而比32時(shí)200多ms慢,也是符合預(yù)期的,與Oracle類似
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。