4. Storage Engine: MyISAM
Table lock
No automated data recovery
No transactions
Only indexes are cached in memory
Compact storage
Friday, December 30, 11
5. Storage Engine: InnoDB
Transactional
Foreign keys
Multiversioning
Clustered by primary key
No cached count(*)
Blocking AUTO_INCREMENT
Optimized cache
Friday, December 30, 11
6. InnoDB Storage Architecture
Tablespaces Segment
leaf node segment
extent extent
non-leaf node segment
extent extent
rollback node segment
...
Extent
Row
Page
trx id
row row
row id
row row
roll pointer
...
col 1 ... col n 64 pages
Friday, December 30, 11
7. InnoDB and File system
File
system
-‐>
InnoDB
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
disk
partition
-‐>
tablespace
file
-‐>
segment
inode
-‐>
fsp0fsp.c
'inode'
fs
space
allocation
unit
-‐>
extent
disk
block
-‐>
page
(16
kB)
Friday, December 30, 11
15. B+tree indexes: Demo
CREATE TABLE People (
last_name varchar(50) not null,
first_name varchar(50) not null,
dob date not null,
gender enum('m', 'f') not null,
key(last_name, first_name, dob)
);
Friday, December 30, 11
17. B+Tree: Types of queries
Match the full value
where last_name=? and first_name=? and bod=?
Match a leftmost prefix
where last_name=?
where last_name=?
Friday, December 30, 11
18. B+Tree: Types of queries
Match a column prefix
where last_name like ”Liang%”
Match a range of values
where last_name > ?
Friday, December 30, 11
19. B+Tree: Types of queries
Match one part exactly and match a range
on another
where last_name=? and first_name>?
Index only queries
select first_name where last_name=?
Friday, December 30, 11
20. B+Tree: Limitations
Doesn’t start from leftmost
where first_name=?
Skip columns in the index
where last_name=? and bod=?
Friday, December 30, 11
21. B+Tree: Limitations
More than one range conditions
where last_name>? and first_name>?
Can’t optimize to the right of the first range
conditon
where last_name>? and first_name=?
Friday, December 30, 11
26. Useful commands
show index from TABLE;
explain [extended] SELECT * FROM TABLE;
UPDATE, DELETE convert to SELECT
Friday, December 30, 11
27. Explain
select_tpe
simple, primary, subquery, derived, union
type
all < index < range < ref < eq_ref < const,
system < null
Friday, December 30, 11
28. Explain
Extra
using where
using index
using filesort
using temporary
Friday, December 30, 11