SlideShare a Scribd company logo
1 of 15
GUID vs INT
DEBATE
Francisco J. Carabez
V1.0 Feb 25 2014
INT
ADVANTAGE
Has better performance when used in joins, indexes and conditions.
Numeric values are easier to understand for application’s users if
they are displayed.
Widely used for incrementing key values serially.
Less space for storing.
GUID
ADVANTAGE
Unique across the [universe] servers.
Client side generated. With GUID, the client application can
generate a new value and can send it to the server. It does not need
to wait till the SAVE function returns to know what is the ID.
Consolidation and syncronization. You have Customer Table in 5
different Databases and you want to make a Data warehouse – no
problem – the records can keep their keys.
GUID
ANATOMY
A GUID is most commonly showed as text as a sequence of
hexadecimal digits separated into five groups, such as:
{3F2504E0-4F89-41D3-9A0C-0305E82C3301}
This text notation contains the following fields, separated by hyphens:
Hex digits Description
8 Data1
4 Data2
4 Data3
4 Initial two bytes from Data4
12 Remaining six bytes from Data4
INT, BIGINT & GUID
SPACE
INT
INT (4 bytes or 32bits)
++Native and faster to manage in older Pcs.
++Less space for Indexing.
BIGINT
GUID
BIGINT (8 bytes or 64bits)
++Native and faster to manage in new Pcs.
+Moderate space for Indexing.
GUID (16 bytes or 128bits)
+Practical without performance hits on new Pcs.
-Fragmentation hits on Indexing.
-More space for storing.
Cast BIGINT as GUID8
THE BETTER OF BOTH WORLD
Practical unique for most database systems, meaning easier
integration with replication
Semi-random client side or server side generated.
Semi-Sequential based on date-time stamp.
Not Fragmentation hits on indexes.
GUID8
ANATOMY
LOW INT (lower 4 bytes)
Hold seconds elapsed since Jan 1, 2000.
HI
HI INT (upper 4 bytes)
Random number.
LOW
GUID8
Date-time stamp RANGE?
One Year has 31536000 Seconds (365*24*60*60)
Lower INT can hold 4294967295
4294967295 / 31536000 = 136 years
The GUID8 time stamp approach is safe from YEAR
2000-2136
GUID8
Probability of one DUPLICATE?
Lower INT hold the Date-Time stamp in seconds.
For every second, the upper INT can hold a
RANDOM Number in range from 0 to 4,294,967,295
So having a duplicate is possible but far probable.
FACTS
ON DATABASE MANAGEMENT
GUID is hard to read or typing... Yes but come on! if you're querying that much at
once, you're probably doing it wrong anyhow.
No all tables needs a GUID.
Cost of storage are cheaper and computers are fasters.
GUID Allows asynchronous architectures more easily.
GUID guiltless used by: IPv6, Electronics Devices, Item tagging, OS…
GUID8
GENERATION CODE SQL
SELECT
CAST(
(
CAST(
( EXTRACT(DAY FROM now()-'2001-01-01')*(24*60*60) ) +
( EXTRACT(HOUR FROM now()) * (60*60) ) +
( EXTRACT(MINUTE FROM now()) * (60) ) +
EXTRACT(SECOND FROM now())
AS BIGINT ) << 32
)
+
CAST ( CAST( ROUND(RANDOM()*999999999) AS INT) AS BIGINT )
AS BIGINT )
GUID8
GENERATION CODE postgreSQL
DECLARE
IntLower int;
IntUpper int;
DateNow timestamp;
IntDias int;
IntHoras int;
IntMinutos int;
IntSegundos int;
BigIntReturn bigint;
BEGIN
DateNow = NOW();
IntDias = EXTRACT(DAY FROM DateNow-'2000-01-01'::date)::int;
IntHoras = EXTRACT(HOUR FROM DateNow)::int;
IntMinutos = EXTRACT(MINUTE FROM DateNow)::int;
IntSegundos = EXTRACT(SECOND FROM DateNow)::int;
IntLower := ( IntDias*(24*60*60) ) + IntHoras*(60*60) + IntMinutos*60 + IntSegundos;
IntUpper := ROUND(RANDOM()*999999999)::int;
BigIntReturn := (IntLower::bigint << 32)+IntUpper;
RETURN (BigIntReturn);
END;
OUR PROJECT
REPLICATION & SINCRONATION
QUESTIONS?
THANK YOU!
Download this presentation:
http://www.carabez.com/downloads/sql_guid_vs_int.zip
More Info:
http://es.wikipedia.org/wiki/Globally_unique_identifier
http://betterexplained.com/articles/the-quick-guide-to-guids/
http://krow.livejournal.com/497839.html
http://blog.sqlauthority.com/2010/04/28/sql-server-guid-vs-int-
your-opinion/
LINKS
For review:

More Related Content

Viewers also liked (8)

Do you remember ppt
Do you remember pptDo you remember ppt
Do you remember ppt
 
โปรแกรมการเรียน
โปรแกรมการเรียนโปรแกรมการเรียน
โปรแกรมการเรียน
 
Codigolimpio
CodigolimpioCodigolimpio
Codigolimpio
 
โปรแกรมการเรียน
โปรแกรมการเรียนโปรแกรมการเรียน
โปรแกรมการเรียน
 
The Lunch Box Diet: Rainbow 28 Day Weight Loss Plan
The Lunch Box Diet: Rainbow 28 Day Weight Loss PlanThe Lunch Box Diet: Rainbow 28 Day Weight Loss Plan
The Lunch Box Diet: Rainbow 28 Day Weight Loss Plan
 
Do's & Donts in Preparing PowerPoint Presentation
Do's & Donts in Preparing PowerPoint PresentationDo's & Donts in Preparing PowerPoint Presentation
Do's & Donts in Preparing PowerPoint Presentation
 
Café du e-Commerce 18mars2009 - Le site web peut-il rivaliser avec le conseil...
Café du e-Commerce 18mars2009 - Le site web peut-il rivaliser avec le conseil...Café du e-Commerce 18mars2009 - Le site web peut-il rivaliser avec le conseil...
Café du e-Commerce 18mars2009 - Le site web peut-il rivaliser avec le conseil...
 
Ecommerce Business Models Jlsynave
Ecommerce Business Models JlsynaveEcommerce Business Models Jlsynave
Ecommerce Business Models Jlsynave
 

Similar to Sql guid vs int debate

Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
EstelaJeffery653
 
IBMHadoopofferingTechline-Systems2015
IBMHadoopofferingTechline-Systems2015IBMHadoopofferingTechline-Systems2015
IBMHadoopofferingTechline-Systems2015
Daniela Zuppini
 
Barcode printing presentation lgi
Barcode printing presentation lgiBarcode printing presentation lgi
Barcode printing presentation lgi
Van Chiang
 

Similar to Sql guid vs int debate (20)

Divide and Rule partitioning in pg11
Divide and Rule partitioning in pg11Divide and Rule partitioning in pg11
Divide and Rule partitioning in pg11
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
 
Analysis of symmetric key cryptographic algorithms
Analysis of symmetric key cryptographic algorithmsAnalysis of symmetric key cryptographic algorithms
Analysis of symmetric key cryptographic algorithms
 
Implementation of 2D Optimal Barcode (QR Code) for Images
Implementation of 2D Optimal Barcode (QR Code) for ImagesImplementation of 2D Optimal Barcode (QR Code) for Images
Implementation of 2D Optimal Barcode (QR Code) for Images
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
 
Combating data leakage trojans in commercial and asic applications with time ...
Combating data leakage trojans in commercial and asic applications with time ...Combating data leakage trojans in commercial and asic applications with time ...
Combating data leakage trojans in commercial and asic applications with time ...
 
Virtual training optimizing the tick stack
Virtual training  optimizing the tick stackVirtual training  optimizing the tick stack
Virtual training optimizing the tick stack
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
 
VectorDB Schema Design 101 - Considerations for Building a Scalable and Perfo...
VectorDB Schema Design 101 - Considerations for Building a Scalable and Perfo...VectorDB Schema Design 101 - Considerations for Building a Scalable and Perfo...
VectorDB Schema Design 101 - Considerations for Building a Scalable and Perfo...
 
Introducing an Encryption Algorithm based on IDEA
Introducing an Encryption Algorithm based on IDEAIntroducing an Encryption Algorithm based on IDEA
Introducing an Encryption Algorithm based on IDEA
 
NWSLTR_Volume12_Issue1
NWSLTR_Volume12_Issue1NWSLTR_Volume12_Issue1
NWSLTR_Volume12_Issue1
 
Direct3D and the Future of Graphics APIs - AMD at GDC14
Direct3D and the Future of Graphics APIs - AMD at GDC14Direct3D and the Future of Graphics APIs - AMD at GDC14
Direct3D and the Future of Graphics APIs - AMD at GDC14
 
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On CloudSecure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
 
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
OSA Con 2022 - Tips and Tricks to Keep Your Queries under 100ms with ClickHou...
 
PERFORMANCE EVALUATION OF PARALLEL INTERNATIONAL DATA ENCRYPTION ALGORITHM ON...
PERFORMANCE EVALUATION OF PARALLEL INTERNATIONAL DATA ENCRYPTION ALGORITHM ON...PERFORMANCE EVALUATION OF PARALLEL INTERNATIONAL DATA ENCRYPTION ALGORITHM ON...
PERFORMANCE EVALUATION OF PARALLEL INTERNATIONAL DATA ENCRYPTION ALGORITHM ON...
 
IBMHadoopofferingTechline-Systems2015
IBMHadoopofferingTechline-Systems2015IBMHadoopofferingTechline-Systems2015
IBMHadoopofferingTechline-Systems2015
 
IRJET- Review on Privacy Preserving on Multi Keyword Search over Encrypte...
IRJET-  	  Review on Privacy Preserving on Multi Keyword Search over Encrypte...IRJET-  	  Review on Privacy Preserving on Multi Keyword Search over Encrypte...
IRJET- Review on Privacy Preserving on Multi Keyword Search over Encrypte...
 
