select * 和 select 字段的速度对比

拿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 *,需求变更时少改些地方

猜你喜欢

转载自www.cnblogs.com/imbin/p/9807931.html