多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
![](https://img.kancloud.cn/41/e0/41e066af9a6c25a24868d9667253ec98_1241x333.jpg) ***** ## 单表优化 建表 ``` create table article( id int unsigned not null primary key auto_increment, author_id int unsigned not null, category_id int unsigned not null, views int unsigned not null, comments int unsigned not null, title varchar(255) not null, content text not null ); ``` 插入数据 ``` insert into article(`author_id`,`category_id`,`views`,`comments`,`title`,`content`) values (1,1,1,1,'1','1'), (2,2,2,2,'2','2'), (1,1,3,3,'3','3'); ``` 查询category_id为1且comments大于1的情况下,views最多的article_id ## 双表优化 建表 ~~~ 商品类别 create table class( id int unsigned not null primary key auto_increment, card int unsigned not null ); 图书表 create table book( bookid int unsigned not null auto_increment primary key, card int unsigned not null ); ~~~ 驱动表的概念,mysql中指定了连接条件时,满足查询条件的记录行数少的表为驱动表;如未指定查询条件,则扫描行数少的为驱动表。mysql优化器就是这么粗暴以小表驱动大表的方式来决定执行顺序的。