MySQL 8.0 Reference Manual(讀書筆記84節-- InnoDB and Online DDL (4))

来源:https://www.cnblogs.com/xuliuzai/p/18119965
-Advertisement-
Play Games

1.綜述 Hive的聚合函數衍生的視窗函數在我們進行數據處理和數據分析過程中起到了很大的作用 在Hive中,視窗函數允許你在結果集的行上進行計算,這些計算不會影響你查詢的結果集的行數。 Hive提供的視窗和分析函數可以分為聚合函數類視窗函數,分組排序類視窗函數,偏移量計算類視窗函數。 本節主要介紹聚 ...


1.Online DDL Space Requirements

Disk space requirements for online DDL operations are outlined【ˈaʊtlaɪnd 概述;略述;顯示…的輪廓;勾勒…的外形;】 below. The requirements do not apply to operations that are performed instantly.

• Temporary log files:

A temporary log file records concurrent DML when an online DDL operation creates an index or alters a table. The temporary log file is extended as required by the value of innodb_sort_buffer_size up to a maximum specified by innodb_online_alter_log_max_size. If the operation takes a long time and concurrent DML modifies the table so much that the size of the temporary log file exceeds the value of innodb_online_alter_log_max_size, the online DDL operation fails with a DB_ONLINE_LOG_TOO_BIG error, and uncommitted concurrent DML operations are rolled back. A large innodb_online_alter_log_max_size setting permits more DML during an online DDL operation, but it also extends the period of time at the end of the DDL operation when the table is locked to apply logged DML.

The innodb_sort_buffer_size variable also defines the size of the temporary log file read buffer and write buffer.

• Temporary sort files:

Online DDL operations that rebuild the table write temporary sort files to the MySQL temporary directory ($TMPDIR on Unix, %TEMP% on Windows, or the directory specified by --tmpdir) during index creation. Temporary sort files are not created in the directory that contains the original table. Each temporary sort file is large enough to hold one column of data, and each sort file is removed when its data is merged into the final table or index. Operations involving temporary sort files may require temporary space equal to the amount of data in the table plus indexes. An error is reported if online DDL operation uses all of the available disk space on the file system where the data directory resides.

If the MySQL temporary directory is not large enough to hold the sort files, set tmpdir to a different directory. Alternatively, define a separate temporary directory for online DDL operations using innodb_tmpdir. This option was introduced to help avoid temporary directory overflows that could occur as a result of large temporary sort files.

• Intermediate table files:

Some online DDL operations that rebuild the table create a temporary intermediate table file in the same directory as the original table. An intermediate table file may require space equal to the size of the original table. Intermediate table file names begin with #sql-ib prefix and only appear briefly during the online DDL operation.

The innodb_tmpdir option is not applicable to intermediate table files.

2. Online DDL Memory Management

Online DDL operations that create or rebuild secondary indexes allocate temporary buffers during different phases of index creation. The innodb_ddl_buffer_size variable, introduced in MySQL 8.0.27, defines the maximum buffer size for online DDL operations. The default setting is 1048576 bytes (1 MB). The setting applies to buffers created by threads executing online DDL operations. Defining an appropriate buffer size limit avoids potential out of memory errors for online DDL operations that create or rebuild secondary indexes. The maximum buffer size per DDL thread is the maximum buffer size divided by the number of DDL threads (innodb_ddl_buffer_size/innodb_ddl_threads).

Prior to MySQL 8.0.27, innodb_sort_buffer_size variable defines the buffer size for online DDL operations that create or rebuild secondary indexes.

3. Configuring Parallel Threads for Online DDL Operations

The workflow of an online DDL operation that creates or rebuilds a secondary index involves:

• Scanning the clustered index and writing data to temporary sort files

• Sorting the data

• Loading sorted data from the temporary sort files into the secondary index

The number of parallel【ˈpærəlel 平行的;並行的;對應的;相應的;同時發生的;極相似的;】threads that can be used to scan clustered index is defined by the innodb_parallel_read_threads variable. The default setting is 4. The maximum setting is 256, which is the maximum number for all sessions. The actual number of threads that scan the clustered index is the number defined by the innodb_parallel_read_threads setting or the number of index subtrees to scan, whichever is smaller. If the thread limit is reached, sessions fall back to using a single thread.

The number of parallel threads that sort and load data is controlled by the innodb_ddl_threads variable, introduced in MySQL 8.0.27. The default setting is 4. Prior to MySQL 8.0.27, sort and load operations are single-threaded.

