Mysql执行INSERT操作是直接写硬盘吗?

panjj1 2008-12-02 10:23:39
请教各位,如果只是单独执行一条INSERT操作,mysql会不会自动将数据缓存,等到一定大小或条数后再执行写硬盘操作,以减少磁盘I/O次数?
我理解设置“bulk_insert_buffer_size”只是再INSERT 语句附带有多个 VALUES 值时效率较高,对INSERT 语句仅附带有一个 VALUES 值并不能减少磁盘读写次数,不知道理解的对不对?
...全文
438 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
w2jc 2008-12-10
  • 打赏
  • 举报
回复
回13楼,不太确定是否完全一样,但可以肯定的是一定用了缓冲,然后批量I/O。
这种具体的细节你要去查MYSQL的文档了。
panjj1 2008-12-10
  • 打赏
  • 举报
回复
谢谢w2jc!只是不知道Mysql的INSERT处理机制和SQL Server是否相同?
panjj1 2008-12-09
  • 打赏
  • 举报
回复
没有人知道吗?
w2jc 2008-12-09
  • 打赏
  • 举报
回复
SQL Server的I/O机制非常复杂,要考虑到性能,数据完整性,锁等各方面。
一个基本特征就是,SQL首先将提交的修改写到缓冲中,并标记为“dirty”,
等有足够的diry page之后,再一次性写入硬盘。
而且,比较有趣的是,SQL 每次写回硬盘的数据量不固定,不是大家通常认为的8K或者32K,
原则是越多越好,这样的I/O才有效率。

下面是非常详细的 INSERT 操作的I/O过程:
BEGIN TRANSACTION
A BeginTran log record is written to the log cache area but there is no need to flush to stable media because SQL Server has not made any physical changes.

INSERT INTO tblTest
1 Page 150 is not currently present in the SQL Server data cache so data it is retrieved into the data cache.

2. Appropriate locks are obtained and the page is latched.

3. An Insert log record is built and added to the log cache.

4. A new row is added to the data page and the page is marked dirty.

5. The latch is released.

6. The log records associated with the transaction do not need to be flushed at this point because all changes remain in volatile storage.

Lazy writer or checkpoint locates page 150 in the buffer pool
Page 150 is currently marked as dirty so both of the processes are aware that the database page should be flushed to stable storage.

1. Latch page 150 to prevent further modifications.

2. Issue a request to log manager to flush all log records up to and including the LSN value stored on page 150. (Log is hardened.)

3. Wait for all log records to be flushed successfully to stable media.

Issue I/O request to flush page 150 to stable media.

下面这篇文章非常详细地介绍了SQL Server I/O:(不知道是否有中文翻译的,不过绝对是微软正版的,呵呵)
SQL Server 2000 I/O Basics
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlIObasics.mspx
panjj1 2008-12-05
  • 打赏
  • 举报
回复
缓存大小是不是bulk_insert_buffer_size控制的?
panjj1 2008-12-05
  • 打赏
  • 举报
回复
谢谢butchroller,那请问log的大小可以设置吗?
butchroller 2008-12-04
  • 打赏
  • 举报
回复
楼主不知道checkpoint的概念吗?oracle/mssql/mysql在写数据到磁盘之前都要经过缓存的。
commit操作只会写log,oracle的新版本甚至连log都可以缓存。
panjj1 2008-12-04
  • 打赏
  • 举报
回复
没有人知道吗?
flairsky 2008-12-02
  • 打赏
  • 举报
回复
我只知道mysql有写入缓存

以前观察过,感觉是空闲时写入磁盘。纯感觉而已
dawugui 2008-12-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 panjj1 的帖子:]
请教各位,如果只是单独执行一条INSERT操作,mysql会不会自动将数据缓存,等到一定大小或条数后再执行写硬盘操作,以减少磁盘I/O次数?
我理解设置“bulk_insert_buffer_size”只是再INSERT 语句附带有多个 VALUES 值时效率较高,对INSERT 语句仅附带有一个 VALUES 值并不能减少磁盘读写次数,不知道理解的对不对?
[/Quote]
sql server 直接写硬盘.
oracle,先放到缓存中,commit后直接写硬盘.
mysql,不知道原理,帮顶.
水族杰纶 2008-12-02
  • 打赏
  • 举报
回复
MSSQL 參考
http://msdn.microsoft.com/zh-cn/library/ms345368.aspx
MYSQL
建議到對應版問問~~
hyde100 2008-12-02
  • 打赏
  • 举报
回复
Mysql?
zhao_tk 2008-12-02
  • 打赏
  • 举报
回复
路过,学习
panjj1 2008-12-02
  • 打赏
  • 举报
回复
谢谢各位,继续等o(∩_∩)o...

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