SlideShare uma empresa Scribd logo
1 de 30
What SQL should
actually be...
Rafael Ördög, PhD.
Would you ever do this?
function initializeAutoSave() {
setTimeOut(2000, function() {
$('input#save').click();
initializeAutoSave();
});
}
How about doing this?
function createThumbnail($sourceImage) {
$size = Config::get('thumb-size');
$targetImage =
$this->getTargetName($sourceImage);
system("convert {$sourceImage}
--resize {$size}x{$size}
{$thumbImage}");
}
And yet we somehow accept this...
$dbh->exec("SELECT field FROM table");
And if we loathe this:
<script type="text/javascript">
<?php foreach($buttons as $button):?>
initButton(<?=$button["id"]?>,
<?=$button["usefulVar"]?>);
<?php endforeach; ?>
</script>
Why aren't we horrified by this?
function doSomeImportantAndComplexStuffInTheDatabase() {
$dbh->exec("UPDTATE {$this->generateComplexJoins()}" .
"SET {$this->generateFieldsAndValueSubQueries()}" .
"WHERE {$this->generateWhere()}");
}
function generateWhere() {
$result = "TRUE";
foreach($this->importantStuffs as $stuff) {
$result += " AND ".$stuff->subWhere();
}
}
Donald D. Chamberlin
the father of SQL
Origin of SQL
SEQUEL: A STRUCTURED ENGLISH QUERY
LANGUAGE (1974)
by Donald D. Chamberlin
Origin of SQL
SEQUEL: A STRUCTURED ENGLISH QUERY
LANGUAGE (1974)
by Donald D. Chamberlin
"However, there is also a large class of users
who, while they are not computer specialists,
would be willing to learn to interact with a
computer in a reasonably high-level, non-
procedural query language."
SQL is User Interface
● It's not an API
○ So that's why we need an ORM tool...
● It's not a protocol
● It's not even designed for programmers
● It was however derived from another
database CLI called SQUARE, that looks a
bit more like a protocol:
○ NAME, SAL EMP DEPT, MGR ('TOY', 'ANDERSON')
VS
○ SELECT NAME, SAL FROM EMP WHERE DEPT = 'TOY' AND MGR = 'ANDERSON'
The command line user interface is
not an API
● Leaking logic to other languages
● Dynamically generated code is hard to debug
● Security issues
○ Escaping is a horror scene
● Large overhead
○ Process launch overheads
○ Parse overhead
○ Command generation overhead
● Fragility
○ It's more prominent with a GUI, but CLIs are not much better
○ Have you ever tried to maintain a moderately sized
Greasemonkey script? It's a nightmare!
SQL is a bad UI by todays standards,
but it's even worse as an API
● Fails to separate concerns
○ Changing a query to improve performance may involve
breaking business logic
○ Requesting a little more data can have a large
performance hit
○ You could not optimize SQL queries with AOP
● Leaking concepts
○ We leak our entire datastructure to the DB
■ That is why a good ORM should generate DDL from
source code and not the way around
○ To solve performance issues we may even leak some of
our business logic. (Aggregating data.)
■ To the one thing that is hard to scale
Origin of SQL
SEQUEL: A STRUCTURED ENGLISH QUERY
LANGUAGE (1974)
by Donald D. Chamberlin
"SEQUEL identifies a set of simple operations
on tabular structures, which can be shown to
be of equivalent power to the first order
predicate calculus."
Non tabular structures
● Connections between people
● Ownership relations
● Documents (like articles, or presentations)
● Data that belongs to a video on YouTube:
○ Video
○ Comments
○ Likes
○ etc.
● Or more abstractly
○ hierarchies
○ graphs
So we have non tabular data
Customer
Order id
Order item
Order item
Order item
Payment details
And tables to store that in
Customer
Order id
Order item
Order item
Order item
Payment details
OrdersCustomersItemsPayments
And tables to store that in
Customer
Order id
Order item
Order item
Order item
Payment details
OrdersCustomersItemsPayments
Impedancemismatch
Data normalization
Customer
Order id
Order item
Order item
Order item
Payment details
OrdersCustomersItemsPayments
So we normalize our structures
● Strongly related data will be scattered all around
the hard drive
● Performance issues
● DBA requests a denormalization
○ Again: changing code for performance reason in a way
that potentially breaks business logic
● Denormalized data is not indexed by the SQL
database
○ So we create index tables...
● The code using the denormalized tables will be
a lot harder to maintain and understand
SQL tries too hard, and we abuse it
● SQL databases are more than just tabular data
stores
○ They enforce a data transfer mechanism
■ Why do I need to use TCP/IP to reach a local DB?
■ And I even need to authenticate!
○ They are indexing services but with very limited
capabilities.
● Why do we use SQL database for
○ Storing temporary data locally (maybe files or memory?)
○ Storing documents (maybe document stores?)
○ Message queues (it's terrible for that!)
○ Inter process communication (I mean... REALLY?!)
● It enforces a data transfer mechanism so it is really
slow to run tests using the database
○ Even if the data is in an in-memory table
○ So we don't test the DB... or only if we must...
● On the other hand since it's a complicated and
frequently used API, one would be tempted to write a
complete fake
○ One that stores stuff in memory, and won't use TCP/IP to
communicate
○ It's almost impossible to do that well, so we don't...
● But SQL queries may change in case of performance
optimization in ways that it breaks logic...
It makes testing hard
So what would be better?
● A native API instead of string commands. I
should be able to independently specify:
○ what data to collect or save
○ how that should be done
○ what to index
○ the way these commands are sent to the db
● The API should be as simple as possible
● Schema less data structure
○ And if you like static typing, then you can define your
schema as data structures or classes
In an SQL database the data
structure is leaked to the DB
SQL DB
Leaked
structure
APP
Dependence
That is the primary reason we
introduced the DB Layer
SQL DB
Leaked
structure
APP
Dependence
DBLayer
Dependence
A schema less database puts the schema to
the right side of the DB layer boundary
NoSQL DB
Data
Structure
APP
Dependence
DBLayer Dependence
And by the way we are hiring:
c0de-x.com
@devillsroom

Mais conteúdo relacionado

Destaque

Sascon social commerce presentation
Sascon social commerce presentationSascon social commerce presentation
Sascon social commerce presentation
yrewol
 
Lentera News edisi #16 Juli 2015
Lentera News edisi #16 Juli 2015Lentera News edisi #16 Juli 2015
Lentera News edisi #16 Juli 2015
Ananta Bangun
 
The Case for Continual Realignment of the IT Function
The Case for Continual Realignment of the IT FunctionThe Case for Continual Realignment of the IT Function
The Case for Continual Realignment of the IT Function
Formicio
 
Tdr-L'aigua
Tdr-L'aiguaTdr-L'aigua
Tdr-L'aigua
choriol
 
Organizational fitness2013
Organizational fitness2013Organizational fitness2013
Organizational fitness2013
Globant
 
Power point presentations
Power point presentationsPower point presentations
Power point presentations
bauder
 
Biomedical engineering
Biomedical engineeringBiomedical engineering
Biomedical engineering
anderson-_-25
 
Inorme 2 trimestre 2014 biblioteca del pio x
Inorme 2 trimestre 2014   biblioteca del pio xInorme 2 trimestre 2014   biblioteca del pio x
Inorme 2 trimestre 2014 biblioteca del pio x
Daniel Francisco Doffo
 
Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)
Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)
Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)
Gheorghitoiumaria
 