The following limitations apply:

• Parallel threads are not supported for building indexes that include virtual 【ˈvɜːrtʃuəl 虛擬的;】columns.

• Parallel threads are not supported for full-text index creation.

• Parallel threads are not supported for spatial 【ˈspeɪʃl 空間的;】index creation.

• Parallel scan is not supported on tables defined with virtual【ˈvɜːrtʃuəl 虛擬的;】columns.

• Parallel scan is not supported on tables defined with a full-text index.

• Parallel scan is not supported on tables defined with a spatial【ˈspeɪʃl 空間的;】index.

4. Simplifying DDL Statements with Online DDL

Before the introduction of online DDL, it was common practice to combine many DDL operations into a single ALTER TABLE statement. Because each ALTER TABLE statement involved【ɪnˈvɑːlvd 參與;卷入的;關註;有關聯;關係密切;複雜難解的;作為一部分;耗費很多時間;】 copying and rebuilding the table, it was more efficient to make several changes to the same table at once, since【因為,由於】those changes could all be done with a single rebuild operation for the table. The downside【ˈdaʊnsaɪd 負面,不利方面;底側;】 was that SQL code involving DDL operations was harder to maintain and to reuse in different scripts. If the specific changes were different each time, you might have to construct a new complex ALTER TABLE for each slightly different scenario【səˈnærioʊ 方案;設想;預測;腳本;(電影或戲劇的)劇情梗概;】.

For DDL operations that can be done online, you can separate them into individual ALTER TABLE statements for easier scripting and maintenance, without sacrificing efficiency. For example, you might take a complicated statement such as:

ALTER TABLE t1 ADD INDEX i1(c1), ADD UNIQUE INDEX i2(c2),
 CHANGE c4_old_name c4_new_name INTEGER UNSIGNED;

and break it down into simpler parts that can be tested and performed independently, such as:

ALTER TABLE t1 ADD INDEX i1(c1);
ALTER TABLE t1 ADD UNIQUE INDEX i2(c2);
ALTER TABLE t1 CHANGE c4_old_name c4_new_name INTEGER UNSIGNED NOT NULL;

You might still use multi-part ALTER TABLE statements for:

• Operations that must be performed in a specific sequence, such as creating an index followed by a foreign key constraint that uses that index.

• Operations all using the same specific LOCK clause, that you want to either succeed or fail as a group.

• Operations that cannot be performed online, that is, that still use the table-copy method.

• Operations for which you specify ALGORITHM=COPY or old_alter_table=1, to force the table-copying behavior if needed for precise backward-compatibility in specialized scenarios.

5.Online DDL Failure Conditions

The failure of an online DDL operation is typically due to【due to 由於;由於,因為;】 one of the following conditions:

• An ALGORITHM clause specifies an algorithm that is not compatible【kəmˈpætəbl相容的,可共存的;<生>親和的;協調一致的;(因志趣等相投而)關係好的,和睦相處的;合得來的,意氣相投的;可共用的;】with the particular type of DDL operation or storage engine.

• A LOCK clause specifies a low degree of locking (SHARED or NONE) that is not compatible with the particular type of DDL operation.

• A timeout occurs while waiting for an exclusive lock on the table, which may be needed briefly during the initial and final phases of the DDL operation.

• The tmpdir or innodb_tmpdir file system runs out of disk space, while MySQL writes temporary sort files on disk during index creation.

• The operation takes a long time and concurrent DML modifies the table so much that the size of the temporary online log exceeds the value of the innodb_online_alter_log_max_size configuration option. This condition causes a DB_ONLINE_LOG_TOO_BIG error.

• Concurrent DML makes changes to the table that are allowed with the original table definition, but not with the new one. The operation only fails at the very end, when MySQL tries to apply all the changes from concurrent DML statements. For example, you might insert duplicate values into a column while a unique index is being created, or you might insert NULL values into a column while creating a primary key index on that column. The changes made by the concurrent DML take precedence, and the ALTER TABLE operation is effectively rolled back.

6.Online DDL Limitations

The following limitations apply to online DDL operations:

• The table is copied when creating an index on a TEMPORARY TABLE.

• The ALTER TABLE clause LOCK=NONE is not permitted if there are ON...CASCADE or ON...SET NULL constraints on the table.

