SlideShare una empresa de Scribd logo
1 de 19
Practical MySQL
    for web applications




       Domas Mituzas
  MySQL @ Sun Microsystems
    Wikimedia Foudnation
This is different world


• Not OLAP, Not OLTP
• OLWP. On line web processing
• OLP?
Web

• Need data now. Right now. Instantly.
• High scale, huge churns
• Repetitive reads
• Click, click, click!
MySQL

• Great network bit-bucket
• Lightweight and fast
• Likes reads a lot
 • Data clustering
 • Covering indexes
Data
• Mostly variable length
• Web users are lazy to type
• Tends to be short:
• Example of varchar(255) web supplied data
     length distribution:

800,000
600,000
400,000
200,000
      0
          <5   >5   >10   >15   >20   >25   >30   >35   >40   >45
Access
• Writes are small and rare
 • Inserts mostly
 • Text changes uncommon
• Reads are bigger and everywhere
 • Ordered data
 • Range scans
 • Pages
Views

• User
• Tag
• Time
• Related
Ordering
• Filesorts are bad.
 • TEXT/BLOB go to filesystem immediately
 • ORDER BY a LIMIT x will still scan whole
    range, 1000x costs
 • Filesort alone is more than 2x expensive
    operation, than just fetching rows
 • In Web, order is known and rarely changed
Indexing


• Provide index for every view pattern
• Composite indexes are a must
InnoDB
• Data is clustered by PK
 • Composite PKs group logical sets
• PK value is in secondary keys
 • Adding PK to index definition - cheap
 • Reading PK+SK values doesn’t read PK
    (table) itself - very very cheap
• Every read is in index-order
Covering index

• A (partial) copy of table for different access
  pattern/view
• Especially useful if table doesn’t fit in
  memory
• 100x less seeks for cold data
• Probably no need with SSDs :-)
JOIN orders
• 5.1 fixes this
• In 5.0, order on joined tables caused
  filesorts, even if indexes exist
• Might be faster fetching single row as
  separate SELECT, instead of joining to it
• May use FORCE INDEX and rely on implicit
  order, instead of ORDER BY. <-- DIRTY!
• Can use app-defined ordering columns in
  keys
Query cache
• Does not work for big apps (transactions,
  lots of changes)
• Does great job for small ones
 • Needs uniform queries
 • Less dynamic queries - better hitrate
• Primary tweak on shared hosting
Counts

• MyISAM count(*) works, sometimes
• Scanning rows - inefficient
• Maintaining counts is easy and cheap
 • Aggregate data is easier to keep hot
 • INSERT ... ON DUPLICATE KEY ...
BLOBs
• Keep in separate tables
• Keep outside search query logic, display only
 • Cheaper metadata updates, especially
    InnoDB
  • Less data to read in big scans, orders,
    grouping, etc
  • Can always revisit blobs in second query
  • Easier to move out afterwards
Paging


• Bad: OFFSET .. LIMIT ..
• Good: WHERE id>xxx LIMIT ..
 • Who cares about 15th page?
Character sets

• Lucky if latin1 (or other 8bit charset) is
  enough
• Even luckier if binary
• Have to be very careful with utf8 and friends
 • More expensive filesorts!
Connections
• Persistent - bad
 • Connect is cheap, connection is not
 • Applications may spend less than 20% time
    in db
 • Prepare application, do all db work,
    disconnect, continue with other work
 • ___QQQ___ instead of _Q_Q_Q_Q_
Locking
• SELECT ... FOR UPDATE - necessary evil
• Good: Hot potato transactions
• Bad: waiting for anything
 • Especially streaming of files, etc
 • Use output buffers!
   • ob_flush() after COMMIT, not before
• Delay and split big changes

Más contenido relacionado

La actualidad más candente

What SQL should actually be...
What SQL should actually be...What SQL should actually be...
What SQL should actually be...
Open Academy
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and Scaling
Gerald Villorente
 
小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage
小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage
小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage
moai kids
 
Database , 15 Object DBMS
Database , 15 Object DBMSDatabase , 15 Object DBMS
Database , 15 Object DBMS
Ali Usman
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
Tuyển Đoàn
 
Database ,16 P2P
Database ,16 P2P Database ,16 P2P
Database ,16 P2P
Ali Usman
 
What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010
jbellis
 

La actualidad más candente (19)

Graphs, parallelism and business cases
Graphs, parallelism and business casesGraphs, parallelism and business cases
Graphs, parallelism and business cases
 
Graphs, parallelism and business cases
 Graphs, parallelism and business cases Graphs, parallelism and business cases
Graphs, parallelism and business cases
 
What SQL should actually be...
What SQL should actually be...What SQL should actually be...
What SQL should actually be...
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and Scaling
 
小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage
小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage
小咄:BlazeDS+AMF Client+MySQLで実現するKey-Value Storage
 
Ajax
AjaxAjax
Ajax
 
Database , 15 Object DBMS
Database , 15 Object DBMSDatabase , 15 Object DBMS
Database , 15 Object DBMS
 
Learn how zheap works
 Learn how zheap works Learn how zheap works
Learn how zheap works
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
 
Database ,16 P2P
Database ,16 P2P Database ,16 P2P
Database ,16 P2P
 
Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)
 
What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010What every developer should know about database scalability, PyCon 2010
What every developer should know about database scalability, PyCon 2010
 
COUNTWORDSFREE - WORD COUNTER
COUNTWORDSFREE - WORD COUNTERCOUNTWORDSFREE - WORD COUNTER
COUNTWORDSFREE - WORD COUNTER
 
Web Service and Mobile Integrated Day II
Web Service and Mobile Integrated Day IIWeb Service and Mobile Integrated Day II
Web Service and Mobile Integrated Day II
 
Evan Ellis "Tumblr. Massively Sharded MySQL"
Evan Ellis "Tumblr. Massively Sharded MySQL"Evan Ellis "Tumblr. Massively Sharded MySQL"
Evan Ellis "Tumblr. Massively Sharded MySQL"
 
No SQL and MongoDB - Hyderabad Scalability Meetup
No SQL and MongoDB - Hyderabad Scalability MeetupNo SQL and MongoDB - Hyderabad Scalability Meetup
No SQL and MongoDB - Hyderabad Scalability Meetup
 
Guide of speeding up WordPress Website
Guide of speeding up WordPress WebsiteGuide of speeding up WordPress Website
Guide of speeding up WordPress Website
 
Quixote
QuixoteQuixote
Quixote
 
Web Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day IWeb Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day I
 

Destacado

Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...
Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...
Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...
Indus Khaitan
 
Open Source Business Intelligence Overview
Open Source Business Intelligence OverviewOpen Source Business Intelligence Overview
Open Source Business Intelligence Overview
Alex Meadows
 

Destacado (17)

Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...
Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...
Creating Interactive Olap Applications With My Sql Enterprise And Mondrian Pr...
 
Pentaho Bi Server Pivot Olap
Pentaho Bi Server Pivot OlapPentaho Bi Server Pivot Olap
Pentaho Bi Server Pivot Olap
 
Geospatial Business Intelligence made easy with GeoMondrian & SOLAPLayers
Geospatial Business Intelligence made easy with GeoMondrian & SOLAPLayersGeospatial Business Intelligence made easy with GeoMondrian & SOLAPLayers
Geospatial Business Intelligence made easy with GeoMondrian & SOLAPLayers
 
Mondrian update (Pentaho community meetup 2012, Amsterdam)
Mondrian update (Pentaho community meetup 2012, Amsterdam)Mondrian update (Pentaho community meetup 2012, Amsterdam)
Mondrian update (Pentaho community meetup 2012, Amsterdam)
 
Mondrian and OLAP Overview
Mondrian and OLAP OverviewMondrian and OLAP Overview
Mondrian and OLAP Overview
 
Performance optimisations PHP meetup Rotterdam
Performance optimisations PHP meetup RotterdamPerformance optimisations PHP meetup Rotterdam
Performance optimisations PHP meetup Rotterdam
 
Big Data MDX with Mondrian and Apache Kylin
Big Data MDX with Mondrian and Apache KylinBig Data MDX with Mondrian and Apache Kylin
Big Data MDX with Mondrian and Apache Kylin
 
Mondrian - Geo Mondrian
Mondrian - Geo MondrianMondrian - Geo Mondrian
Mondrian - Geo Mondrian
 