Destaque (18)

Series y libros.htm
Series y libros.htmSeries y libros.htm
Series y libros.htm
 
Sascon social commerce presentation
Sascon social commerce presentationSascon social commerce presentation
Sascon social commerce presentation
 
FATZO Mouse - Semaglutide Poster - 2015 GTC-Diabetes Summit
FATZO Mouse - Semaglutide Poster - 2015 GTC-Diabetes SummitFATZO Mouse - Semaglutide Poster - 2015 GTC-Diabetes Summit
FATZO Mouse - Semaglutide Poster - 2015 GTC-Diabetes Summit
 
Bolroo
BolrooBolroo
Bolroo
 
Lentera News edisi #16 Juli 2015
Lentera News edisi #16 Juli 2015Lentera News edisi #16 Juli 2015
Lentera News edisi #16 Juli 2015
 
The Case for Continual Realignment of the IT Function
The Case for Continual Realignment of the IT FunctionThe Case for Continual Realignment of the IT Function
The Case for Continual Realignment of the IT Function
 
How to be Creative
How to be CreativeHow to be Creative
How to be Creative
 
Tdr-L'aigua
Tdr-L'aiguaTdr-L'aigua
Tdr-L'aigua
 
Organizational fitness2013
Organizational fitness2013Organizational fitness2013
Organizational fitness2013
 
