큰 주문입니다.
중개인 접근 방식을 제안하겠습니다.
임의의 guid를 생성하는 System.Guid.NewGuid ()에 문제가 있습니다. (클라이언트가 데이터베이스를 사용하여 순차 ID를 작성하는 대신 자체 guid를 작성할 수 있도록 허용했습니다).
클라이언트 측에서 UuidCreateSequential로 이동하면 특히 INSERT에서 성능이 훨씬 향상되었습니다.
다음은 DotNet 클라이언트 코드 부두입니다. 나는 어딘가에서 나왔을 것이라고 확신한다.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MyCompany.MyTechnology
{
public static class Guid
{
[DllImport("rpcrt4.dll", SetLastError = true)]
static extern int UuidCreateSequential(out System.Guid guid);
public static System.Guid NewGuid()
{
return CreateSequentialUUID();
}
public static System.Guid CreateSequentialUUID()
{
const int RPC_S_OK = 0;
System.Guid g;
int hr = UuidCreateSequential(out g);
if (hr != RPC_S_OK)
throw new ApplicationException("UuidCreateSequential failed: " + hr);
return g;
}
}
}
/*
Original Reference for Code:
http://www.pinvoke.net/default.aspx/rpcrt4/UuidCreateSequential.html
*/
/*
Text From URL above:
UuidCreateSequential (rpcrt4)
Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than rpcrt4, prefix the name with the module name and a period.
. Summary
Creates a new UUID
C# Signature:
[DllImport("rpcrt4.dll", SetLastError=true)]
static extern int UuidCreateSequential(out Guid guid);
VB Signature:
Declare Function UuidCreateSequential Lib "rpcrt4.dll" (ByRef id As Guid) As Integer
User-Defined Types:
None.
Notes:
Microsoft changed the UuidCreate function so it no longer uses the machine's MAC address as part of the UUID. Since CoCreateGuid calls UuidCreate to get its GUID, its output also changed. If you still like the GUIDs to be generated in sequential order (helpful for keeping a related group of GUIDs together in the system registry), you can use the UuidCreateSequential function.
CoCreateGuid generates random-looking GUIDs like these:
92E60A8A-2A99-4F53-9A71-AC69BD7E4D75
BB88FD63-DAC2-4B15-8ADF-1D502E64B92F
28F8800C-C804-4F0F-B6F1-24BFC4D4EE80
EBD133A6-6CF3-4ADA-B723-A8177B70D268
B10A35C0-F012-4EC1-9D24-3CC91D2B7122
UuidCreateSequential generates sequential GUIDs like these:
19F287B4-8830-11D9-8BFC-000CF1ADC5B7
19F287B5-8830-11D9-8BFC-000CF1ADC5B7
19F287B6-8830-11D9-8BFC-000CF1ADC5B7
19F287B7-8830-11D9-8BFC-000CF1ADC5B7
19F287B8-8830-11D9-8BFC-000CF1ADC5B7
Here is a summary of the differences in the output of UuidCreateSequential:
The last six bytes reveal your MAC address
Several GUIDs generated in a row are sequential
Tips & Tricks:
Please add some!
Sample Code in C#:
static Guid UuidCreateSequential()
{
const int RPC_S_OK = 0;
Guid g;
int hr = UuidCreateSequential(out g);
if (hr != RPC_S_OK)
throw new ApplicationException
("UuidCreateSequential failed: " + hr);
return g;
}
Sample Code in VB:
Sub Main()
Dim myId As Guid
Dim code As Integer
code = UuidCreateSequential(myId)
If code <> 0 Then
Console.WriteLine("UuidCreateSequential failed: {0}", code)
Else
Console.WriteLine(myId)
End If
End Sub
*/
대체 아이디어 :
주 DB와 원격 DB가 "링크 된"경우 (sp_linkserver에서와 같이) ... 주 DB를 "uuid generator"로 사용할 수 있습니다.
uuid의 "일대일"을 원하지 않기 때문에 너무 많은 대화가 필요합니다.
그러나 당신은 일련의 uuid를 잡을 수 있습니다.
아래는 몇 가지 코드입니다.
IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N'[dbo].[uspNewSequentialUUIDCreateRange]') AND type in (N'P',
N'PC'))
DROP PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange]
GO
CREATE PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange] (
@newUUIDCount int --return
)
AS
SET NOCOUNT ON
declare @t table ( dummyid int , entryid int identity(1,1) , uuid
uniqueidentifier default newsequentialid() )
insert into @t ( dummyid ) select top (@newUUIDCount) 0 from dbo.sysobjects
so with (nolock)
select entryid , uuid from @t
SET NOCOUNT OFF
GO
/ *
--START TEST
set nocount ON
Create Table #HolderTable (entryid int , uuid uniqueidentifier )
declare @NewUUIDCount int
select @NewUUIDCount = 20
INSERT INTO #HolderTable EXEC dbo.uspNewSequentialUUIDCreateRange
@NewUUIDCount
select * from #HolderTable
DROP Table #HolderTable
--END TEST CODE
* /