eazyBI Overview - Embedding Mondrian in other applications
eazyBI Overview - Embedding Mondrian in other applicationseazyBI Overview - Embedding Mondrian in other applications
eazyBI Overview - Embedding Mondrian in other applications
 
Data Warehouses and Multi-Dimensional Data Analysis
Data Warehouses and Multi-Dimensional Data AnalysisData Warehouses and Multi-Dimensional Data Analysis
Data Warehouses and Multi-Dimensional Data Analysis
 
mondrian-olap JRuby library
mondrian-olap JRuby librarymondrian-olap JRuby library
mondrian-olap JRuby library
 
Optiq: A dynamic data management framework
Optiq: A dynamic data management frameworkOptiq: A dynamic data management framework
Optiq: A dynamic data management framework
 
Introduction To Pentaho Analysis
Introduction To Pentaho AnalysisIntroduction To Pentaho Analysis
Introduction To Pentaho Analysis
 
Open Source Business Intelligence Overview
Open Source Business Intelligence OverviewOpen Source Business Intelligence Overview
Open Source Business Intelligence Overview
 
Pentaho
PentahoPentaho
Pentaho
 
Cost-based query optimization in Apache Hive
Cost-based query optimization in Apache HiveCost-based query optimization in Apache Hive
Cost-based query optimization in Apache Hive
 
Metadata in Business Intelligence
Metadata in Business IntelligenceMetadata in Business Intelligence
Metadata in Business Intelligence
 

Similar a Practical MySQL

Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009
Andrei Gheorghe
 
