且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 * 与字段名称列表的 SELECT 语句性能

更新时间:2023-02-18 23:41:44

作为编程的一般规则,显式几乎总是***实践.

As a general rule in programming, it is almost always a best practice to be explicit.

Select * 在维护方面并没有真正为您节省多少,因为在大多数情况下无论如何都必须更新使用该查询的代码.

Select * doesn't really save you that much in terms of maintenance given that the code that consumes that query will have to be updated in most cases anyway.

如果您编写的代码只是盲目地对特定表中的任何字段进行操作,那么您就是在自找麻烦.例如,向表中添加某种维护列(如时间戳)的 DBA 不会认为它会突然出现在您的应用程序中.让您的应用面向未来的***方式是明确.

If you are writing code that just blindly operates on whatever fields happen to be in a specific table, you are asking for trouble. For example, the DBA who adds some kind of maintenance column to a table like a timestamp isn't going to be thinking it will suddenly show up in your app. The best way to future-proof your app is to be explicit.

此外,不要忘记在客户端-服务器架构中拖拽您不打算使用的数据列所带来的带宽成本.

Also, don't forget about the bandwidth cost in a client-server architecture from dragging down columns of data that you aren't going to use.

在我不久前写的这篇短文中,我对使用 select * 的性能影响做了更彻底的处理:"不要使用 Select *"

I did a more thorough treatment on the performance implications of using select * in this short article I wrote a while back: "Don't Use Select *"