SQL Server 检索行时的性能比较

发布于 2025-01-01 04:28:24 字数 213 浏览 3 评论 0原文

我想知道以下场景中哪个更快:

是否更有效

  1. 三个表 A、B 和 C - 使用Select * from A, select * from B 然后使用 C ,从而接收它们的所有数据results
  2. 内连接 AB 和 C 并在单个数组中接收所有结果?

谢谢并希望它是清楚的

I wanted to know which is faster from the following scenario:

Three tables A, B and C - Is it more efficient to use

  1. Select * from A, select * from B and then C and hence receive all their results
  2. Inner join A B and C and receive all results in a single array?

Thanks and hope it is clear

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淑女气质 2025-01-08 04:28:24

方法2,否则

  1. 你会在客户端得到3组数据要处理
  2. 到数据库服务器的3次往返
  3. 记录比你需要的多,因为SQL Server中没有通过JOIN进行过滤
  4. 数据库被设计为JOIN
  5. 不要认为你可以比 RDBMS 做得更好
  6. ...

Method 2, otherwise

  1. You get 3 sets of data to process in the client
  2. 3 round trips to the database server
  3. More records than you need , because no filtering via the JOIN is applied in SQL Server
  4. Databases are designed to JOIN
  5. Don't think you can do better than the RDBMS
  6. ...
放手` 2025-01-08 04:28:24

理论上,方法1应该更慢,因为如果与方法2相比,你将触发3条sql语句,只有1条sql语句。

theoretically, method 1 should be slower because you will be firing 3 sql statement if compare with method 2, only 1 single sql statement.

故事还在继续 2025-01-08 04:28:24

连接应该更快,因为索引(如果有)将尽可能使用;但是,永远不要使用“select *”,而是仅列出您需要的列。使用 * 会导致性能下降,因为您将检索超出需要的列,或者如果表结构发生变化并添加了更多列(例如 blob)。

The join should be faster since indexes, if any, will be used whenever possible; however, don't ever use 'select *' instead list only the columns you need. Using * will cause performance degradation just by the fact that you'll be retrieving more columns than needed or if the table structure changes and more columns are added, for example blobs.

最舍不得你 2025-01-08 04:28:24

这取决于。
我曾经使用连接从 3 个表中读取数据,这在结果集中生成了大约 100 万行来读取。现在我使用 3 个简单的选择,总共大约有 44000 行,并使用 .net 字典(它是一个 C# 应用程序)将它们连接到内存中。显然,这比通过网络检索一百万行要快得多。

It depends.
I once read from 3 Tables using joins, which generated me about 1 Million rows in the result set to read. Now I'm using 3 simple selects, wich gives me about 44000 rows overall, and join them in memory using .net Dictionaries (It's a C# application). Obviously this is much faster than retreiving a million rows via network.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文