本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/database/setting_innodb_table_initial_size.html InnoDB在写密集的压力时,由于B-Tree扩展,因而也会带来数据文件的
本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/database/setting_innodb_table_initial_size.html
InnoDB在写密集的压力时,由于B-Tree扩展,因而也会带来数据文件的扩展,然而,InnoDB数据文件扩展需要使用mutex保护数据文件,这就会导致波动。 丁奇的博客说明了这个问题:http://dinglin.iteye.com/blog/1317874
When InnoDB under heavy write workload, datafiles will extend quickly, because of B-Tree allocate new pages. But InnoDB need to use mutex to protect datafile, so it will cause performance jitter. Xiaobin Lin said this in his blog: http://dinglin.iteye.com/blog/1317874
解决的方法也很简单,只要知道数据文件可能会增长到多大,预先扩展即可。阅读代码可以知道,InnoDB建表后自动初始化大小是FIL_IBD_FILE_INITIAL_SIZE这个常量控制的,而初始化数据文件是由fil_create_new_single_table_tablespace()函数控制的。所以要改变数据文件初始化大小,只要修改fil_create_new_single_table_tablespace的传入值即可,默认是FIL_IBD_FILE_INITIAL_SIZE。
How to solve it? That’s easy. If we know the datafile will extend to which size at most, we can pre-extend it. After reading source code, we can know InnoDB initial datafile size by FIL_IBD_FILE_INITIAL_SIZE, and fil_create_new_single_table_tablespace() function to do it. So if we want to change datafile initial size, we only need to change the initial size parameter in fil_create_new_single_table_tablespace(), the default value is FIL_IBD_FILE_INITIAL_SIZE.
因此,我在建表语法中加上了datafile_initial_size这个参数,例如:
CREATE TABLE test (
…
) ENGINE = InnoDB DATAFILE_INITIAL_SIZE=100000;
如果设定的值比FIL_IBD_FILE_INITIAL_SIZE还小,就依然传入FIL_IBD_FILE_INITIAL_SIZE给fil_create_new_single_table_tablespace,否则传入datafile_initial_size进行初始化。
So, I add a new parameter for CREATE TABLE, named ‘datafile_initial_size’. For example:
CREATE TABLE test (
…
) ENGINE = InnoDB DATAFILE_INITIAL_SIZE=100000;
If DATAFILE_INITIAL_SIZE value less than FIL_IBD_FILE_INITIAL_SIZE, I will still pass FIL_IBD_FILE_INITIAL_SIZE to fil_create_new_single_table_tablespace(), otherwise, I pass DATAFILE_INITIAL_SIZE value to fil_create_new_single_table_tablespace() function for initialization.
因此,这个简单安全的patch就有了,可以看 http://bugs.mysql.com/bug.php?id=67792 关注官方的进展:
So, I wrote this simple patch, see http://bugs.mysql.com/bug.php?id=67792:
Index: storage/innobase/dict/dict0crea.c =================================================================== --- storage/innobase/dict/dict0crea.c (revision 3063) +++ storage/innobase/dict/dict0crea.c (working copy) @@ -294,7 +294,8 @@ error = fil_create_new_single_table_tablespace( space, path_or_name, is_path, flags == DICT_TF_COMPACT ? 0 : flags, - FIL_IBD_FILE_INITIAL_SIZE); + table->datafile_initial_size datafile_initial_size); table->space = (unsigned int) space; ? if (error != DB_SUCCESS) { Index: storage/innobase/handler/ha_innodb.cc =================================================================== --- storage/innobase/handler/ha_innodb.cc (revision 3063) +++ storage/innobase/handler/ha_innodb.cc (working copy) @@ -7155,6 +7155,7 @@ col_len); } ? + table->datafile_initial_size= form->datafile_initial_size; error = row_create_table_for_mysql(table, trx); ? if (error == DB_DUPLICATE_KEY) { @@ -7760,6 +7761,7 @@ ? row_mysql_lock_data_dictionary(trx); ? + form->datafile_initial_size= create_info->datafile_initial_size; error = create_table_def(trx, form, norm_name, create_info->options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL, flags); Index: storage/innobase/include/dict0mem.h =================================================================== --- storage/innobase/include/dict0mem.h (revision 3063) +++ storage/innobase/include/dict0mem.h (working copy) @@ -678,6 +678,7 @@ /** Value of dict_table_struct::magic_n */ # define DICT_TABLE_MAGIC_N 76333786 #endif /* UNIV_DEBUG */ + uint datafile_initial_size; /* the initial size of the datafile */ }; ? #ifndef UNIV_NONINL Index: support-files/mysql.5.5.18.spec =================================================================== --- support-files/mysql.5.5.18.spec (revision 3063) +++ support-files/mysql.5.5.18.spec (working copy) @@ -244,7 +244,7 @@ Version: 5.5.18 Release: %{release}%{?distro_releasetag:.%{distro_releasetag}} Distribution: %{distro_description} -License: Copyright (c) 2000, 2011, %{mysql_vendor}. All rights reserved. Under %{license_type} license as shown in the Description field. +License: Copyright (c) 2000, 2012, %{mysql_vendor}. All rights reserved. Under %{license_type} license as shown in the Description field. Source: http://www.mysql.com/Downloads/MySQL-5.5/%{src_dir}.tar.gz URL: http://www.mysql.com/ Packager: MySQL Release Engineering Index: sql/table.h =================================================================== --- sql/table.h (revision 3063) +++ sql/table.h (working copy) @@ -596,6 +596,7 @@ */ key_map keys_in_use; key_map keys_for_keyread; + uint datafile_initial_size; /* the initial size of the datafile */ ha_rows min_rows, max_rows; /* create information */ ulong avg_row_length; /* create information */ ulong version, mysql_version; @@ -1094,6 +1095,8 @@ #endif MDL_ticket *mdl_ticket; ? + uint datafile_initial_size; + void init(THD *thd, TABLE_LIST *tl); bool fill_item_list(List *item_list) const; void reset_item_list(List *item_list) const; Index: sql/sql_yacc.yy =================================================================== --- sql/sql_yacc.yy (revision 3063) +++ sql/sql_yacc.yy (working copy) @@ -906,6 +906,7 @@ %token DATABASE %token DATABASES %token DATAFILE_SYM +%token DATAFILE_INITIAL_SIZE_SYM %token DATA_SYM /* SQL-2003-N */ %token DATETIME %token DATE_ADD_INTERVAL /* MYSQL-FUNC */ @@ -5046,6 +5047,18 @@ Lex->create_info.db_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE; } + | DATAFILE_INITIAL_SIZE_SYM opt_equal ulonglong_num + { + if ($3 > UINT_MAX32) + { + Lex->create_info.datafile_initial_size= UINT_MAX32; + } + else + { + Lex->create_info.datafile_initial_size= $3; + } + Lex->create_info.used_fields|= HA_CREATE_USED_DATAFILE_INITIAL_SIZE; + } | MAX_ROWS opt_equal ulonglong_num { Lex->create_info.max_rows= $3; @@ -12585,6 +12598,7 @@ | CURSOR_NAME_SYM {} | DATA_SYM {} | DATAFILE_SYM {} + | DATAFILE_INITIAL_SIZE_SYM{} | DATETIME {} | DATE_SYM {} | DAY_SYM {} Index: sql/handler.h =================================================================== --- sql/handler.h (revision 3063) +++ sql/handler.h (working copy) @@ -387,6 +387,8 @@ #define HA_CREATE_USED_TRANSACTIONAL (1L <img src="/static/imghwm/default1.png" data-src="http://www1.feedsky.com/t1/727603630/plinux/feedsky/s.gif?r=http://www.penglixun.com/tech/database/setting_innodb_table_initial_size.html" class="lazy" border="0" style="max-width:90%" style="position:absolute" style="max-width:90%" alt="InnoDB建表时设定初始大小 (Setting InnoDB table datafile ini" > 本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: ht […...<img src="/static/imghwm/default1.png" data-src="http://www1.feedsky.com/t1/727603630/plinux/feedsky/s.gif?r=http://www.penglixun.com/tech/database/setting_innodb_table_initial_size.html" class="lazy" border="0" style="max-width:90%" style="position:absolute" style="max-width:90%" alt="InnoDB建表时设定初始大小 (Setting InnoDB table datafile ini" >

InnoDBBufferPool通过缓存数据和索引页来减少磁盘I/O,提升数据库性能。其工作原理包括:1.数据读取:从BufferPool中读取数据;2.数据写入:修改数据后写入BufferPool并定期刷新到磁盘;3.缓存管理:使用LRU算法管理缓存页;4.预读机制:提前加载相邻数据页。通过调整BufferPool大小和使用多个实例,可以优化数据库性能。

MySQL与其他编程语言相比,主要用于存储和管理数据,而其他语言如Python、Java、C 则用于逻辑处理和应用开发。 MySQL以其高性能、可扩展性和跨平台支持着称,适合数据管理需求,而其他语言在各自领域如数据分析、企业应用和系统编程中各有优势。

MySQL值得学习,因为它是强大的开源数据库管理系统,适用于数据存储、管理和分析。1)MySQL是关系型数据库,使用SQL操作数据,适合结构化数据管理。2)SQL语言是与MySQL交互的关键,支持CRUD操作。3)MySQL的工作原理包括客户端/服务器架构、存储引擎和查询优化器。4)基本用法包括创建数据库和表,高级用法涉及使用JOIN连接表。5)常见错误包括语法错误和权限问题,调试技巧包括检查语法和使用EXPLAIN命令。6)性能优化涉及使用索引、优化SQL语句和定期维护数据库。

MySQL适合初学者学习数据库技能。1.安装MySQL服务器和客户端工具。2.理解基本SQL查询,如SELECT。3.掌握数据操作:创建表、插入、更新、删除数据。4.学习高级技巧:子查询和窗口函数。5.调试和优化:检查语法、使用索引、避免SELECT*,并使用LIMIT。

MySQL通过表结构和SQL查询高效管理结构化数据,并通过外键实现表间关系。1.创建表时定义数据格式和类型。2.使用外键建立表间关系。3.通过索引和查询优化提高性能。4.定期备份和监控数据库确保数据安全和性能优化。

MySQL是一个开源的关系型数据库管理系统,广泛应用于Web开发。它的关键特性包括:1.支持多种存储引擎,如InnoDB和MyISAM,适用于不同场景;2.提供主从复制功能,利于负载均衡和数据备份;3.通过查询优化和索引使用提高查询效率。

SQL用于与MySQL数据库交互,实现数据的增、删、改、查及数据库设计。1)SQL通过SELECT、INSERT、UPDATE、DELETE语句进行数据操作;2)使用CREATE、ALTER、DROP语句进行数据库设计和管理;3)复杂查询和数据分析通过SQL实现,提升业务决策效率。

MySQL的基本操作包括创建数据库、表格,及使用SQL进行数据的CRUD操作。1.创建数据库:CREATEDATABASEmy_first_db;2.创建表格:CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY,titleVARCHAR(100)NOTNULL,authorVARCHAR(100)NOTNULL,published_yearINT);3.插入数据:INSERTINTObooks(title,author,published_year)VA


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver CS6
视觉化网页开发工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

禅工作室 13.0.1
功能强大的PHP集成开发环境