开发者

Would be SELECT * faster than 40 columns listing? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Which is faster/best? SELECT * or SELECT column1, colum2, column3开发者_JAVA技巧, etc.

I have table about 45 columns, however I need to select 40 of them.

Wouldn't be SELECT * faster than to list every column but those 5 I do not need?

What's faster in this case?

I'm selecting only ONE ROW!


Typing the columns out is faster for the database, typing * is faster for you to type. Pick whichever is more important :-)


from http://forge.mysql.com/wiki/Top10SQLPerformanceTips

Network Performance Tips:

Minimize traffic by fetching only what you need:

  • Don't use SELECT *

Also think of DB engine allocating result set memory for those 5 extra columns that you don't need and sending it over the wire. Even if there is no performance penalty there is memory overhead, so it is almost always better to select only what you need.


SELECT * should never be used, at least in production applications. It is always slower. Use SELECT * only while in development stage, when it is faster for you. By the way, it is bad code practice. Read about drawbacks here: http://www.pdxperts.com/article-sqlselect.php


The server still has to read pages from disk if it is not in memory, then read from memory to cache and finally to cpu and those data will be on the same page unless you have some really huge columns that you don't want to fetch.

You can reduce the network traffic a little bit (40 vs 45 fields), but I doubt it will make a big difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