1. 程式人生 > >select * 和 select 欄位的速度對比

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 *,需求變更時少改些地方