分类: Mysql/postgreSQL
2010-01-19 11:37:30
1) 使用MyISAM引擎时,MySQL使用的是fast table locking,支持多读者单写者。但这种方式对于 在一个table上持续同时有update和 slow select操作的情况,效率低下。
2)对于 not strict SQL mode,或者使用IGNORE修饰的INSERT or UPDATE,MySQL处理notransactional tables时,会按如下规则进行:
EXPLAIN [EXTENDED | PARTITIONS] SELECT select_options
内部锁,interal locking, 是MySQL server自己使用,用于管理多线程(或会话 session)竞争。外部锁,exteranl locking,是MySQL server和其他外部程序用于协同管理表文件的访问的。
下面的场景应当使用table locks:
2)Statements for the table are a mix of reads and writes, where writes are updates or deletes for a single row that can be fetched with one key read:
3)SELECT combined with concurrent INSERT statement, and very few UPDATE or DELETE statements
4)Many scans or GROUP BY operations on the entire table without any writers
For large tables, table locking is often better than row locking, but there are some disadvantages:
1)Table locking enables many sessions to read from a table at the same time, but if a session wants to write to a table, it must firstget exclusive access. During the update, all other sessions that want to access this particular table must wait until the update isdone.
2)Table locking causes problems in cases such as when a session is waiting because the disk is full and free space needs to becomeavailable before the session can proceed. In this case, all sessions that want to access the problem table are also put in a waiting state until more disk space is made available.
The MyISAM storage engine supports concurrent inserts to reduce contention between readers and writers for a given table: If a MyISAM table has no holes in the data file (deleted rows in the middle), an INSERT statement can be executed to add rows to the end of the table at the same time that SELECT statements are reading rows from the table. If there are multiple INSERT statements, they are queued and performed in sequence, concurrently with the SELECT statements.