SQL Server 检索行时的性能比较
我想知道以下场景中哪个更快:
是否更有效
- 三个表 A、B 和 C - 使用
Select * from A, select * from B
然后使用 C ,从而接收它们的所有数据results 内连接 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
Select * from A, select * from B
and then C and hence receive all their resultsInner join A B and C
and receive all results in a single array?
Thanks and hope it is clear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
方法2,否则
Method 2, otherwise
理论上,方法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.
连接应该更快,因为索引(如果有)将尽可能使用;但是,永远不要使用“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.
这取决于。
我曾经使用连接从 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.