Homage to sri aurobindo, part 2
Homage to sri aurobindo, part 2Homage to sri aurobindo, part 2
Homage to sri aurobindo, part 2
 
Power point presentations
Power point presentationsPower point presentations
Power point presentations
 
Biomedical engineering
Biomedical engineeringBiomedical engineering
Biomedical engineering
 
Afs presentation from SHFCA, March 2013
Afs presentation from SHFCA, March 2013Afs presentation from SHFCA, March 2013
Afs presentation from SHFCA, March 2013
 
INFLUENȚA FACTORILOR DE MEDIU ASUPRA DEGRADĂRII OPERELOR DE ARTĂ MONUMENTALE ...
INFLUENȚA FACTORILOR DE MEDIU ASUPRA DEGRADĂRIIOPERELOR DE ARTĂ MONUMENTALE ...INFLUENȚA FACTORILOR DE MEDIU ASUPRA DEGRADĂRIIOPERELOR DE ARTĂ MONUMENTALE ...
INFLUENȚA FACTORILOR DE MEDIU ASUPRA DEGRADĂRII OPERELOR DE ARTĂ MONUMENTALE ...
 
Best Residential Interior Designer In Pune
Best Residential Interior Designer In PuneBest Residential Interior Designer In Pune
Best Residential Interior Designer In Pune
 
Inorme 2 trimestre 2014 biblioteca del pio x
Inorme 2 trimestre 2014   biblioteca del pio xInorme 2 trimestre 2014   biblioteca del pio x
Inorme 2 trimestre 2014 biblioteca del pio x
 
Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)
Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)
Teoria si metodologia_instruirii_autor_conf_univ_dr_irina_maciuc (1)
 
Razvoj i prezentacija na proekt
Razvoj i prezentacija na proektRazvoj i prezentacija na proekt
Razvoj i prezentacija na proekt
 

Semelhante a What SQL should actually be...

Tales from the Field
Tales from the FieldTales from the Field
Tales from the Field
MongoDB
 
Big Data in 200 km/h | AWS Big Data Demystified #1.3
Big Data in 200 km/h | AWS Big Data Demystified #1.3  Big Data in 200 km/h | AWS Big Data Demystified #1.3
Big Data in 200 km/h | AWS Big Data Demystified #1.3
Omid Vahdaty
 
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using StarlingSpeeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using Starling
Erik Osterman
 

Semelhante a What SQL should actually be... (20)

Improving PySpark performance: Spark Performance Beyond the JVM
Improving PySpark performance: Spark Performance Beyond the JVMImproving PySpark performance: Spark Performance Beyond the JVM
Improving PySpark performance: Spark Performance Beyond the JVM
 
Tales from the Field
Tales from the FieldTales from the Field
Tales from the Field
 
How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2
 
The magic of (data parallel) distributed systems and where it all breaks - Re...
The magic of (data parallel) distributed systems and where it all breaks - Re...The magic of (data parallel) distributed systems and where it all breaks - Re...
The magic of (data parallel) distributed systems and where it all breaks - Re...
 
Keeping the fun in functional w/ Apache Spark @ Scala Days NYC
Keeping the fun in functional   w/ Apache Spark @ Scala Days NYCKeeping the fun in functional   w/ Apache Spark @ Scala Days NYC
Keeping the fun in functional w/ Apache Spark @ Scala Days NYC
 
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Beyond Shuffling  - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...Beyond Shuffling  - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
 
Randomizing Data With SQL Server
Randomizing Data With SQL ServerRandomizing Data With SQL Server
Randomizing Data With SQL Server
 
Etl confessions pg conf us 2017
Etl confessions   pg conf us 2017Etl confessions   pg conf us 2017
Etl confessions pg conf us 2017
 
Data Pipline Observability meetup
Data Pipline Observability meetup Data Pipline Observability meetup
Data Pipline Observability meetup
 
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
 
Big Data in 200 km/h | AWS Big Data Demystified #1.3
Big Data in 200 km/h | AWS Big Data Demystified #1.3  Big Data in 200 km/h | AWS Big Data Demystified #1.3
Big Data in 200 km/h | AWS Big Data Demystified #1.3
 
Sql server performance tuning
Sql server performance tuningSql server performance tuning
Sql server performance tuning
 
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using StarlingSpeeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using Starling
 
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
PostgreSQL - масштабирование в моде, Valentine Gogichashvili (Zalando SE)
 
SPL_ALL_EN.pptx
SPL_ALL_EN.pptxSPL_ALL_EN.pptx
SPL_ALL_EN.pptx
 
Stumbling stones when migrating from Oracle
 Stumbling stones when migrating from Oracle Stumbling stones when migrating from Oracle
Stumbling stones when migrating from Oracle
 
Dirty data? Clean it up! - Datapalooza Denver 2016
Dirty data? Clean it up! - Datapalooza Denver 2016Dirty data? Clean it up! - Datapalooza Denver 2016
Dirty data? Clean it up! - Datapalooza Denver 2016
 
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
Dirty Data? Clean it up! - Rocky Mountain DataCon 2016
 
The immutable database datomic
The immutable database   datomicThe immutable database   datomic
The immutable database datomic
 
Webinar: Avoiding Sub-optimal Performance in your Retail Application
Webinar: Avoiding Sub-optimal Performance in your Retail ApplicationWebinar: Avoiding Sub-optimal Performance in your Retail Application
Webinar: Avoiding Sub-optimal Performance in your Retail Application
 

Mais de Open Academy

Dev tools rendering & memory profiling
Dev tools rendering & memory profilingDev tools rendering & memory profiling
Dev tools rendering & memory profiling
Open Academy
 
BlackBerry10 alapú natív alkalmazásfejlesztés
BlackBerry10 alapú natív alkalmazásfejlesztésBlackBerry10 alapú natív alkalmazásfejlesztés
BlackBerry10 alapú natív alkalmazásfejlesztés
Open Academy
 
Okostelefonok és táblagépek menedzsmentje
Okostelefonok és táblagépek menedzsmentjeOkostelefonok és táblagépek menedzsmentje
Okostelefonok és táblagépek menedzsmentje
Open Academy
 

Mais de Open Academy (20)

BDD demisztifikálva
BDD demisztifikálvaBDD demisztifikálva
BDD demisztifikálva
 
Dev tools rendering & memory profiling
Dev tools rendering & memory profilingDev tools rendering & memory profiling
Dev tools rendering & memory profiling
 
Firefox OS: hackelni könnyű
Firefox OS:  hackelni könnyűFirefox OS:  hackelni könnyű
Firefox OS: hackelni könnyű
 
Coding dojo
Coding dojoCoding dojo
Coding dojo
 
BlackBerry10 alapú natív alkalmazásfejlesztés
BlackBerry10 alapú natív alkalmazásfejlesztésBlackBerry10 alapú natív alkalmazásfejlesztés
BlackBerry10 alapú natív alkalmazásfejlesztés
 
Android fejlesztés
Android fejlesztésAndroid fejlesztés
Android fejlesztés
 
Magvas gondolatok
Magvas gondolatokMagvas gondolatok
Magvas gondolatok
 
A Windows Phone világa
A Windows Phone világaA Windows Phone világa
A Windows Phone világa
 
Okostelefonok és táblagépek menedzsmentje
Okostelefonok és táblagépek menedzsmentjeOkostelefonok és táblagépek menedzsmentje
Okostelefonok és táblagépek menedzsmentje
 
Windows 8
Windows 8Windows 8
Windows 8
 
Ipari felhő infrastruktúrák a gyakorlatban
Ipari felhő infrastruktúrák a gyakorlatbanIpari felhő infrastruktúrák a gyakorlatban
Ipari felhő infrastruktúrák a gyakorlatban
 
Túlélés a Három Betűs Rövidítések világában
Túlélés a Három Betűs Rövidítések világábanTúlélés a Három Betűs Rövidítések világában
Túlélés a Három Betűs Rövidítések világában
 
Adminisztratív protokollok ellenőrzési lehetőségei
Adminisztratív protokollok ellenőrzési lehetőségeiAdminisztratív protokollok ellenőrzési lehetőségei
Adminisztratív protokollok ellenőrzési lehetőségei
 
Naplózás a gyakorlatban
Naplózás a gyakorlatbanNaplózás a gyakorlatban
Naplózás a gyakorlatban
 
Hogyan optimalizáljunk C/C++ kódokat!
Hogyan optimalizáljunk C/C++ kódokat!Hogyan optimalizáljunk C/C++ kódokat!
Hogyan optimalizáljunk C/C++ kódokat!
 
Hogy kerül a csizma az asztalra?
Hogy kerül a csizma az asztalra?Hogy kerül a csizma az asztalra?
Hogy kerül a csizma az asztalra?
 
AGILIS / SCRUM fejlesztés
AGILIS / SCRUM fejlesztésAGILIS / SCRUM fejlesztés
AGILIS / SCRUM fejlesztés
 
Multiplatform mobil fejlesztések
Multiplatform mobil fejlesztésekMultiplatform mobil fejlesztések
Multiplatform mobil fejlesztések
 
Webműves Kelemen tanácsai, avagy mi kell a PHP falába?
Webműves Kelemen tanácsai, avagy mi kell a PHP falába?Webműves Kelemen tanácsai, avagy mi kell a PHP falába?
Webműves Kelemen tanácsai, avagy mi kell a PHP falába?
 
Verziókövető rendszerek alkalmazása fejlesztési projektekben
Verziókövető rendszerek alkalmazása fejlesztési projektekbenVerziókövető rendszerek alkalmazása fejlesztési projektekben
Verziókövető rendszerek alkalmazása fejlesztési projektekben
 

Último

Último (20)

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...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