[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice
javablend
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
marvin herrera
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
Don Demcsak
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
FromDual GmbH
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
Paul Pajo
 
My S Q L Replication Getting The Most From Slaves
My S Q L  Replication  Getting  The  Most  From  SlavesMy S Q L  Replication  Getting  The  Most  From  Slaves
My S Q L Replication Getting The Most From Slaves
PerconaPerformance
 

Similar a Practical MySQL (20)

Advanced Deployment
Advanced DeploymentAdvanced Deployment
Advanced Deployment
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009Scalarea Aplicatiilor Web - 2009
Scalarea Aplicatiilor Web - 2009
 
[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice[Roblek] Distributed computing in practice
[Roblek] Distributed computing in practice
 
No C-QL (Or how I learned to stop worrying, and love eventual consistency) (N...
No C-QL (Or how I learned to stop worrying, and love eventual consistency) (N...No C-QL (Or how I learned to stop worrying, and love eventual consistency) (N...
No C-QL (Or how I learned to stop worrying, and love eventual consistency) (N...
 
Extending The My Sql Data Landscape
Extending The My Sql Data LandscapeExtending The My Sql Data Landscape
Extending The My Sql Data Landscape
 
Http Status Report
Http Status ReportHttp Status Report
Http Status Report
 
Кирилл Шутемов aka “kas” - О Transparent Hugepages и Huge zero page
Кирилл Шутемов aka “kas” - О Transparent Hugepages и Huge zero pageКирилл Шутемов aka “kas” - О Transparent Hugepages и Huge zero page
Кирилл Шутемов aka “kas” - О Transparent Hugepages и Huge zero page
 
MongoDB Aggregation Performance
MongoDB Aggregation PerformanceMongoDB Aggregation Performance
MongoDB Aggregation Performance
 
Building a Database for the End of the World
Building a Database for the End of the WorldBuilding a Database for the End of the World
Building a Database for the End of the World
 
Qure Tech Presentation
Qure Tech PresentationQure Tech Presentation
Qure Tech Presentation
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
 
Shootout at the PAAS Corral
Shootout at the PAAS CorralShootout at the PAAS Corral
Shootout at the PAAS Corral
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
 
Practical Intro Merb
Practical Intro MerbPractical Intro Merb
Practical Intro Merb
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
My S Q L Replication Getting The Most From Slaves
My S Q L  Replication  Getting  The  Most  From  SlavesMy S Q L  Replication  Getting  The  Most  From  Slaves
My S Q L Replication Getting The Most From Slaves
 
CASSANDRA MEETUP - Choosing the right cloud instances for success
CASSANDRA MEETUP - Choosing the right cloud instances for successCASSANDRA MEETUP - Choosing the right cloud instances for success
CASSANDRA MEETUP - Choosing the right cloud instances for success
 

Más de Indus Khaitan

Bitzer Mobile TiECON 2013 Pitch Indus Khaitan
Bitzer Mobile TiECON 2013 Pitch Indus KhaitanBitzer Mobile TiECON 2013 Pitch Indus Khaitan
Bitzer Mobile TiECON 2013 Pitch Indus Khaitan
Indus Khaitan
 
NSDC at NASSCOM Product Conclave 2010
NSDC at NASSCOM Product Conclave 2010NSDC at NASSCOM Product Conclave 2010
NSDC at NASSCOM Product Conclave 2010
Indus Khaitan
 
NSEF India - Why become a social entrepreneur now
NSEF India - Why become a social entrepreneur nowNSEF India - Why become a social entrepreneur now
NSEF India - Why become a social entrepreneur now
Indus Khaitan
 
Building Winning Teams - Jain International Trade Organization Bangalore 06_J...
Building Winning Teams - Jain International Trade Organization Bangalore 06_J...Building Winning Teams - Jain International Trade Organization Bangalore 06_J...
Building Winning Teams - Jain International Trade Organization Bangalore 06_J...
Indus Khaitan
 

Más de Indus Khaitan (13)

Product marketing in B2B SaaS Startup Indus Khaitan 2018
Product marketing in B2B SaaS Startup Indus Khaitan 2018Product marketing in B2B SaaS Startup Indus Khaitan 2018
Product marketing in B2B SaaS Startup Indus Khaitan 2018
 
Bringing Contracts to Life | Keynote session at IACCM Dublin Ireland, May 2015
Bringing Contracts to Life | Keynote session at IACCM Dublin Ireland, May 2015Bringing Contracts to Life | Keynote session at IACCM Dublin Ireland, May 2015
Bringing Contracts to Life | Keynote session at IACCM Dublin Ireland, May 2015
 
Oracle OpenWorld | CON9707 Enterprise Mobile Security Architecture beyond the...
Oracle OpenWorld | CON9707 Enterprise Mobile Security Architecture beyond the...Oracle OpenWorld | CON9707 Enterprise Mobile Security Architecture beyond the...
Oracle OpenWorld | CON9707 Enterprise Mobile Security Architecture beyond the...
 
Oracle OpenWorld 2015 | CON9456 Mobile Security in the Cloud
Oracle OpenWorld 2015 | CON9456 Mobile Security in the CloudOracle OpenWorld 2015 | CON9456 Mobile Security in the Cloud
Oracle OpenWorld 2015 | CON9456 Mobile Security in the Cloud
 
Lets talk about decision making - UC Berkeley
Lets talk about decision making - UC BerkeleyLets talk about decision making - UC Berkeley
Lets talk about decision making - UC Berkeley
 
Bitzer Mobile TiECON 2013 Pitch Indus Khaitan
Bitzer Mobile TiECON 2013 Pitch Indus KhaitanBitzer Mobile TiECON 2013 Pitch Indus Khaitan
Bitzer Mobile TiECON 2013 Pitch Indus Khaitan
 
Mobile Security
Mobile SecurityMobile Security
Mobile Security
 
NSDC at NASSCOM Product Conclave 2010
NSDC at NASSCOM Product Conclave 2010NSDC at NASSCOM Product Conclave 2010
NSDC at NASSCOM Product Conclave 2010
 
NSEF India - Why become a social entrepreneur now
NSEF India - Why become a social entrepreneur nowNSEF India - Why become a social entrepreneur now
NSEF India - Why become a social entrepreneur now
 
Building Winning Teams - Jain International Trade Organization Bangalore 06_J...
Building Winning Teams - Jain International Trade Organization Bangalore 06_J...Building Winning Teams - Jain International Trade Organization Bangalore 06_J...
Building Winning Teams - Jain International Trade Organization Bangalore 06_J...
 
Disha 2010 Presentation on Entrepreneurship Jan'10 -- Indus Khaitan
Disha 2010 Presentation on Entrepreneurship Jan'10 -- Indus Khaitan Disha 2010 Presentation on Entrepreneurship Jan'10 -- Indus Khaitan
Disha 2010 Presentation on Entrepreneurship Jan'10 -- Indus Khaitan
 
Ford Motor Company 1902 Indus Khaitan
Ford Motor Company 1902 Indus KhaitanFord Motor Company 1902 Indus Khaitan
Ford Motor Company 1902 Indus Khaitan
 
5 Bare Minimum Things A Web Startup CTO Must Worry About
5 Bare Minimum Things A Web Startup CTO Must Worry About5 Bare Minimum Things A Web Startup CTO Must Worry About
5 Bare Minimum Things A Web Startup CTO Must Worry About
 

Último

Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 

Último (20)

Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 

Practical MySQL

  • 1. Practical MySQL for web applications Domas Mituzas MySQL @ Sun Microsystems Wikimedia Foudnation
  • 2. This is different world • Not OLAP, Not OLTP • OLWP. On line web processing • OLP?
  • 3. Web • Need data now. Right now. Instantly. • High scale, huge churns • Repetitive reads • Click, click, click!
  • 4. MySQL • Great network bit-bucket • Lightweight and fast • Likes reads a lot • Data clustering • Covering indexes
  • 5. Data • Mostly variable length • Web users are lazy to type • Tends to be short: • Example of varchar(255) web supplied data length distribution: 800,000 600,000 400,000 200,000 0 <5 >5 >10 >15 >20 >25 >30 >35 >40 >45
  • 6. Access • Writes are small and rare • Inserts mostly • Text changes uncommon • Reads are bigger and everywhere • Ordered data • Range scans • Pages
  • 7. Views • User • Tag • Time • Related
  • 8. Ordering • Filesorts are bad. • TEXT/BLOB go to filesystem immediately • ORDER BY a LIMIT x will still scan whole range, 1000x costs • Filesort alone is more than 2x expensive operation, than just fetching rows • In Web, order is known and rarely changed
  • 9. Indexing • Provide index for every view pattern • Composite indexes are a must
  • 10. InnoDB • Data is clustered by PK • Composite PKs group logical sets • PK value is in secondary keys • Adding PK to index definition - cheap • Reading PK+SK values doesn’t read PK (table) itself - very very cheap • Every read is in index-order
  • 11. Covering index • A (partial) copy of table for different access pattern/view • Especially useful if table doesn’t fit in memory • 100x less seeks for cold data • Probably no need with SSDs :-)
  • 12. JOIN orders • 5.1 fixes this • In 5.0, order on joined tables caused filesorts, even if indexes exist • Might be faster fetching single row as separate SELECT, instead of joining to it • May use FORCE INDEX and rely on implicit order, instead of ORDER BY. <-- DIRTY! • Can use app-defined ordering columns in keys
  • 13. Query cache • Does not work for big apps (transactions, lots of changes) • Does great job for small ones • Needs uniform queries • Less dynamic queries - better hitrate • Primary tweak on shared hosting
  • 14. Counts • MyISAM count(*) works, sometimes • Scanning rows - inefficient • Maintaining counts is easy and cheap • Aggregate data is easier to keep hot • INSERT ... ON DUPLICATE KEY ...
  • 15. BLOBs • Keep in separate tables • Keep outside search query logic, display only • Cheaper metadata updates, especially InnoDB • Less data to read in big scans, orders, grouping, etc • Can always revisit blobs in second query • Easier to move out afterwards
  • 16. Paging • Bad: OFFSET .. LIMIT .. • Good: WHERE id>xxx LIMIT .. • Who cares about 15th page?
  • 17. Character sets • Lucky if latin1 (or other 8bit charset) is enough • Even luckier if binary • Have to be very careful with utf8 and friends • More expensive filesorts!
  • 18. Connections • Persistent - bad • Connect is cheap, connection is not • Applications may spend less than 20% time in db • Prepare application, do all db work, disconnect, continue with other work • ___QQQ___ instead of _Q_Q_Q_Q_
  • 19. Locking • SELECT ... FOR UPDATE - necessary evil • Good: Hot potato transactions • Bad: waiting for anything • Especially streaming of files, etc • Use output buffers! • ob_flush() after COMMIT, not before • Delay and split big changes

Notas del editor