InfiniBox z pohledu zákazníka
InfiniBox z pohledu zákazníkaInfiniBox z pohledu zákazníka
InfiniBox z pohledu zákazníka
 
Barcode printing presentation lgi
Barcode printing presentation lgiBarcode printing presentation lgi
Barcode printing presentation lgi
 
Pulpit operatorski Mitsubishi GOT2000 HMI
Pulpit operatorski Mitsubishi GOT2000 HMIPulpit operatorski Mitsubishi GOT2000 HMI
Pulpit operatorski Mitsubishi GOT2000 HMI
 

Recently uploaded

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Sql guid vs int debate

  • 1. GUID vs INT DEBATE Francisco J. Carabez V1.0 Feb 25 2014
  • 2. INT ADVANTAGE Has better performance when used in joins, indexes and conditions. Numeric values are easier to understand for application’s users if they are displayed. Widely used for incrementing key values serially. Less space for storing.
  • 3. GUID ADVANTAGE Unique across the [universe] servers. Client side generated. With GUID, the client application can generate a new value and can send it to the server. It does not need to wait till the SAVE function returns to know what is the ID. Consolidation and syncronization. You have Customer Table in 5 different Databases and you want to make a Data warehouse – no problem – the records can keep their keys.
  • 4. GUID ANATOMY A GUID is most commonly showed as text as a sequence of hexadecimal digits separated into five groups, such as: {3F2504E0-4F89-41D3-9A0C-0305E82C3301} This text notation contains the following fields, separated by hyphens: Hex digits Description 8 Data1 4 Data2 4 Data3 4 Initial two bytes from Data4 12 Remaining six bytes from Data4
  • 5. INT, BIGINT & GUID SPACE INT INT (4 bytes or 32bits) ++Native and faster to manage in older Pcs. ++Less space for Indexing. BIGINT GUID BIGINT (8 bytes or 64bits) ++Native and faster to manage in new Pcs. +Moderate space for Indexing. GUID (16 bytes or 128bits) +Practical without performance hits on new Pcs. -Fragmentation hits on Indexing. -More space for storing.
  • 6. Cast BIGINT as GUID8 THE BETTER OF BOTH WORLD Practical unique for most database systems, meaning easier integration with replication Semi-random client side or server side generated. Semi-Sequential based on date-time stamp. Not Fragmentation hits on indexes.
  • 7. GUID8 ANATOMY LOW INT (lower 4 bytes) Hold seconds elapsed since Jan 1, 2000. HI HI INT (upper 4 bytes) Random number. LOW
  • 8. GUID8 Date-time stamp RANGE? One Year has 31536000 Seconds (365*24*60*60) Lower INT can hold 4294967295 4294967295 / 31536000 = 136 years The GUID8 time stamp approach is safe from YEAR 2000-2136
  • 9. GUID8 Probability of one DUPLICATE? Lower INT hold the Date-Time stamp in seconds. For every second, the upper INT can hold a RANDOM Number in range from 0 to 4,294,967,295 So having a duplicate is possible but far probable.
  • 10. FACTS ON DATABASE MANAGEMENT GUID is hard to read or typing... Yes but come on! if you're querying that much at once, you're probably doing it wrong anyhow. No all tables needs a GUID. Cost of storage are cheaper and computers are fasters. GUID Allows asynchronous architectures more easily. GUID guiltless used by: IPv6, Electronics Devices, Item tagging, OS…
  • 11. GUID8 GENERATION CODE SQL SELECT CAST( ( CAST( ( EXTRACT(DAY FROM now()-'2001-01-01')*(24*60*60) ) + ( EXTRACT(HOUR FROM now()) * (60*60) ) + ( EXTRACT(MINUTE FROM now()) * (60) ) + EXTRACT(SECOND FROM now()) AS BIGINT ) << 32 ) + CAST ( CAST( ROUND(RANDOM()*999999999) AS INT) AS BIGINT ) AS BIGINT )
  • 12. GUID8 GENERATION CODE postgreSQL DECLARE IntLower int; IntUpper int; DateNow timestamp; IntDias int; IntHoras int; IntMinutos int; IntSegundos int; BigIntReturn bigint; BEGIN DateNow = NOW(); IntDias = EXTRACT(DAY FROM DateNow-'2000-01-01'::date)::int; IntHoras = EXTRACT(HOUR FROM DateNow)::int; IntMinutos = EXTRACT(MINUTE FROM DateNow)::int; IntSegundos = EXTRACT(SECOND FROM DateNow)::int; IntLower := ( IntDias*(24*60*60) ) + IntHoras*(60*60) + IntMinutos*60 + IntSegundos; IntUpper := ROUND(RANDOM()*999999999)::int; BigIntReturn := (IntLower::bigint << 32)+IntUpper; RETURN (BigIntReturn); END;
  • 15. Download this presentation: http://www.carabez.com/downloads/sql_guid_vs_int.zip More Info: http://es.wikipedia.org/wiki/Globally_unique_identifier http://betterexplained.com/articles/the-quick-guide-to-guids/ http://krow.livejournal.com/497839.html http://blog.sqlauthority.com/2010/04/28/sql-server-guid-vs-int- your-opinion/ LINKS For review: