第二个要快多少取决于太多的东西。与结果集的大小相比,网络开销可能是微不足道的。
还有另一种选择(它应该比锁定行为更快),即call all of them asynchronously - 那么当最长的页面完成时,您的页面可以有效地完成。显然,这将需要一些额外的编码。
在这个例子中,只有一个SP开销。我们假设该SP返回单个行集客户端将拆分/过程或多个行集:
int[] ids; // array of ids
CallSQLStoredProc(ids) // stored procedure returns more than one row for each id
在这个例子中,SP调用开销N次单呼。和调用序列:
foreach(item in mylist) {
CallSQLStoredProc(item.id);
}
在第三种方式:
foreach(item in mylist) {
StartSQLStoredProc(item.id);
}
// Continue building the page until you reach a point where you absolutely have to have the data
wait();
这仍然具有n个DB调用的开销,但性能的提升可以依赖于SQL服务器和网络的能力为了平行工作量。此外,您还可以在页面构建时启动SQL Server的工作。
单个SP解决方案仍然可以胜出,特别是如果它可以用UNION组装SQL Server可以并行化任务的单个结果集。但是,如果结果集具有单独的模式或者UNION不能很好地执行,多个SP异步解决方案可以将其打败(并且还可以利用在页面中执行其他工作的能力)。
你使用哪个db? 我正在SQL Server中寻找这个函数“spiltCSVs”。 谷歌“spiltCSVs”返回我1结果:-) – 2009-03-24 03:46:05
这是一个实用功能,每个人都根据需要自行编写。 http://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-recor – 2009-03-24 13:21:29