What SQL should actually be...

  • 1. What SQL should actually be... Rafael Ördög, PhD.
  • 2.
  • 3.
  • 4. Would you ever do this? function initializeAutoSave() { setTimeOut(2000, function() { $('input#save').click(); initializeAutoSave(); }); }
  • 5. How about doing this? function createThumbnail($sourceImage) { $size = Config::get('thumb-size'); $targetImage = $this->getTargetName($sourceImage); system("convert {$sourceImage} --resize {$size}x{$size} {$thumbImage}"); }
  • 6. And yet we somehow accept this... $dbh->exec("SELECT field FROM table");
  • 7. And if we loathe this: <script type="text/javascript"> <?php foreach($buttons as $button):?> initButton(<?=$button["id"]?>, <?=$button["usefulVar"]?>); <?php endforeach; ?> </script>
  • 8. Why aren't we horrified by this? function doSomeImportantAndComplexStuffInTheDatabase() { $dbh->exec("UPDTATE {$this->generateComplexJoins()}" . "SET {$this->generateFieldsAndValueSubQueries()}" . "WHERE {$this->generateWhere()}"); } function generateWhere() { $result = "TRUE"; foreach($this->importantStuffs as $stuff) { $result += " AND ".$stuff->subWhere(); } }
  • 9.
  • 10. Donald D. Chamberlin the father of SQL
  • 11. Origin of SQL SEQUEL: A STRUCTURED ENGLISH QUERY LANGUAGE (1974) by Donald D. Chamberlin
  • 12. Origin of SQL SEQUEL: A STRUCTURED ENGLISH QUERY LANGUAGE (1974) by Donald D. Chamberlin "However, there is also a large class of users who, while they are not computer specialists, would be willing to learn to interact with a computer in a reasonably high-level, non- procedural query language."
  • 13. SQL is User Interface ● It's not an API ○ So that's why we need an ORM tool... ● It's not a protocol ● It's not even designed for programmers ● It was however derived from another database CLI called SQUARE, that looks a bit more like a protocol: ○ NAME, SAL EMP DEPT, MGR ('TOY', 'ANDERSON') VS ○ SELECT NAME, SAL FROM EMP WHERE DEPT = 'TOY' AND MGR = 'ANDERSON'
  • 14. The command line user interface is not an API ● Leaking logic to other languages ● Dynamically generated code is hard to debug ● Security issues ○ Escaping is a horror scene ● Large overhead ○ Process launch overheads ○ Parse overhead ○ Command generation overhead ● Fragility ○ It's more prominent with a GUI, but CLIs are not much better ○ Have you ever tried to maintain a moderately sized Greasemonkey script? It's a nightmare!
  • 15. SQL is a bad UI by todays standards, but it's even worse as an API ● Fails to separate concerns ○ Changing a query to improve performance may involve breaking business logic ○ Requesting a little more data can have a large performance hit ○ You could not optimize SQL queries with AOP ● Leaking concepts ○ We leak our entire datastructure to the DB ■ That is why a good ORM should generate DDL from source code and not the way around ○ To solve performance issues we may even leak some of our business logic. (Aggregating data.) ■ To the one thing that is hard to scale
  • 16. Origin of SQL SEQUEL: A STRUCTURED ENGLISH QUERY LANGUAGE (1974) by Donald D. Chamberlin "SEQUEL identifies a set of simple operations on tabular structures, which can be shown to be of equivalent power to the first order predicate calculus."
  • 17. Non tabular structures ● Connections between people ● Ownership relations ● Documents (like articles, or presentations) ● Data that belongs to a video on YouTube: ○ Video ○ Comments ○ Likes ○ etc. ● Or more abstractly ○ hierarchies ○ graphs
  • 18. So we have non tabular data Customer Order id Order item Order item Order item Payment details
  • 19. And tables to store that in Customer Order id Order item Order item Order item Payment details OrdersCustomersItemsPayments
  • 20. And tables to store that in Customer Order id Order item Order item Order item Payment details OrdersCustomersItemsPayments Impedancemismatch
  • 21. Data normalization Customer Order id Order item Order item Order item Payment details OrdersCustomersItemsPayments
  • 22. So we normalize our structures ● Strongly related data will be scattered all around the hard drive ● Performance issues ● DBA requests a denormalization ○ Again: changing code for performance reason in a way that potentially breaks business logic ● Denormalized data is not indexed by the SQL database ○ So we create index tables... ● The code using the denormalized tables will be a lot harder to maintain and understand
  • 23. SQL tries too hard, and we abuse it ● SQL databases are more than just tabular data stores ○ They enforce a data transfer mechanism ■ Why do I need to use TCP/IP to reach a local DB? ■ And I even need to authenticate! ○ They are indexing services but with very limited capabilities. ● Why do we use SQL database for ○ Storing temporary data locally (maybe files or memory?) ○ Storing documents (maybe document stores?) ○ Message queues (it's terrible for that!) ○ Inter process communication (I mean... REALLY?!)
  • 24. ● It enforces a data transfer mechanism so it is really slow to run tests using the database ○ Even if the data is in an in-memory table ○ So we don't test the DB... or only if we must... ● On the other hand since it's a complicated and frequently used API, one would be tempted to write a complete fake ○ One that stores stuff in memory, and won't use TCP/IP to communicate ○ It's almost impossible to do that well, so we don't... ● But SQL queries may change in case of performance optimization in ways that it breaks logic... It makes testing hard
  • 25.
  • 26. So what would be better? ● A native API instead of string commands. I should be able to independently specify: ○ what data to collect or save ○ how that should be done ○ what to index ○ the way these commands are sent to the db ● The API should be as simple as possible ● Schema less data structure ○ And if you like static typing, then you can define your schema as data structures or classes
  • 27. In an SQL database the data structure is leaked to the DB SQL DB Leaked structure APP Dependence
  • 28. That is the primary reason we introduced the DB Layer SQL DB Leaked structure APP Dependence DBLayer Dependence
  • 29. A schema less database puts the schema to the right side of the DB layer boundary NoSQL DB Data Structure APP Dependence DBLayer Dependence
  • 30. And by the way we are hiring: c0de-x.com @devillsroom