Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc

后端 未结 30 3480
清歌不尽
清歌不尽 2020-11-21 23:59

I\'ve heard that SELECT * is generally bad practice to use when writing SQL commands because it is more efficient to SELECT columns you specificall

30条回答
  •  一个人的身影
    2020-11-22 00:37

    While explicitly listing columns is good for performance, don't get crazy.

    So if you use all the data, try SELECT * for simplicity (imagine having many columns and doing a JOIN... query may get awful). Then - measure. Compare with query with column names listed explicitly.

    Don't speculate about performance, measure it!

    Explicit listing helps most when you have some column containing big data (like body of a post or article), and don't need it in given query. Then by not returning it in your answer DB server can save time, bandwidth, and disk throughput. Your query result will also be smaller, which is good for any query cache.

提交回复
热议问题