原理介紹:
索引建立
目錄結構劃分方案也只是很簡易的實現了一下
比如一條數據
山寨索引 四個字的unicode為
[
[
[
[
[
[
[
[
那麼對應的文件結構為
索引使用
比如搜索
則搜索
實用性
具體的實用性還有待驗證
演示效果
實現了針對test標的name和caption兩個字段作索引搜索
go
create table test( id uniqueidentifier
insert into test select top
insert into test select top
insert into test select top
insert into test select top
create index i_testid on test( id)
declare @t int
select @t=
dbo
from test
select a
where a
/*
C
*/
clr代碼如下:編譯為MyFullIndex
復制代碼 代碼如下:
using System;
using System
using Microsoft
using System
using System
public partial class UserDefinedFunctions
{
/// <summary>
/// 設置索引目錄
/// </summary>
/// <param name=
/// <returns></returns>
[Microsoft
public static SqlBoolean SetRoot(SqlString value)
{
if (value
if (System
{
root = value
return true ;
}
else
{
return false ;
}
}
/// <summary>
/// 獲取索引目錄
/// </summary>
/// <returns></returns>
[Microsoft
public static SqlString GetRoot()
{
return new SqlString (root);
}
/// <summary>
/// 建立索引
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
[Microsoft
public static SqlInt
{
if (key
return _setIndex(key
}
/// <summary>
/// 查詢索引
/// </summary>
/// <param name=
/// <param name=
/// <returns></returns>
[SqlFunction (TableDefinition =
public static IEnumerable GetIndex(SqlString word
{
System
if (word
return _getIndex
}
public static void FillRow(Object obj
{
string key = obj
pk = key;
}
static string root = @
/// <summary>
/// 獲取有空格分隔的索引信息
/// </summary>
/// <param name=
/// <param name=
/// <returns></returns>
static System
{
string [] arrWord = word
System
if (arrWord
System
for (int i =
{
System
key_list[i] = key_i;
}
for (int i=key_
{
foreach (System
{
if (key_i
{
key_
continue ;
}
}
}
return key_
}
/// <summary>
/// 獲取單個詞的索引信息
/// </summary>
/// <param name=
/// <param name=
/// <returns></returns>
static System
{
System
byte [] bWord = System
if (bWord
string path = string
if (System
{
return ret;
}
string [] arrFiles = System
foreach (string file in arrFiles)
{
string key = System
string index = System
int cIndex = int
bool bHas = true ;
for (int i =
{
string nextFile = string
root
if (System
{
bHas = false ;
break ;
}
}
if (bHas == true &&ret
ret
}
return ret;
}
/// <summary>
/// 建立索引文件
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
static int _setIndex(string key
{
byte [] bContent = System
if (bContent
for (int i =
{
string path = string
if (System
{
System
}
string file = string
if (System
{
System
}
}
return content
}
};
部署的sql腳本如下
CREATE ASSEMBLY MyFullIndex FROM
go
CREATE FUNCTION dbo
RETURNS table ( pk nvarchar (
AS EXTERNAL NAME MyFullIndex
go
CREATE FUNCTION dbo
RETURNS int
AS EXTERNAL NAME MyFullIndex
go
CREATE FUNCTION dbo
RETURNS nvarchar ( max )
AS EXTERNAL NAME MyFullIndex
go
CREATE FUNCTION dbo
RETURNS bit
AS EXTERNAL NAME MyFullIndex
go
From:http://tw.wingwit.com/Article/program/SQLServer/201404/30570.html