简体   繁体   English

SQL 查询优化

[英]SQL Query Optimization

If I have a table that has 50 columns, will it take less time to use a statement like如果我有一个有 50 列的表,那么使用如下语句会花费更少的时间吗

SELECT id,name,description FROM table

or will it be the same as if I write还是和我写的一样

SELECT * FROM table

Always return the least number of columns possible to satisfy your needs.始终返回尽可能少的列数以满足您的需求。

If you don't need all the columns, it's certainly best to only select the ones you need.如果您不需要所有列,那么最好只使用您需要的 select。 While it probably won't take MySQL more time to locate the rows, it will certainly be faster to send the results back to the client (since there is less data to return).虽然可能不会花费更多时间来定位行,但将结果发送回客户端肯定会更快(因为要返回的数据更少)。

Selecting all columns always takes longer than selecting the columns you actually want.选择所有列总是比选择您实际需要的列花费更长的时间。 Try them out in PHPMyAdmin or something and have a look at the time they take to complete.在 PHPMyAdmin 或其他东西中试用它们,看看它们完成所需的时间。 For this, using a bigger table is a good idea to get times greater than 0.001 seconds and the like.为此,使用更大的表来获得大于0.001秒等的时间是一个好主意。

James詹姆士

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM