惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
S
Secure Thoughts
酷 壳 – CoolShell
酷 壳 – CoolShell
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
美团技术团队
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
V
Visual Studio Blog
腾讯CDC
小众软件
小众软件
有赞技术团队
有赞技术团队
博客园 - 聂微东
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
IT之家
IT之家
C
CERT Recently Published Vulnerability Notes
大猫的无限游戏
大猫的无限游戏
T
Threat Research - Cisco Blogs
SecWiki News
SecWiki News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Hacker News
The Hacker News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Troy Hunt's Blog
月光博客
月光博客
雷峰网
雷峰网
T
Tor Project blog
I
Intezer
S
Securelist
罗磊的独立博客
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
NISL@THU
NISL@THU
Google Online Security Blog
Google Online Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
www.infosecurity-magazine.com
www.infosecurity-magazine.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
Lohrmann on Cybersecurity
The Cloudflare Blog
Attack and Defense Labs
Attack and Defense Labs
P
Privacy International News Feed
W
WeLiveSecurity
Forbes - Security
Forbes - Security
量子位
Last Week in AI
Last Week in AI

博客园 - thh

svm资料收集 向量空间及其他相关数学结构 难题--autoconf、automake、libtool Linq 中不爽之处 关于UI设计的文章汇总 Window Live Writer LR 剖析器 MVP模式中的P和V关系 静态构造函数线程安全的几个版本[转载] 区域性 ID 2155 (0x086B)不是受支持的区域性 解决方法 windbg给clr设置断点 python ip和int 互转函数 interface与pojo类之间的关系 关于OpenId Python SOAPpy访问asp.net web service 代码 Python SOAPpy 和 .net WebService Type.GetType 获得本Assembly以外的类型 NHibernate 代码生成工具 NHibernate使用笔记
Guid、Int、BigInt编号的速度和存储空间的比较
thh · 2007-10-02 · via 博客园 - thh

   比较了一下创建记录的时间,和表空间的大小,首先创建了3个表:

CREATE TABLE [dbo].[Role](
    
[Id] [uniqueidentifier] NOT NULL,
    
[Name] [nvarchar](255NULL,
    
[Description] [nvarchar](255NULL,
    
PRIMARY KEY CLUSTERED 
    (
        
[Id] ASC
    )
)

CREATE TABLE [dbo].[RoleId](
    
[Id] [int] NOT NULL,
    
[Name] [nvarchar](255NULL,
    
[Description] [nvarchar](255NULL,
    
PRIMARY KEY CLUSTERED 
    (
        
[Id] ASC
    )
)

CREATE TABLE [dbo].[RoleBigId](
    
[Id] [bigint] NOT NULL,
    
[Name] [nvarchar](255NULL,
    
[Description] [nvarchar](255NULL,
    
PRIMARY KEY CLUSTERED 
    (
        
[Id] ASC
    )
)


  

然后分别添加100万条记录

declare @i int
set @i=0
while @i <1000000
begin
   
insert into role(Id) values(newid())
   
set @i = @i +1 
end   

declare @j int 
set @j=0
while @j <1000000
begin
   
insert into roleid(Id) values(@j)
   
set @j = @j +1 
end


declare @m bigint
set @m=4294967296
while @m <4295967296
begin
   
insert into RoleBigId(Id) values(@m)
   
set @m = @m +1 
end  

空间 时间
Guid data:33792KB
index_size:160KB
20.47s
Int data:12864kb
index_size:56 KB
3.39s
Bigint data:16808kb
index_size:88kb
3.38s

分析:
   运行速度:Guid的插入速度比其他的明显慢很多。然后select newid() 1万条看,大约18s,按比例计算,主要的时间是在newid函数上。
   存储空间:Guid是耗费的空间大约是bigint的2倍,bigint大约比int大1/3.

结论:因为在同一个系统(可能存在多个服务器)内要产生唯一的Id,有2个类型的Id,一种是Guid,一种是int(bigint)。Guid的实现比较简单,只要newid()类似的功能。而使用int类编号,必须附加一些额外的产生机制,保证不重复。额外的机制需要建立一个Id生成的方法,如分配一定的范围为每个使用者,建立一个多用户环境的同步机制。 这个部分的代码的效能可能比newid需要更多的时间,或者更多的配置,结果导致系统更复杂。 从这个综合考虑看,newid()的方法在更适用于多服务器环境。