SlideShare una empresa de Scribd logo
1 de 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:

Más contenido relacionado

Destacado (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 a 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 a 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
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
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...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

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: