Home  >  Article  >  Database  >  mysql手写

mysql手写

WBOY
WBOYOriginal
2016-06-07 16:25:381433browse

mysql手记 myisam innoDB是mysql常用的存储引擎 MyISAM不支持事务、也不支持外键,但其访问速度快,对事务完整性没有要求。 InnoDB存储引擎提供了具有提交、回滚和崩溃恢复能力的事务安全。但是比起MyISAM存储引擎,InnoDB写的处理效率差一些并且会占用更多的

mysql手记

myisam innoDB是mysql常用的存储引擎

MyISAM不支持事务、也不支持外键,但其访问速度快,对事务完整性没有要求。 

InnoDB存储引擎提供了具有提交、回滚和崩溃恢复能力的事务安全。但是比起MyISAM存储引擎,InnoDB写的处理效率差一些并且会占用更多的磁盘空间以保留数据和索引。 

innodb的索引有两种,叫第一索引,以及第二索引。有的也叫聚集索引与辅助索引。其中聚集索引存放了表中的记录,查询的时候不需要回表扫描,同时索引项较大;辅助索引存放的位置信息,需要回表扫描,相对来说,I/0 次数会增加。

查询的时候最好能够从索引中取得数据,减少回表,相对来说离散的 I/0,

MYISAM 没有聚集索引。存放的记录的物理位置

OLTP (联机事务处理)故名思议主要强调事务,如(银行存款的修改,用户订单等)面向应用

OLAP (联机分析处理) 主要作为数据仓库,面向决策,分析等。

联接算法:

nested-loops join 主要思想是:从外表中拿出一个数据与内表的每一条数据比较,O(M*N) 。当有索引时:内表只需要比较索引的高度,近似于O(M*H)

Block nested--loops join 主要思想 是:改进 nested-loops join 外部表每次去一定的数据到缓冲区,比如10条,然后这10条记录在跟内部表的数据比较,减少内部表的扫描次数。

Hash join 只能== 以及!=,不能部分比较(为何?,hash是对整个字符串hash) 主要思想是:将外部表的数据放到join buffer,然后hash,这一阶段

为build;probe阶段,从内表中取出数据hash,比较。

基本的测试:

create TABLE myorder
( id int not null auto_increment,
   userid int not null ,
  orderdate date,
comein int DEFAULT 0,
comeout int DEFAULT 0,
PRIMARY key (id)
);

INSERT into myorder VALUES("","11123940","2014-05-10","","50");


SELECT userid ,orderdate ,comein -comeout as rest 
from myorder
GROUP BY userid ,orderdate;


create index myorderindex on myorder(id,userid);


explain SELECT userid ,orderdate ,comein -comeout as rest 
from myorder
GROUP BY userid ,orderdate;



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn