摘要: 1.mysql总是通过创建并填充临时表来执行union查询; 2.除非要服务器消除重复的行,否则一定要用union all。如果没有all关键字,mysql会在临时表加个distinct选项,会导致临时表做唯一检查,这样代价很高; 阅读全文
posted @ 2017-02-09 16:16 李修远 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 一.创建索引 创建表时,同时创建索引 create table stu( id int primary key auto_increment, name varchar(32) not null, age tinyint unsigned not null, email varchar(32) no 阅读全文
posted @ 2017-02-09 16:05 李修远 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 1.当取出的数据超过20%时,优化器不会使用索引,而是全表扫描; 2.limit和offset的问题,其实是offset的问题,它会导致mysql扫描大量不需要的行然后删掉 如: select * from user limit 1000,10; 它是先查1010条,然后删除1000条; 可以试一试 阅读全文
posted @ 2017-02-09 15:34 李修远 阅读(306) 评论(0) 推荐(0) 编辑
摘要: 最常见的一种 select count(*) from goods group by goods_id; 商品数量少的话可以用下面两种写法 select sum(IF(goods_id=1,1,0)) as a,sum(goods_id=2,1,0) as b from goods; select 阅读全文
posted @ 2017-02-09 14:19 李修远 阅读(964) 评论(0) 推荐(0) 编辑
摘要: SELECT count(*) FROM test2 WHERE num<=1; 阅读全文
posted @ 2017-02-09 14:00 李修远 阅读(3693) 评论(0) 推荐(0) 编辑
摘要: count(*) 是统计包含null的记录,而count(列)不含null; 在不带where的情况下count(*)与count(列)相比,并非统计所有列,而是忽略所有列而直接统计行数; 当count(*) 带有where的时候,跟count(列)的性能差不多; 当num字段用了索引时,count 阅读全文
posted @ 2017-02-09 13:27 李修远 阅读(2815) 评论(0) 推荐(0) 编辑
摘要: 1.下载composer并全局安装 curl -sS https://getcomposer.org/installer | php 2.查看全局命令目录 echo $PATH 移动composer到全局目录,这样可以在任何时候可以执行composer命令; mv composer.phar /us 阅读全文
posted @ 2017-02-09 12:54 李修远 阅读(1043) 评论(0) 推荐(0) 编辑
摘要: 1.缓存一些不经常改的数据,如页面显示什么导航,侧边栏按什么分类 2.文件缓存系统设置:如缓存公司用哪个邮箱向用户发邮件; 阅读全文
posted @ 2017-02-09 00:13 李修远 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Select tables optimized away(选择表优化) 阅读全文
posted @ 2017-02-08 20:08 李修远 阅读(1499) 评论(0) 推荐(0) 编辑
摘要: create table daily_hit_counter( day date not null, slot tinyint unsigned not null, cnt int unsigned not null, primary key (day,slot) )engine=innodb in 阅读全文
posted @ 2017-02-08 19:33 李修远 阅读(277) 评论(0) 推荐(0) 编辑