• Before an in-place online DDL operation can finish, it must wait for transactions that hold metadata locks on the table to commit or roll back. An online DDL operation may briefly【ˈbriːfli 簡要地;簡短地;短暫地;暫時地;】 require an exclusive metadata lock on the table during its execution phase, and always requires one in the final phase of the operation when updating the table definition. Consequently【ˈkɑːnsɪkwentli 因此;所以;】, transactions holding metadata locks on the table can cause an online DDL operation to block. The transactions that hold metadata locks on the table may have been started before or during the online DDL operation. A long running or inactive【ɪnˈæktɪv 不活躍的;無效的;不活動的;未使用的;無行動的;無作用的;不運轉的;】 transaction that holds a metadata lock on the table can cause an online DDL operation to timeout.

• When running an in-place online DDL operation, the thread that runs the ALTER TABLE statement applies an online log of DML operations that were run concurrently on the same table from other connection threads. When the DML operations are applied, it is possible to encounter a duplicate key entry error (ERROR 1062 (23000): Duplicate entry), even if the duplicate entry is only temporary and would be reverted by a later entry in the online log. This is similar to the idea of a foreign key constraint check in InnoDB in which constraints must hold during a transaction.

• OPTIMIZE TABLE for an InnoDB table is mapped to an ALTER TABLE operation to rebuild the table and update index statistics and free unused space in the clustered index. Secondary indexes are not created as efficiently because keys are inserted in the order they appeared in the primary key. OPTIMIZE TABLE is supported with the addition of online DDL support for rebuilding regular and partitioned InnoDB tables.

• Tables created before MySQL 5.6 that include temporal columns (DATE, DATETIME or TIMESTAMP) and have not been rebuilt using ALGORITHM=COPY do not support ALGORITHM=INPLACE. In this case, an ALTER TABLE ... ALGORITHM=INPLACE operation returns the following error:

ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported.
Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.

