SlideShare a Scribd company logo
1 of 52
Download to read offline
© 2015 by Markus Winand
iStockPhoto/Mitshu
From Backend to Frontend
When database optimization affects the full stack
@MarkusWinand
@SQLPerfTips
@ModernSQL
© 2015 by Markus Winand
Full Stack, Really?
© 2015 by Markus Winand
Full Stack, Really?
© 2015 by Markus Winand
What Users Want are Used to
© 2015 by Markus Winand
What Users Want are Used to
Let’s
click here
© 2015 by Markus Winand
User Clicks on Page 2
Gimme
Page 2!
Gimme
Rows
11 to 20
SQL for “Gimme Rows 11 to 20”
se!e"# *
$%om news
whe%e #op&" ' 1234
o%de% b( da#e des", &d des"
o!!se" 10
#$m$" 10
Inside the Database: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'20)
So%# Me#hod: "op-N heapso&" Memo&(: 19)B
-> B&#map Heap S"an (a"#ua! %ows'10000)
Re"he") *ond: (#op&" ' 1234)
-> B&#map Index S"an (a"#ua! %ows'10000)
Index *ond: (#op&" ' 1234)
Inside the Database: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'30)
So%# Me#hod: "op-N heapso&" Memo&(: 20)B
-> B&#map Heap S"an (a"#ua! %ows'10000)
Re"he") *ond: (#op&" ' 1234)
-> B&#map Index S"an (a"#ua! %ows'10000)
Index *ond: (#op&" ' 1234)
Inside the Database: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'40)
So%# Me#hod: "op-N heapso&" Memo&(: 22)B
-> B&#map Heap S"an (a"#ua! %ows'10000)
Re"he") *ond: (#op&" ' 1234)
-> B&#map Index S"an (a"#ua! %ows'10000)
Index *ond: (#op&" ' 1234)
Inside the Database: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'10000)
So%# Me#hod: ex"e&na# me&*e D$s): 1200)B
-> B&#map Heap S"an (a"#ua! %ows'10000)
Re"he") *ond: (#op&" ' 1234)
-> B&#map Index S"an (a"#ua! %ows'10000)
Index *ond: (#op&" ' 1234)
Inside the Database: Worst Case
Speed depends on the number of matched rows
and the page fetched.
Fetching the last page
can take considerably
longer than fetching
the first page.
Improvement 1: Indexed order by
se!e"# *
$%om news
whe%e #op&" ' 1234
o%de% b( da#e des", &d des"
o$$se# 10
!&m&# 10;
%&ea"e $ndex on news ("op$%, da"e, $d)
A single index to support the whe%e and o%de% b(
clauses.
Improvement 1: Indexed order by
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'10)
Index *ond: (#op&" ' 0)
Improvement 1: Indexed order by
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'20)
Index *ond: (#op&" ' 0)
Improvement 1: Indexed order by
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'30)
Index *ond: (#op&" ' 0)
Improvement 1: Indexed order by
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'40)
Index *ond: (#op&" ' 0)
Improvement 1: Indexed order by
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'10000)
So%# Me#hod: ex"e&na# me&*e D$s): 1200)B
-> B&#map Heap S"an (a"#ua! %ows'10000)
Re"he") *ond: (#op&" ' 1234)
-> B&#map Index S"an (a"#ua! %ows'10000)
Index *ond: (#op&" ' 1234)
Improvement 1: Indexed order by
Fetching the first page is not affected by the
Base-Set size!
Fetching the next page
is also faster.
However, the database
might revert to the other
execution plan when
browsing to the end.
© 2013 by Markus Winand
It’s not just about performance
© 2015 by Markus Winand
Offsets Yield Unstable Results
© 2015 by Markus Winand
Offsets Yield Unstable Results
© 2015 by Markus Winand
Offsets Yield Unstable Results
© 2013 by Markus Winand
Why don’t we ask for
the next rows after...
© 2015 by Markus Winand
Asking for “Next After” in SQL
© 2015 by Markus Winand
Asking for “Next After” in SQL
© 2015 by Markus Winand
Asking for “Next After” in SQL
© 2015 by Markus Winand
Asking for “Next After” in SQL
© 2015 by Markus Winand
Asking for “Next After” in SQL
© 2015 by Markus Winand
Asking for “Next After” in SQL
SQL For “Next After” (Key-Set Pagination)
se!e"# *
$%om news
whe%e #op&" ' 1234
and (da"e, $d) < (?, ?)
o%de% b( da#e des", &d des"
!&m&# 10 Look Ma,
no offset!
Key-Set Pagination: Worst Case
Key-Set Pagination: Worst Case
L&m&# (a%"ua# &ows'10)
-> So%# (a%"ua# &ows'10)
So%# Me#hod: "op-N heapso&" Memo&(: 18)B
-> B&#map Heap S"an (&ows'10000)
Re"he") *ond: (#op&" ' 1234)
-> B&#map Index S"an (&ows'10000)
Index *ond: (#op&" ' 1234)
Key-Set Pagination: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'10)
So%# Me#hod: "op-N heapso&" Memo&(: 18)B
-> B&#map Heap S"an (a%"ua# &ows'9990)
Rows Remo+ed b( F$#"e&: 10 (new &n 9.2)
-> B&#map Index S"an (a%"ua# &ows'10000)
Index *ond: (#op&" ' 1234)
Key-Set Pagination: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'10)
So%# Me#hod: "op-N heapso&" Memo&(: 18)B
-> B&#map Heap S"an (a%"ua# &ows'9980)
Rows Remo+ed b( F$#"e&: 20 (new &n 9.2)
-> B&#map Index S"an (a%"ua# &ows'10000)
Index *ond: (#op&" ' 1234)
Key-Set Pagination: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'10)
So%# Me#hod: "op-N heapso&" Memo&(: 18)B
-> B&#map Heap S"an (a%"ua# &ows'9970)
Rows Remo+ed b( F$#"e&: 30 (new &n 9.2)
-> B&#map Index S"an (a%"ua# &ows'10000)
Index *ond: (#op&" ' 1234)
Key-Set Pagination: Worst Case
L&m&# (a"#ua! %ows'10)
-> So%# (a%"ua# &ows'10)
So%# Me#hod: "op-N heapso&" Memo&(: 18)B
-> B&#map Heap S"an (a%"ua# &ows'10)
Rows Remo+ed b( F$#"e&: 9990 (new &n 9.2)
-> B&#map Index S"an (a%"ua# &ows'10000)
Index *ond: (#op&" ' 1234)
Key-Set Pagination w/o Index for order by
Always needs to retrieve the full base set, but the
top-n sort buffer needs
to hold only 10 rows.
The response time remains
the same even when
browsing to the last page.
And the memory footprint
is very low!
Key-Set Pagination: Best Case
se!e"# *
$%om news
whe%e #op&" ' 1234
and (da#e, &d) < (?, ?)
o%de% b( da#e des", &d des"
!&m&# 10;
%&ea"e $ndex on news ("op$%, da"e, $d)
Key-Set Pagination: Best Case
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'10)
Index *ond: (#op&" ' 1234)
Key-Set Pagination: Best Case
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'10)
Index *ond: ((#op&" ' 1234)
AND (ROW(d#, &d) < ROW(‘...’, 23456)))
Key-Set Pagination: Best Case
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'10)
Index *ond: ((#op&" ' 1234)
AND (ROW(d#, &d) < ROW(‘...’, 34567)))
Key-Set Pagination: Best Case
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'10)
Index *ond: ((#op&" ' 1234)
AND (ROW(d#, &d) < ROW(‘...’, 45678)))
Key-Set Pagination: Best Case
L&m&# (a%"ua# &ows'10)
-> Index S"an Ba")wa%d (a%"ua# &ows'10)
Index *ond: ((#op&" ' 1234)
AND (ROW(d#, &d) < ROW(‘...’, 56789)))
Key-Set Pagination: Best Case
Successively browsing back doesn’t slow down.
Neither the size of the
base set(*) nor the fetched
page number affects the
response time.
(*) the index tree depth still affects the response time.
ComparisonOffsetKey-Set
Worst Case Best Case
© 2015 by Markus Winand
Too good to be true?
Key-Set Pagination has serious limitations:
‣You cannot directly navigate to arbitrary pages
‣because you need the values from the previous page
‣Bi-directional navigation is possible but tedious
‣you need to reverse the o%de% b( direction and RV comparison
‣Tooling...???
© 2015 by Markus Winand
Required Tooling for Key-Set Pagination
© 2015 by Markus Winand
Required Tooling for Key-Set Pagination
Proper Row-
Values Support.
Don’t use
OFFSET.NoSQL is
also
Also for
NoSQL
© 2015 by Markus Winand
Required Tooling for Key-Set Pagination
Proper Row-
Values Support.
Don’t use
OFFSET.
Offer
Infinite Scrolling.
Don’t think in
pages.
Ask the right
question.
OFFSET is EVIL
http://use-the-index-luke.com/no-offset
© 2015 by Markus Winand
About Markus Winand
Tuning developers for
high SQL performance
Training & co (one-man show):
winand.at
Geeky blog:
use-the-index-luke.com
Author of:
SQL Performance Explained

More Related Content

What's hot

Social media Dive training
Social media  Dive training Social media  Dive training
Social media Dive training Hind Al Nahedh
 
O captain! my captain! by walt whitman poetry foundation
O captain! my captain! by walt whitman   poetry foundationO captain! my captain! by walt whitman   poetry foundation
O captain! my captain! by walt whitman poetry foundationtapanma
 
Skytide by the Numbers
Skytide by the NumbersSkytide by the Numbers
Skytide by the NumbersPatrick Hurley
 
Medicos247 sales presentation
Medicos247   sales presentationMedicos247   sales presentation
Medicos247 sales presentationGustavo Cuervo
 
Electronic Marketing To Your Fan Base
Electronic Marketing To Your Fan BaseElectronic Marketing To Your Fan Base
Electronic Marketing To Your Fan BaseJeff Risley
 
Sass maps, my precious! 2.0
Sass maps, my precious! 2.0Sass maps, my precious! 2.0
Sass maps, my precious! 2.0Andréa Zambrana
 
I Pro Con Technology And Transformation Consultancy And Interim Resources
I Pro Con   Technology And Transformation Consultancy And Interim ResourcesI Pro Con   Technology And Transformation Consultancy And Interim Resources
I Pro Con Technology And Transformation Consultancy And Interim Resourcesleeswonnell
 
Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...
Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...
Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...Cendoo
 
Secretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviários
Secretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviáriosSecretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviários
Secretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviáriosJornal do Commercio
 

What's hot (13)

Social media Dive training
Social media  Dive training Social media  Dive training
Social media Dive training
 
O captain! my captain! by walt whitman poetry foundation
O captain! my captain! by walt whitman   poetry foundationO captain! my captain! by walt whitman   poetry foundation
O captain! my captain! by walt whitman poetry foundation
 
Skytide by the Numbers
Skytide by the NumbersSkytide by the Numbers
Skytide by the Numbers
 
เจ้าหน้าที่บริหารงานคอมพิวเตอร์
เจ้าหน้าที่บริหารงานคอมพิวเตอร์เจ้าหน้าที่บริหารงานคอมพิวเตอร์
เจ้าหน้าที่บริหารงานคอมพิวเตอร์
 
Medicos247 sales presentation
Medicos247   sales presentationMedicos247   sales presentation
Medicos247 sales presentation
 
Cocina para impostores
Cocina para impostoresCocina para impostores
Cocina para impostores
 
Electronic Marketing To Your Fan Base
Electronic Marketing To Your Fan BaseElectronic Marketing To Your Fan Base
Electronic Marketing To Your Fan Base
 
Sass maps, my precious! 2.0
Sass maps, my precious! 2.0Sass maps, my precious! 2.0
Sass maps, my precious! 2.0
 
Youkomlun
YoukomlunYoukomlun
Youkomlun
 
I Pro Con Technology And Transformation Consultancy And Interim Resources
I Pro Con   Technology And Transformation Consultancy And Interim ResourcesI Pro Con   Technology And Transformation Consultancy And Interim Resources
I Pro Con Technology And Transformation Consultancy And Interim Resources
 
Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...
Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...
Czym zabłysnę gdy przyjdzie konkurencja, i jak trzymać wydatki na obsługę Kli...
 
แนวข้อสอบคอมพิวเตอร์
แนวข้อสอบคอมพิวเตอร์แนวข้อสอบคอมพิวเตอร์
แนวข้อสอบคอมพิวเตอร์
 
Secretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviários
Secretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviáriosSecretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviários
Secretaria de Saúde de Pernambuco negou antecipação de vacina aos rodoviários
 

Viewers also liked

Pagination Done the Right Way
Pagination Done the Right WayPagination Done the Right Way
Pagination Done the Right WayMarkus Winand
 
SQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they workSQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they workMarkus Winand
 
SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202Markus Winand
 
Modern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesModern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesMarkus Winand
 
Row Pattern Matching in SQL:2016
Row Pattern Matching in SQL:2016Row Pattern Matching in SQL:2016
Row Pattern Matching in SQL:2016Markus Winand
 
Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"Markus Winand
 
Indexes: The neglected performance all rounder
Indexes: The neglected performance all rounderIndexes: The neglected performance all rounder
Indexes: The neglected performance all rounderMarkus Winand
 
10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were PossibleLukas Eder
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationAlexey Lesovsky
 

Viewers also liked (9)

Pagination Done the Right Way
Pagination Done the Right WayPagination Done the Right Way
Pagination Done the Right Way
 
SQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they workSQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they work
 
SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202
 
Modern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesModern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial Databases
 
Row Pattern Matching in SQL:2016
Row Pattern Matching in SQL:2016Row Pattern Matching in SQL:2016
Row Pattern Matching in SQL:2016
 
Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"
 
Indexes: The neglected performance all rounder
Indexes: The neglected performance all rounderIndexes: The neglected performance all rounder
Indexes: The neglected performance all rounder
 
10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
 

Similar to Backend to Frontend: When database optimization affects the full stack

Un petit guide de la domination du monde
Un petit guide de la domination du mondeUn petit guide de la domination du monde
Un petit guide de la domination du mondeGeoffrey Dorne
 
Overview Heylife
Overview HeylifeOverview Heylife
Overview Heyliferuimssousa
 
E-Primer Your Business Online
E-Primer Your Business OnlineE-Primer Your Business Online
E-Primer Your Business Onlineguestfc9d8a
 
Roberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanosRoberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanosRoberto Isaias
 
William Isaías-Derechos humanos
William Isaías-Derechos humanosWilliam Isaías-Derechos humanos
William Isaías-Derechos humanosWilliam Isaias
 
The Lean Startup - simplified
The Lean Startup - simplifiedThe Lean Startup - simplified
The Lean Startup - simplifiedStefano Bernardi
 
Interaction design
Interaction designInteraction design
Interaction designfeifei2011
 
Experience Mining and Dialogues with a Pattern Language for Creative Learning
Experience Mining and Dialogues with a Pattern Language for Creative LearningExperience Mining and Dialogues with a Pattern Language for Creative Learning
Experience Mining and Dialogues with a Pattern Language for Creative LearningTakashi Iba
 
Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...
Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...
Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...Nonprofit Finance Fund
 
Understanding variations of entanglement and complexity: A way to influence e...
Understanding variations of entanglement and complexity: A way to influence e...Understanding variations of entanglement and complexity: A way to influence e...
Understanding variations of entanglement and complexity: A way to influence e...RSD7 Symposium
 
Al Fazl International Weekly26 June 2015
Al Fazl International  Weekly26 June 2015Al Fazl International  Weekly26 June 2015
Al Fazl International Weekly26 June 2015muzaffertahir9
 
Frontend First Design & Development
Frontend First Design & DevelopmentFrontend First Design & Development
Frontend First Design & DevelopmentAdam Nemeth
 
Magazine Anim Art
Magazine Anim ArtMagazine Anim Art
Magazine Anim ArtStudent
 

Similar to Backend to Frontend: When database optimization affects the full stack (20)

Csharp intsight[1]
Csharp intsight[1]Csharp intsight[1]
Csharp intsight[1]
 
Csharp intsight
Csharp intsightCsharp intsight
Csharp intsight
 
Composicion danza2
Composicion danza2Composicion danza2
Composicion danza2
 
Un petit guide de la domination du monde
Un petit guide de la domination du mondeUn petit guide de la domination du monde
Un petit guide de la domination du monde
 
Pimp your data
Pimp your dataPimp your data
Pimp your data
 
Overview Heylife
Overview HeylifeOverview Heylife
Overview Heylife
 
E-Primer Your Business Online
E-Primer Your Business OnlineE-Primer Your Business Online
E-Primer Your Business Online
 
Roberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanosRoberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanos
 
William Isaías-Derechos humanos
William Isaías-Derechos humanosWilliam Isaías-Derechos humanos
William Isaías-Derechos humanos
 
All about Apache ACE
All about Apache ACEAll about Apache ACE
All about Apache ACE
 
The Lean Startup - simplified
The Lean Startup - simplifiedThe Lean Startup - simplified
The Lean Startup - simplified
 
Curriculo de primer año
Curriculo de primer añoCurriculo de primer año
Curriculo de primer año
 
Interaction design
Interaction designInteraction design
Interaction design
 
Experience Mining and Dialogues with a Pattern Language for Creative Learning
Experience Mining and Dialogues with a Pattern Language for Creative LearningExperience Mining and Dialogues with a Pattern Language for Creative Learning
Experience Mining and Dialogues with a Pattern Language for Creative Learning
 
Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...
Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...
Pay for Success Projects and Social Impact Bonds: Structuring Considerations ...
 
Understanding variations of entanglement and complexity: A way to influence e...
Understanding variations of entanglement and complexity: A way to influence e...Understanding variations of entanglement and complexity: A way to influence e...
Understanding variations of entanglement and complexity: A way to influence e...
 
UX 101 - TajRiba | UX Month Nairobi
UX 101 - TajRiba | UX Month NairobiUX 101 - TajRiba | UX Month Nairobi
UX 101 - TajRiba | UX Month Nairobi
 
Al Fazl International Weekly26 June 2015
Al Fazl International  Weekly26 June 2015Al Fazl International  Weekly26 June 2015
Al Fazl International Weekly26 June 2015
 
Frontend First Design & Development
Frontend First Design & DevelopmentFrontend First Design & Development
Frontend First Design & Development
 
Magazine Anim Art
Magazine Anim ArtMagazine Anim Art
Magazine Anim Art
 

Recently uploaded

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Recently uploaded (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Backend to Frontend: When database optimization affects the full stack

  • 1. © 2015 by Markus Winand iStockPhoto/Mitshu From Backend to Frontend When database optimization affects the full stack @MarkusWinand @SQLPerfTips @ModernSQL
  • 2. © 2015 by Markus Winand Full Stack, Really?
  • 3. © 2015 by Markus Winand Full Stack, Really?
  • 4. © 2015 by Markus Winand What Users Want are Used to
  • 5. © 2015 by Markus Winand What Users Want are Used to Let’s click here
  • 6. © 2015 by Markus Winand User Clicks on Page 2 Gimme Page 2! Gimme Rows 11 to 20
  • 7. SQL for “Gimme Rows 11 to 20” se!e"# * $%om news whe%e #op&" ' 1234 o%de% b( da#e des", &d des" o!!se" 10 #$m$" 10
  • 8. Inside the Database: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'20) So%# Me#hod: "op-N heapso&" Memo&(: 19)B -> B&#map Heap S"an (a"#ua! %ows'10000) Re"he") *ond: (#op&" ' 1234) -> B&#map Index S"an (a"#ua! %ows'10000) Index *ond: (#op&" ' 1234)
  • 9. Inside the Database: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'30) So%# Me#hod: "op-N heapso&" Memo&(: 20)B -> B&#map Heap S"an (a"#ua! %ows'10000) Re"he") *ond: (#op&" ' 1234) -> B&#map Index S"an (a"#ua! %ows'10000) Index *ond: (#op&" ' 1234)
  • 10. Inside the Database: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'40) So%# Me#hod: "op-N heapso&" Memo&(: 22)B -> B&#map Heap S"an (a"#ua! %ows'10000) Re"he") *ond: (#op&" ' 1234) -> B&#map Index S"an (a"#ua! %ows'10000) Index *ond: (#op&" ' 1234)
  • 11. Inside the Database: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'10000) So%# Me#hod: ex"e&na# me&*e D$s): 1200)B -> B&#map Heap S"an (a"#ua! %ows'10000) Re"he") *ond: (#op&" ' 1234) -> B&#map Index S"an (a"#ua! %ows'10000) Index *ond: (#op&" ' 1234)
  • 12. Inside the Database: Worst Case Speed depends on the number of matched rows and the page fetched. Fetching the last page can take considerably longer than fetching the first page.
  • 13. Improvement 1: Indexed order by se!e"# * $%om news whe%e #op&" ' 1234 o%de% b( da#e des", &d des" o$$se# 10 !&m&# 10; %&ea"e $ndex on news ("op$%, da"e, $d) A single index to support the whe%e and o%de% b( clauses.
  • 14. Improvement 1: Indexed order by L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'10) Index *ond: (#op&" ' 0)
  • 15. Improvement 1: Indexed order by L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'20) Index *ond: (#op&" ' 0)
  • 16. Improvement 1: Indexed order by L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'30) Index *ond: (#op&" ' 0)
  • 17. Improvement 1: Indexed order by L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'40) Index *ond: (#op&" ' 0)
  • 18. Improvement 1: Indexed order by L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'10000) So%# Me#hod: ex"e&na# me&*e D$s): 1200)B -> B&#map Heap S"an (a"#ua! %ows'10000) Re"he") *ond: (#op&" ' 1234) -> B&#map Index S"an (a"#ua! %ows'10000) Index *ond: (#op&" ' 1234)
  • 19. Improvement 1: Indexed order by Fetching the first page is not affected by the Base-Set size! Fetching the next page is also faster. However, the database might revert to the other execution plan when browsing to the end.
  • 20. © 2013 by Markus Winand It’s not just about performance
  • 21. © 2015 by Markus Winand Offsets Yield Unstable Results
  • 22. © 2015 by Markus Winand Offsets Yield Unstable Results
  • 23. © 2015 by Markus Winand Offsets Yield Unstable Results
  • 24. © 2013 by Markus Winand Why don’t we ask for the next rows after...
  • 25. © 2015 by Markus Winand Asking for “Next After” in SQL
  • 26. © 2015 by Markus Winand Asking for “Next After” in SQL
  • 27. © 2015 by Markus Winand Asking for “Next After” in SQL
  • 28. © 2015 by Markus Winand Asking for “Next After” in SQL
  • 29. © 2015 by Markus Winand Asking for “Next After” in SQL
  • 30. © 2015 by Markus Winand Asking for “Next After” in SQL
  • 31. SQL For “Next After” (Key-Set Pagination) se!e"# * $%om news whe%e #op&" ' 1234 and (da"e, $d) < (?, ?) o%de% b( da#e des", &d des" !&m&# 10 Look Ma, no offset!
  • 33. Key-Set Pagination: Worst Case L&m&# (a%"ua# &ows'10) -> So%# (a%"ua# &ows'10) So%# Me#hod: "op-N heapso&" Memo&(: 18)B -> B&#map Heap S"an (&ows'10000) Re"he") *ond: (#op&" ' 1234) -> B&#map Index S"an (&ows'10000) Index *ond: (#op&" ' 1234)
  • 34. Key-Set Pagination: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'10) So%# Me#hod: "op-N heapso&" Memo&(: 18)B -> B&#map Heap S"an (a%"ua# &ows'9990) Rows Remo+ed b( F$#"e&: 10 (new &n 9.2) -> B&#map Index S"an (a%"ua# &ows'10000) Index *ond: (#op&" ' 1234)
  • 35. Key-Set Pagination: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'10) So%# Me#hod: "op-N heapso&" Memo&(: 18)B -> B&#map Heap S"an (a%"ua# &ows'9980) Rows Remo+ed b( F$#"e&: 20 (new &n 9.2) -> B&#map Index S"an (a%"ua# &ows'10000) Index *ond: (#op&" ' 1234)
  • 36. Key-Set Pagination: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'10) So%# Me#hod: "op-N heapso&" Memo&(: 18)B -> B&#map Heap S"an (a%"ua# &ows'9970) Rows Remo+ed b( F$#"e&: 30 (new &n 9.2) -> B&#map Index S"an (a%"ua# &ows'10000) Index *ond: (#op&" ' 1234)
  • 37. Key-Set Pagination: Worst Case L&m&# (a"#ua! %ows'10) -> So%# (a%"ua# &ows'10) So%# Me#hod: "op-N heapso&" Memo&(: 18)B -> B&#map Heap S"an (a%"ua# &ows'10) Rows Remo+ed b( F$#"e&: 9990 (new &n 9.2) -> B&#map Index S"an (a%"ua# &ows'10000) Index *ond: (#op&" ' 1234)
  • 38. Key-Set Pagination w/o Index for order by Always needs to retrieve the full base set, but the top-n sort buffer needs to hold only 10 rows. The response time remains the same even when browsing to the last page. And the memory footprint is very low!
  • 39. Key-Set Pagination: Best Case se!e"# * $%om news whe%e #op&" ' 1234 and (da#e, &d) < (?, ?) o%de% b( da#e des", &d des" !&m&# 10; %&ea"e $ndex on news ("op$%, da"e, $d)
  • 40. Key-Set Pagination: Best Case L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'10) Index *ond: (#op&" ' 1234)
  • 41. Key-Set Pagination: Best Case L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'10) Index *ond: ((#op&" ' 1234) AND (ROW(d#, &d) < ROW(‘...’, 23456)))
  • 42. Key-Set Pagination: Best Case L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'10) Index *ond: ((#op&" ' 1234) AND (ROW(d#, &d) < ROW(‘...’, 34567)))
  • 43. Key-Set Pagination: Best Case L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'10) Index *ond: ((#op&" ' 1234) AND (ROW(d#, &d) < ROW(‘...’, 45678)))
  • 44. Key-Set Pagination: Best Case L&m&# (a%"ua# &ows'10) -> Index S"an Ba")wa%d (a%"ua# &ows'10) Index *ond: ((#op&" ' 1234) AND (ROW(d#, &d) < ROW(‘...’, 56789)))
  • 45. Key-Set Pagination: Best Case Successively browsing back doesn’t slow down. Neither the size of the base set(*) nor the fetched page number affects the response time. (*) the index tree depth still affects the response time.
  • 47. © 2015 by Markus Winand Too good to be true? Key-Set Pagination has serious limitations: ‣You cannot directly navigate to arbitrary pages ‣because you need the values from the previous page ‣Bi-directional navigation is possible but tedious ‣you need to reverse the o%de% b( direction and RV comparison ‣Tooling...???
  • 48. © 2015 by Markus Winand Required Tooling for Key-Set Pagination
  • 49. © 2015 by Markus Winand Required Tooling for Key-Set Pagination Proper Row- Values Support. Don’t use OFFSET.NoSQL is also Also for NoSQL
  • 50. © 2015 by Markus Winand Required Tooling for Key-Set Pagination Proper Row- Values Support. Don’t use OFFSET. Offer Infinite Scrolling. Don’t think in pages. Ask the right question.
  • 52. © 2015 by Markus Winand About Markus Winand Tuning developers for high SQL performance Training & co (one-man show): winand.at Geeky blog: use-the-index-luke.com Author of: SQL Performance Explained