MySQL 大欄位問題
開發規範中,一般不讓使用大欄位,大部分關於給出的原因有影響快取,高併發查詢的情況會打滿頻寬,溢位儲存,查詢的時候多了一次指標查詢,在姜老師的書中還看到了一個原因,就是大欄位的dml 會使用悲觀的方式處理,這種對二叉樹加x-latch,會導致併發效能的下降。
姜老師的書中描述是大欄位的插入,更新,刪除會使用悲觀操作,但是我測試的情況是針對insert沒有使用悲觀操作,update是使用了悲觀操作
update的堆疊如下
btr_cur_pessimistic_update(unsigned long flags, btr_cur_t * cursor, big_rec_t ** big_rec, upd_t * update, unsigned long cmpl_info, que_thr_t * thr, mtr_t * mtr) (/root/mysql-5.0.15/innobase/btr/btr0cur.c:1766) row_upd_clust_rec(upd_node_t * node, dict_index_t * index, que_thr_t * thr, mtr_t * mtr) (/root/mysql-5.0.15/innobase/row/row0upd.c:1530) row_upd_clust_step(upd_node_t * node, que_thr_t * thr) (/root/mysql-5.0.15/innobase/row/row0upd.c:1742) row_upd(que_thr_t * thr, upd_node_t * node) (/root/mysql-5.0.15/innobase/row/row0upd.c:1819) row_upd_step(que_thr_t * thr) (/root/mysql-5.0.15/innobase/row/row0upd.c:1948) row_update_for_mysql(unsigned char * mysql_rec, row_prebuilt_t * prebuilt) (/root/mysql-5.0.15/innobase/row/row0mysql.c:1386) ha_innobase::update_row(ha_innobase * const this, const mysql_byte * old_row, mysql_byte * new_row) (/root/mysql-5.0.15/sql/ha_innodb.cc:3622) mysql_update(THD * thd, TABLE_LIST * table_list, List<Item> & fields, List<Item> & values, COND * conds, uint order_num, ORDER * order, ha_rows limit, enum_duplicates handle_duplicates, bool ignore) (/root/mysql-5.0.15/sql/sql_update.cc:429) mysql_execute_command(THD * thd) (/root/mysql-5.0.15/sql/sql_parse.cc:3192) mysql_parse(THD * thd, char * inBuf, uint length) (/root/mysql-5.0.15/sql/sql_parse.cc:5536) dispatch_command(enum_server_command command, THD * thd, char * packet, unsigned int packet_length) (/root/mysql-5.0.15/sql/sql_parse.cc:1697) do_command(THD * thd) (/root/mysql-5.0.15/sql/sql_parse.cc:1498) handle_one_connection(void * arg) (/root/mysql-5.0.15/sql/sql_parse.cc:1143) libpthread.so.0!start_thread (Unknown Source:0) libc.so.6!clone (Unknown Source:0)
在更新的時候,先加的s index->lock,然後加了x鎖
堆疊如下
mysqld!btr_cur_search_to_nth_level(dict_index_t*, unsigned long, dtuple_t const*, page_cur_mode_t, unsigned long, btr_cur_t*, unsigned long, char const*, unsigned long, mtr_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/btr/btr0cur.cc:996) mysqld!btr_pcur_open_with_no_init_func(dict_index_t*, dtuple_t const*, page_cur_mode_t, unsigned long, btr_pcur_t*, unsigned long, char const*, unsigned long, mtr_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/include/btr0pcur.ic:528) mysqld!btr_pcur_restore_position_func(unsigned long, btr_pcur_t*, char const*, unsigned long, mtr_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/btr/btr0pcur.cc:365) mysqld!row_upd_clust_rec(unsigned long, upd_node_t*, dict_index_t*, unsigned long*, mem_block_info_t**, que_thr_t*, mtr_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/row/row0upd.cc:2694) mysqld!row_upd_clust_step(upd_node_t*, que_thr_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/row/row0upd.cc:2957) mysqld!row_upd(upd_node_t*, que_thr_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/row/row0upd.cc:3054) mysqld!row_upd_step(que_thr_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/row/row0upd.cc:3200) mysqld!row_update_for_mysql_using_upd_graph(unsigned char const*, row_prebuilt_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/row/row0mysql.cc:2582) mysqld!row_update_for_mysql(unsigned char const*, row_prebuilt_t*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/row/row0mysql.cc:2672) mysqld!ha_innobase::update_row(unsigned char const*, unsigned char*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/innobase/handler/ha_innodb.cc:8257) mysqld!handler::ha_update_row(unsigned char const*, unsigned char*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/handler.cc:8134) mysqld!mysql_update(THD*, List<Item>&, List<Item>&, unsigned long long, enum_duplicates, unsigned long long*, unsigned long long*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/sql_update.cc:894) mysqld!Sql_cmd_update::try_single_table_update(THD*, bool*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/sql_update.cc:2906) mysqld!Sql_cmd_update::execute(THD*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/sql_update.cc:3037) mysqld!mysql_execute_command(THD*, bool) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/sql_parse.cc:3616) mysqld!mysql_parse(THD*, Parser_state*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/sql_parse.cc:5584) mysqld!dispatch_command(THD*, COM_DATA const*, enum_server_command) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/sql_parse.cc:1491) mysqld!do_command(THD*) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/sql_parse.cc:1032) mysqld!::handle_connection(void *) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/sql/conn_handler/connection_handler_per_thread.cc:313) mysqld!::pfs_spawn_thread(void *) (/Users/xiaoyu.bai/Downloads/mysql-5.7.29/storage/perfschema/pfs.cc:2197)
在btr_cur_search_to_nth_level函式中,執行下面的case分支,加x
switch (latch_mode) { case BTR_MODIFY_TREE: /* Most of delete-intended operations are purging. Free blocks and read IO bandwidth should be prior for them, when the history list is glowing huge. */ if (lock_intention == BTR_INTENTION_DELETE && trx_sys->rseg_history_len > BTR_CUR_FINE_HISTORY_LENGTH && buf_get_n_pending_read_ios()) { mtr_x_lock(dict_index_get_lock(index), mtr);
blob,text 更新都會執行mtr_x_lock(dict_index_get_lock(index), mtr);
即使是更新表中的其他欄位,比如varchar 欄位也會加x鎖,不包含text,blob型別的表更新是不會有的。
所以在規範說明中,可以併發影響這一條。
有興趣學習原始碼的加群一起學習啊 QQ: 700072075
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25719946/viewspace-2898118/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20231020]增加欄位的問題.txt
- MySql 查詢某一天日期格式欄位走索引問題MySql索引
- MySQL 欄位約束MySql
- 解決mybatis用Map返回的欄位全變大寫的問題MyBatis
- MySQL 欄位擷取拼接MySql
- MySQL-刪除欄位MySql
- 記錄一次因 mysql 欄位取名不規範導致的問題MySql
- MySQL8.0大表秒加欄位,是真的嗎?MySql
- Mysql多欄位大表的幾種優化方法MySql優化
- [20210208]lob欄位與查詢的問題.txt
- mysql表操作(alter)/mysql欄位型別MySql型別
- MySQL欄位新增註釋,但不改變欄位的型別MySql型別
- MySQL-建立計算欄位MySql
- MySQL欄位型別最全解析MySql型別
- MySQL欄位的取值範圍MySql
- resultMap 和 resultType 的欄位對映覆蓋問題
- api 介面欄位規範的問題,請教大家API
- 巧用 Base62 解決欄位太短的問題
- [20201109]11.2.0.4增加欄位與預設值問題.txt
- MySQL 5.7使用pt-online-schema-change對大表加欄位MySql
- 通用首部欄位詳解-四大首部欄位之一
- MySQL 中 JSON 欄位的使用技巧MySqlJSON
- MySQL中JSON欄位的使用技巧MySqlJSON
- ORACLE LOB大欄位維護Oracle
- 請求首部欄位詳解-四大首部欄位之一
- MyBatis 解決欄位名不一致的問題MyBatis
- mysql資料庫新增和修改欄位MySql資料庫
- mysql5.6生成排序欄位MySql排序
- MySQL 更新同一個表不同欄位MySql
- 5_MySQL 表的欄位約束MySql
- 要慎用mysql的enum欄位的原因MySql
- MySQL-去掉不為null的欄位MySqlNull
- mysql-資料庫欄位date datetimeMySql資料庫
- MySQL5.7密碼欄位變更MySql密碼
- mysql修改表欄位學習筆記MySql筆記
- mysql sql同一個欄位多個行轉成一個欄位查詢MySql
- 圖解MySQL:count(*) 、count(1) 、count(主鍵欄位)、count(欄位)哪個效能最好?圖解MySql
- pydantic 欄位欄位校驗