• The following limitations are generally applicable to online DDL operations on large tables that involve rebuilding the table:

  • There is no mechanism to pause an online DDL operation or to throttle I/O or CPU usage for an online DDL operation.
  •  Rollback of an online DDL operation can be expensive should the operation fail.
  •  Long running online DDL operations can cause replication lag. An online DDL operation must finish running on the source before it is run on the replica. Also, DML that was processed concurrently on the source is only processed on the replica after the DDL operation on the replica is completed.

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • @目錄前言簡介一、準備工作1.1 創建寫入腳本1.2 設置執行許可權1.3 添加定時任務1.4 配置生效二、Tomcat日誌 按每天分割2.1 創建一個 sh文件2.2 設置執行許可權2.3 設置crontab指令,指定每日定時任務2.4 配置生效總結 前言 請各大網友尊重本人原創知識分享,謹記本人博客 ...
  • ESP-IDF NVS 目錄ESP-IDF NVS1. 什麼是NVS?2. NVS中的概念2.1. partition 分區2.2. namespace 命名空間2.3. key-value 鍵值對3. ESP-IDF中NVS的代碼實現 1. 什麼是NVS? 非易失性存儲 (NVS) 庫主要用於在 ...
  • Ubuntu 22.04 自帶ufw 無需下載 ufw是Uncomplicated Firewall的縮寫,是一個用戶友好的命令行工具,用於管理Ubuntu系統上的防火牆。通過ufw命令,用戶可以輕鬆地配置防火牆規則、查看當前的防火牆狀態、啟用或禁用防火牆等操作,幫助用戶保護系統安全並控制網路流量。 ...
  • 一:when語句 1:基礎瞭解 說到底,還是有多個表達式來組成一個判斷語句,很多種的判斷語句 1、 為什麼需要判斷語句: 有的時候play的結果需要依賴於變數,fact或者是前一個任務的執行結果,或者基於上一個task執行返回的結果而決定如何執行後續的task,這個時候就需要條件的判斷了,一個很簡單 ...
  • 使用opc-ua-sim模擬server 前言 一直想找一種將模擬server放到docker容器中運行的方式,這樣就不需要在每個電腦上都安裝軟體,僅僅只需要將鏡像保存起來,使用時載入就行。於是乎就跑到了HUB里搜尋,你說巧不巧,就剛好找到了. iotechsys 在HUB里找到這個作者(iotec ...
  • 本文分享自華為雲社區《openGauss 5.0 單點企業版部署_Centos7_x86》,本文作者:董小姐 本文檔環境:CentOS7.9 x86_64 4G1C40G python2.7.5 互動式初始化環境方式 1、介紹 openGauss是一款開源關係型資料庫管理系統,採用木蘭寬鬆許可證v2 ...
  • 引言 在當前的IT行業,無論是校園招聘還是社會招聘,MySQL的重要性不言而喻。 面試過程中,MySQL相關的問題經常出現,這不僅因為它是最流行的關係型資料庫之一,而且在日常的軟體開發中,MySQL的應用廣泛,尤其是對於Java後端開發者來說,熟練掌握MySQL已成為他們技術能力評估的重要指標。 因 ...
  • 不同於Oracle:SEQUENCE的區別 前言 在使用Oracle資料庫SEQUENCE功能時,發現Oracle對邊界處理比較奇怪。剛好GreatSQL也支持SEQUENCE,就拿來一起比較一下。 先說結論:GreatSQL 的使用基本和Oracle基本一致,但是對 START WITH 的邊界限 ...
一周排行
    -Advertisement-
    Play Games
  • 一:背景 1. 講故事 這一期程式故障除了做原理分析,還順帶吐槽一下,熟悉我的朋友都知道我分析dump是免費的,但免費不代表可以濫用我的寶貴時間,我不知道有些人故意惡搞卡死是想幹嘛,不得而知,希望後面類似的事情越來越少吧!廢話不多說,我們來看看是如何被惡搞的。 二:WinDbg 分析 1. 程式是如 ...
  • TCP(Transmission Control Protocol): 特點:面向連接、可靠傳輸、按序交付、流量控制、擁塞控制。 用途:適用於需要高可靠性的數據傳輸,如網頁瀏覽、電子郵件、文件傳輸等。 優勢:數據包順序和完整性有保障,適合需要準確無誤傳輸數據的場景。 舉例:線上購物網站的交易數據傳輸 ...
  • 前面兩篇隨筆介紹了EAV模型(實體-屬性-值)的設計思路和Winform前端對於通用查詢的處理,本篇隨筆繼續深入EAV模型(實體-屬性-值)設計的探討,介紹實體屬性的定義,以及根據不同屬性的定義構建不同的輸入控制項處理,以及列表界面的展示。旨在結合關係型資料庫的熟練使用、性能優勢和MongoDB資料庫... ...
  • IEC60870-5-104 是一種電力自動化系統中常用的通信協議,使用 TCP/IP 協議作為底層通信協議,用於監視和控制電力系統中的各種設備,如變電站、發電機、開關等。 ...
  • 前言:最近幾天有好幾個小伙伴玩WPF,遇到不同頁面,不知道要怎麼傳遞消息。於是,我今天就來演示一個事件聚合器的玩法,採用prism框架來實現。作為福利,內容附帶了主頁面打開對話框時候直接通過參數傳遞消息的一個小例子,具體請自行圍觀。 以下內容,創建wpf項目以及引用prism和實現依賴註入等細節,可 ...
  • 在這篇文章中,我們介紹瞭如何利用大型語言模型為情人節營造難忘的氛圍。通過上傳圖片併進行風格轉化,我們可以為對方呈現一幅獨特的作品,增添浪漫的色彩。同時,藉助搜索功能,我們能夠輕鬆獲取與情人節相關的信息,為策劃活動提供更多靈感和建議。 ...
  • 正文 晚上跳舞回來,在便利店照例買根冰淇淋吃。看到店裡的老闆娘在訓她孩子。言辭依稀可以聽見考上好初中之類。 當時一個臨時起意,打算買兩根冰淇淋,塞一根到他手上,說一句:“我小時候也老被罵,沒什麼。” 然後跑掉。但是在冰櫃里翻了半天,都沒找到自己想吃的那種。與此同時,聽到他媽媽聲色俱厲地說:“你知道我小時 ...
  • strcpy和memcpy 目錄strcpy和memcpy 複製內容: strcpy:專門用於複製字元串,它會一直複製直到遇到源字元串中的'\0'結束符。這意味著如果源字元串長度超過了目標緩衝區的大小(不包括'\0'),就會發生緩衝區溢出,這是一個常見的安全隱患。 memcpy:可以複製任意內容,如 ...
  • 本文介紹在Visual Studio中,通過屬性表,使得一個新建解決方案中的項目可以快速配置已有解決方案的項目中各類已編譯好的C++第三方庫的方法~ ...
  • 將多個第三方包封裝成一個項目後,如果你的目的是讓其他開發人員可以直接引用這些依賴,一般來說有兩種常見的方式: 打成JAR包:將封裝好的項目編譯打包成JAR文件,其他開發人員可以將這個JAR文件添加到他們的項目中,併在項目的構建工具(比如Maven)中配置該JAR作為依賴。這樣做的好處是簡單直接,其他 ...