MySQL 8.0新特性中并行查詢innodb及并行讀取線程是怎樣的,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
公司主營業(yè)務(wù):成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出岳塘免費做網(wǎng)站回饋大家。長久以來MySQL沒有并行查詢,并且在其他數(shù)據(jù)庫已經(jīng)有了的情況下,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)
任何事情沒有一開始就完美,而是日復(fù)一日的堅持,對MySQL來說,這是一個很好的開端,并為真正的并行查詢執(zhí)行開辟了一條道路。
下面是我的測試結(jié)果
mysql>set local innodb_parallel_read_threads = 1; 執(zhí)行成功,耗時:8 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:2275 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:2316 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:2191 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:2196 ms. mysql>set local innodb_parallel_read_threads = 16; 執(zhí)行成功,耗時:8 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:594 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:557 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:570 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:594 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:582 ms. mysql>set local innodb_parallel_read_threads=32; 執(zhí)行成功,耗時:9 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:265 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:251 ms. mysql>set local innodb_parallel_read_threads=64; 執(zhí)行成功,耗時:9 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:340 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:363 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:306 ms. mysql>set local innodb_parallel_read_threads=32; 執(zhí)行成功,耗時:9 ms. mysql>select count(*) from PARALLELTEST; +--------------------+ | count(*) | +--------------------+ | 9175040 | +--------------------+ 返回行數(shù):[1],耗時:276 ms.
和文章中的結(jié)論一致,但是我參數(shù)設(shè)置到64的360ms 時反而比32時200多ms慢,也是符合預(yù)期的,與Oracle類似
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。