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

推荐订阅源

量子位
S
Secure Thoughts
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Privacy International News Feed
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
C
Cybersecurity and Infrastructure Security Agency CISA
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Latest news
Latest news
H
Hacker News: Front Page
月光博客
月光博客
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
WordPress大学
WordPress大学
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
D
Docker
U
Unit 42
Recorded Future
Recorded Future
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Heimdal Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
G
GRAHAM CLULEY
Apple Machine Learning Research
Apple Machine Learning Research
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
Help Net Security
Help Net Security
Google Online Security Blog
Google Online Security Blog
S
SegmentFault 最新的问题

博客园 - 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()的方法在更适用于多服务器环境。