SQLSERVER2008中CTE的Split与CLR的性能比较


我们新建一个DataBase project,然后建立一个UserDefinedFunctions,Code像这样:

复制代码 代码如下:

1: /// <summary>
/// SQLs the array.
/// </summary>
/// <param name="str">The STR.</param>
/// <param name="delimiter">The delimiter.</param>
/// <returns></returns>
/// 1/8/2010 2:41 PM author: v-pliu
[SqlFunction(Name = "CLR_Split",
FillRowMethodName = "FillRow",
TableDefinition = "id nvarchar(10)")]
public static IEnumerable SqlArray(SqlString str, SqlChars delimiter)
{
if (delimiter.Length == 0)
return new string[1] { str.Value };
return str.Value.Split(delimiter[0]);
}
/// <summary>
/// Fills the row.
/// </summary>
/// <param name="row">The row.</param>
/// <param name="str">The STR.</param>
/// 1/8/2010 2:41 PM author: v-pliu
public static void FillRow(object row, out SqlString str)
{
str = new SqlString((string)row);
}

然后Bulid,Deploy一切OK后,在SSMS中执行以下测试T-sql:
复制代码 代码如下:

DECLARE @array VARCHAR(max)
SET @array = '39,15,93,68,64,43,90,58,39,9,26,26,89,47,91,57,98,16,55,9,63,29,69,16,41,76,34,60,68,64,61,53,32,30,11,72,57,63,36,43,22,14,60,38,24,5,66,26,26,21,22,99,55,18,7,10,46,76,27,88,9,29,89,75,48,72,94,59,35,19,0,35,79,11,87,49,68,30,91,35,9,7,34,47,41,61,98,13,22,1,26,80,35,48,34,92,24,85,90,51' SELECT id FROM dbo.CLR_Split(@array,',')

我们来看它的Client Statistic:

Split string in SQL Server 2005+ CLR vs. T-SQL
Author:Petter Liu



相关阅读:
安装 VS2005 SP1 有关问题的解决办法
JavaScript之信息的封装 js对象入门
.NET 4:可扩展缓存构建监视器
JQuery 前台切换网站的样式实现
用PHP将网址字符串转换成超链接(网址或email)
oracle杀死死锁进程
Windows7系统技巧:常用的10个快捷键
MooTools教程(7):设置和获取样式表属性
Discuz! 7.0论坛模板制作更加简单化
SQL2005 服务器因重装改名后出错的说明
甲骨文如何解析语义谜题
在DB2数据库的表中插入和删除数据
SQLServer更改sa用户名的方法
Silverlight融合ajax实现前后台数据交互
快速导航

Copyright © 2016 phpStudy |