深入SQL(随时更新。。。)

explain  select * from table;   使用explain命令调查最终查询计划,但是sql语句不执行

 

create table cityex like city     只会获取到city这个表的表结构,其中的内容无法同步获取到放在新表cityex里面

 

insert into cityex select * from city     

不光会获取到city这个表的表结构,其中的内容也会同步获取到放在新表cityex里面

 

create table cityex as select * from city;       创建表的同时,把数据填进去。

 

删除索引

alter table `config` drop index idx_config_name;

表达式不走索引

函数不走索引

不等于不走索引

explain select * from cityex where ID - 1 =276;
mysql中的UPPER(s)函数是用来把小写的字符转换成大写
explain select * from cityex where UPPER(name) = 'HEFEI';

explain select * from cityex where name != 'HE';

楼下也为不等于
explain select * from cityex where name <> 'he';
楼下为in的时候就走索引
explain select * from cityex where name not in ('HE','ge');
改为‘h%’就走索引
explain select * from cityex where name like '%h';

新建索引,之后以新建索引来扫描,而不是全盘扫码

新建索引
alter table table1 add index idx_population(population,name);
查看是什么扫描
explain select population,name from table1 order by population desc;
alter table table1 add index idx_CountryCode_pop_name(countrycode,population,name);
建索引要遵循最左原则,也就是从where后面的条件开始设置他的一组索引中的第一个索引
explain select population,name from table1 where countrycode = 'CHINA' order by population desc;
 

 

 

 

个性签名:一个人在年轻的时候浪费自己的才华与天赋是一件非常可惜的事情

        如果觉得这篇文章对你有小小的帮助的话,记得在左下角点个“👍”哦,博主在此感谢!

 

万水千山总是情,打赏5毛买辣条行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾! 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值