惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
博客园_首页
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
博客园 - 司徒正美
有赞技术团队
有赞技术团队
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog

博客园 - 斌哥tobin

Go工程选择开源分库分表中间件可用性测试 Golang解决fatal error: all goroutines are asleep - deadlock! Laravel Model查询结果的3种存储格式内存占用对比 Laravel配置Route调用artisan 研究微信红包分配算法之Golang版 解决IDEA提示Untrusted Server's certificate 证书不可用( Server's certificate is not trusted ) Docker镜像拉取失败或超时的解决办法:添加国内镜像 php连接docker运行的mysql,显示(HY000/2002): Connection refused的解决办法 VirtualBox虚拟CentOS7共享文件夹 Windows7用VirtualBox虚拟Ubuntu共享文件夹的终极方式 PhpStorm添加PHP代码规范检查CodeSniffer(phpcs)和PHP代码静态分析工具Mess Detector(phpmd) php的三个常用判断函数 php计算字符串长度 mac brew 安装php扩展报错:parent directory is world writable but not sticky Mac iTerm2命令行快捷操作 System.Web.AspNetHostingPermission 类型的权限已失败 优化phpstorm运行卡顿问题! composer [ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist - 斌哥tobin nginx1.8安装nginx_concat_module及400错误解决办法
select * 和 select 字段的速度对比
斌哥tobin · 2018-10-17 · via 博客园 - 斌哥tobin

2018-10-17 23:42  斌哥tobin  阅读(4061)  评论()    收藏  举报

拿WordPress的数据库做一个对比

SELECT ID,post_title, post_author FROM wp_posts ORDER BY ID LIMIT 100;
OK, Time: 0.023000s

SELECT * FROM wp_posts ORDER BY ID LIMIT 100;
OK, Time: 0.261000s

SELECT `ID` ,  `post_author` ,  `post_date` ,  `post_date_gmt` ,  `post_content` ,  `post_title` ,  `post_excerpt` ,  `post_status` ,  `comment_status` ,  `ping_status` ,  `post_password`,  `post_name` ,  `to_ping` ,  `pinged` ,   `post_modified` ,  `post_modified_gmt`,  `post_content_filtered`,  `post_parent` ,  `guid`,  `menu_order`,  `post_type`,  `post_mime_type`,  `comment_count`  FROM wp_posts ORDER BY ID LIMIT 100;
OK, Time: 0.231000s

总结

  1. 字段更少速度更快
  2. 没有大内容字段查询速度更快,有大内容字段的表需要最优速度时,可以写明 select 的字段来排除大内容字段
  3. select * 和 select 全部字段的查询速度相差不大

select * 的缺点

  1. select * 不能有效的利用覆盖索引
  2. select * 读取不需要的列会增加CPU、IO、NET消耗

覆盖索引

覆盖索引就是从索引中直接获取查询结果,要使用覆盖索引需要注意select查询列包含在索引列中;where条件包含索引列或者复合索引的前导列