SlideShare a Scribd company logo
1 of 66
Download to read offline
Other MySQL-verses
Our journey to Aurora
Our journey to Aurora
Our journey to Aurora
Our journey to Aurora
Our journey to Aurora
Our journey to Aurora
Our journey to Aurora
Our journey to Aurora
Indexes
Indexes
Primary key index
Secondary key index
Clustered key index
Hash index*
Primary key index (btree)
Primary key index (btree)
Rows are attached to the
Leaf node as part of same
data-structure
Secondary key index (btree)
Secondary key index (btree)
Leaf node have pointers to
PK of rows
Clustered Key
In absence of PK/uniq key,
MySQL creates a hidden
clustered key.
Index use
● Left prefix rule
○ Name, ID, country
■ Select … where ID = 3 and country = us
■ Select … where ID = 3
■ Select … where country = us
■ Select … where Name = ‘blah’ and country = us
■ Select … where Name = ‘blah’ and ID = 4
Index use
● Left prefix rule
○ Name, ID, country
■ Select … where ID = 3 and country = us
■ Select … where ID = 3
■ Select … where country = us
■ Select … where Name = ‘blah’ and country = us
■ Select … where Name = ‘blah’ and ID = 4
● Duplicate indexes
○ Name, country
○ Name, country, zip
○ Name, zip
Index use
● Selectivity rule
○ Select … where gender = male
○ Say 2ndary index on gender (cardinality is say 2 = male/female)
○ Say 70 % of rows are male
Index use
● Selectivity rule
○ Select … where gender = male
○ Say 2ndary index on gender (cardinality is say 2 = male/female)
○ Say 70 % of rows are male
○ => in the btree, 70% of rows will be under male node.
Index use
● Selectivity rule
○ Select … where gender = male
○ Say 2ndary index on gender (cardinality is say 2 = male/female)
○ Say 70 % of rows are male
○ => in the btree, 70% of rows will be under male node.
○ => since 2ndary index, the node has pointers to 70% of rows
Index use
● Selectivity rule
○ Select … where gender = male
○ Say 2ndary index on gender (cardinality is say 2 = male/female)
○ Say 70 % of rows are male
○ => in the btree, 70% of rows will be under male node.
○ => since 2ndary index, the node has pointers to 70% of rows
○ What does MySQL Do ?
Index use
● Selectivity rule
○ Select … where gender = male
○ Say 2ndary index on gender (cardinality is say 2 = male/female)
○ Say 70 % of rows are male
○ => in the btree, 70% of rows will be under male node.
○ => since 2ndary index, the node has pointers to 70% of rows
○ What does MySQL Do ?
■ Does it read index , traverse it and then go to disk for the 70% of data ?
Index use
● Selectivity rule
○ Select … where gender = male
○ Say 2ndary index on gender (cardinality is say 2 = male/female)
○ Say 70 % of rows are male
○ => in the btree, 70% of rows will be under male node.
○ => since 2ndary index, the node has pointers to 70% of rows
○ What does MySQL Do ?
■ Does it read index , traverse it and then go to disk for the 70% of data ?
■ It does not , it bypasses index and goes to disk directly
Index use
● Selectivity rule
○ Select … where gender = male
○ Say 2ndary index on gender (cardinality is say 2 = male/female)
○ Say 70 % of rows are male
○ => in the btree, 70% of rows will be under male node.
○ => since 2ndary index, the node has pointers to 70% of rows
○ What does MySQL Do ?
■ Does it read index , traverse it and then go to disk for the 70% of data ?
■ It does not , it bypasses index and goes to disk directly
■ It does a table scan ! (more effective).
● Explain might indicate use of index but in practice it does not!
Storage engines
Innodb *
MyIsam
Memory (can create hash index)
Federated
NDB
Storage engines
Innodb * (enable adaptive hash idx)
MyIsam
Memory (can create hash index)
Federated
NDB
Lock wait timeout exceeded error
Deadlocks
Lock errors
1. Lock wait timeout exceeded:
a. set global innodb_lock_wait_timeout = x; <default is 150 sec i believe>
b. Show engine innodb status; (when txn is blocked, u can see on whats its blocked)
c. Show process list; (list of connections and what they are doing)
Lock errors
1. Lock wait timeout exceeded:
a. set global innodb_lock_wait_timeout = x; <default is 150 sec i believe>
b. Show engine innodb status; (when txn is blocked, u can see on whats its blocked)
c. Show process list; (list of connections and what they are doing)
2. Deadlocks
a. You have to do nothing. Auto resolved by Mysql - randomly 1 txn wins and other rolled back.
b. Show engine innodb status - shows u latest deadlocks that occurred
Select for update
Select for share
Read locks
1. Select for update
a. Use carefully.
i. You might end up locking part of the index tree. (select .. where cost > 50)
b. Good practice is to select row ids first and then update (i.e. specific row locks)
i. Select id where cost > 50
ii. Update where id = x
Read locks
1. Select for update
a. Use carefully.
i. You might end up locking part of the index tree. (select .. where cost > 50)
b. Good practice is to select row ids first and then update (i.e. specific row locks)
i. Select id where cost > 50
ii. Update where id = x
2. Select for share
a. It’s a pure read lock. Writers will wait for read to complete
Repeatable read
Read committed
Read un-committed
Serializable
Isolation levels
1. Repeatable read (default i believe in aurora)
a. The same read if done again in the txn sees the same thing (except if some other txn commits
before the second read)
Isolation levels
1. Repeatable read (default i believe in aurora)
a. The same read if done again in the txn sees the same thing (except if some other txn commits
before the second read)
2. Read Committed (newly added)
a. Every read in the txn sees the latest state
Isolation levels
1. Repeatable read (default i believe in aurora)
a. The same read if done again in the txn sees the same thing (except if some other txn commits
before the second read)
2. Read Committed (newly added)
a. Every read in the txn sees the latest state
3. Read un-Committed (not recommended)
a. A read in the txn sees the dirty state of uncommitted txns
Isolation levels
1. Repeatable read (default i believe in aurora)
a. The same read if done again in the txn sees the same thing (except if some other txn commits
before the second read)
2. Read Committed (newly added)
a. Every read in the txn sees the latest state
3. Read un-Committed (not recommended)
a. A read in the txn sees the dirty state of uncommitted txns
4. Serializable
a. All txns go in sequence
Why is this important ?
For every transaction:
Why is this important ?
For every transaction:
1. Rows updated:
a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored.
Why is this important ?
For every transaction:
1. Rows updated:
a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored.
b. Even newly inserted rows are stored in undo log.
Why is this important ?
For every transaction:
1. Rows updated:
a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored.
b. Even newly inserted rows are stored in undo log.
c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows.
Why is this important ?
For every transaction:
1. Rows updated:
a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored.
b. Even newly inserted rows are stored in undo log.
c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows.
2. Rows being read:
a. A snapshot is stored in the undo log.
Why is this important ?
For every transaction:
1. Rows updated:
a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored.
b. Even newly inserted rows are stored in undo log.
c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows.
2. Rows being read:
a. A snapshot is stored in the undo log.
b. It helps satisfy the isolation level of txn
Why is this important ?
For every transaction:
1. Rows updated:
a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored.
b. Even newly inserted rows are stored in undo log.
c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows.
2. Rows being read:
a. A snapshot is stored in the undo log.
b. It helps satisfy the isolation level of txn
c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows.
Aurora Undo Log
● Normally in vanilla mysql,
○ each node has its own storage.
Aurora Undo Log
● Normally in vanilla mysql,
○ each node has its own storage.
● Storage is shared across nodes
○ => a single undo log that is shared between writer & reader
Aurora Undo Log
● Normally in vanilla mysql,
○ each node has its own storage.
● Storage is shared across nodes
○ => a single undo log that is shared between writer & reader
● Imagine long running transactions
Aurora Undo Log
● Normally in vanilla mysql,
○ each node has its own storage.
● Storage is shared across nodes
○ => a single undo log that is shared between writer & reader
● Imagine long running transactions
○ Based on isolation level
Aurora Undo Log
● Normally in vanilla mysql,
○ each node has its own storage.
● Storage is shared across nodes
○ => a single undo log that is shared between writer & reader
● Imagine long running transactions
○ Based on isolation level
○ The undo log might keep growing …
Aurora Undo Log
● Normally in vanilla mysql,
○ each node has its own storage.
● Storage is shared across nodes
○ => a single undo log that is shared between writer & reader
● Imagine long running transactions
○ Based on isolation level
○ The undo log might keep growing …
○ Purging / garbage collection will not occur…
Aurora Undo Log
● Normally in vanilla mysql,
○ each node has its own storage.
● Storage is shared across nodes
○ => a single undo log that is shared between writer & reader
● Imagine long running transactions
○ Based on isolation level
○ The undo log might keep growing …
○ Purging / garbage collection will not occur…
○ At some point, Paralysis due to overdue GC
Writes to Aurora & Cost
● Keep an eye on IOPS
○ IOPS ++ == $ ++
● Batch your writes if possible
● Compress your data before sending.
1. Mysql error log
2. Mysql slow query log
3. Metrics
Monitoring
1. Never ignore mysql error logs. It might have something critical mentioned. Its
your best friend !
2. Can Enable slow query logs to keep track of slow running queries
3. Metrics
a. Recommend Percona PMM (available metrics are graphed nicely)
b. Buffer pool usage metrics
c. Undo log history growth / RollbackSegmentHistoryListLength metric
d. Insert latencies
e. IOPS usage
Aurora Parallel query
1. The only feature missing in other mysql variants.
2. Allows for parallelism in a select query
Aurora Parallel query
1. The only feature missing in other mysql variants.
2. Allows for parallelism in a select query
3. Bypasses the in-memory buffer pool doing table scans on disk. :)
Aurora Parallel query
1. The only feature missing in other mysql variants.
2. Allows for parallelism in a select query
3. Bypasses the in-memory buffer pool doing table scans on disk. :)
a. => IOPS => $ :)
Aurora Parallel query
1. The only feature missing in other mysql variants.
2. Allows for parallelism in a select query
3. Bypasses the in-memory buffer pool doing table scans on disk. :)
a. => IOPS => $ :)
4. Supposedly good for your reporting queries
Other helpful stuff
1. Use START TRANSACTION READ ONLY
; (less bookkeeping for readonly)
2. Run an explain on your query; be aware if index is used.
a. Explains are not always accurate
3. Show process list; (i used to kill long running transactions/ sleeping transactions - no
mercy :) )
4. Show engine innodb status;
5. You have an index on group by columns but order by columns not in index ?
6. Joining 2 tables - think of 2 for loops (keep outer for loop short)
7. Query Cache - apparently works well in aurora ! (discouraged in rds/mysql)
Finally ● Make 1 change at a time
○ Change
○ See effect
○ Make next change
Finally
● Make 1 change at a time
○ Change
○ See effect
○ Make next change
● Keep an eye on $ cost
Select QNS from you;
select Thank you from me;
Who am I ?
Ex Mysql Guy at Flipkart / Data guy at Trustana
linkedin.com/in/213vishnu/
mash213.wordpress.com/conferences/
https://twitter.com/sweetweet213

More Related Content

Similar to A talk on mysql & aurora

Back to Basics 3: Scaling 30,000 Requests a Second with MongoDB
Back to Basics 3: Scaling 30,000 Requests a Second with MongoDBBack to Basics 3: Scaling 30,000 Requests a Second with MongoDB
Back to Basics 3: Scaling 30,000 Requests a Second with MongoDBMongoDB
 
Scaling to 30,000 Requests Per Second and Beyond with MongoDB
Scaling to 30,000 Requests Per Second and Beyond with MongoDBScaling to 30,000 Requests Per Second and Beyond with MongoDB
Scaling to 30,000 Requests Per Second and Beyond with MongoDBmchesnut
 
LinuxCon Japan 2010 suzaki
LinuxCon Japan 2010 suzakiLinuxCon Japan 2010 suzaki
LinuxCon Japan 2010 suzakiKuniyasu Suzaki
 
Managing Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDBManaging Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDBJason Terpko
 
Low Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).pptLow Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).pptLearnWithJCM
 
Managing data and operation distribution in MongoDB
Managing data and operation distribution in MongoDBManaging data and operation distribution in MongoDB
Managing data and operation distribution in MongoDBAntonios Giannopoulos
 
Distributed Coordination
Distributed CoordinationDistributed Coordination
Distributed CoordinationLuis Galárraga
 
Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediConnor McDonald
 
what every web and app developer should know about multithreading
what every web and app developer should know about multithreadingwhat every web and app developer should know about multithreading
what every web and app developer should know about multithreadingIlya Haykinson
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLConnor McDonald
 
Cache aware hybrid sorter
Cache aware hybrid sorterCache aware hybrid sorter
Cache aware hybrid sorterManchor Ko
 
Cassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapestCassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapestDuyhai Doan
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!Boris Hristov
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionTony Albrecht
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure Eman magdy
 
Introduction to Cassandra
Introduction to CassandraIntroduction to Cassandra
Introduction to Cassandraaaronmorton
 
Python in 90 Minutes
Python in 90 MinutesPython in 90 Minutes
Python in 90 MinutesNachu Muthu
 

Similar to A talk on mysql & aurora (20)

Back to Basics 3: Scaling 30,000 Requests a Second with MongoDB
Back to Basics 3: Scaling 30,000 Requests a Second with MongoDBBack to Basics 3: Scaling 30,000 Requests a Second with MongoDB
Back to Basics 3: Scaling 30,000 Requests a Second with MongoDB
 
Scaling to 30,000 Requests Per Second and Beyond with MongoDB
Scaling to 30,000 Requests Per Second and Beyond with MongoDBScaling to 30,000 Requests Per Second and Beyond with MongoDB
Scaling to 30,000 Requests Per Second and Beyond with MongoDB
 
LinuxCon Japan 2010 suzaki
LinuxCon Japan 2010 suzakiLinuxCon Japan 2010 suzaki
LinuxCon Japan 2010 suzaki
 
Managing Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDBManaging Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDB
 
Low Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).pptLow Level Prog. (from 201-c).ppt
Low Level Prog. (from 201-c).ppt
 
Managing data and operation distribution in MongoDB
Managing data and operation distribution in MongoDBManaging data and operation distribution in MongoDB
Managing data and operation distribution in MongoDB
 
Python made easy
Python made easy Python made easy
Python made easy
 
Distributed Coordination
Distributed CoordinationDistributed Coordination
Distributed Coordination
 
Sangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL JediSangam 18 - Database Development: Return of the SQL Jedi
Sangam 18 - Database Development: Return of the SQL Jedi
 
what every web and app developer should know about multithreading
what every web and app developer should know about multithreadingwhat every web and app developer should know about multithreading
what every web and app developer should know about multithreading
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
Cache aware hybrid sorter
Cache aware hybrid sorterCache aware hybrid sorter
Cache aware hybrid sorter
 
Cassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapestCassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapest
 
C language
C languageC language
C language
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
 
Jvm memory model
Jvm memory modelJvm memory model
Jvm memory model
 
Parallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical SectionParallel Programming: Beyond the Critical Section
Parallel Programming: Beyond the Critical Section
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
Introduction to Cassandra
Introduction to CassandraIntroduction to Cassandra
Introduction to Cassandra
 
Python in 90 Minutes
Python in 90 MinutesPython in 90 Minutes
Python in 90 Minutes
 

More from vishnu rao

Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafkavishnu rao
 
Mysql Relay log - the unsung hero
Mysql Relay log - the unsung heroMysql Relay log - the unsung hero
Mysql Relay log - the unsung herovishnu rao
 
simple introduction to hadoop
simple introduction to hadoopsimple introduction to hadoop
simple introduction to hadoopvishnu rao
 
Druid beginner performance tips
Druid beginner performance tipsDruid beginner performance tips
Druid beginner performance tipsvishnu rao
 
Demystifying datastores
Demystifying datastoresDemystifying datastores
Demystifying datastoresvishnu rao
 
Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker vishnu rao
 
StormWars - when the data stream shrinks
StormWars - when the data stream shrinksStormWars - when the data stream shrinks
StormWars - when the data stream shrinksvishnu rao
 
Punch clock for debugging apache storm
Punch clock for  debugging apache stormPunch clock for  debugging apache storm
Punch clock for debugging apache stormvishnu rao
 
a wild Supposition: can MySQL be Kafka ?
a wild Supposition: can MySQL be Kafka ?a wild Supposition: can MySQL be Kafka ?
a wild Supposition: can MySQL be Kafka ?vishnu rao
 
Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...
Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...
Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...vishnu rao
 

More from vishnu rao (10)

Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Mysql Relay log - the unsung hero
Mysql Relay log - the unsung heroMysql Relay log - the unsung hero
Mysql Relay log - the unsung hero
 
simple introduction to hadoop
simple introduction to hadoopsimple introduction to hadoop
simple introduction to hadoop
 
Druid beginner performance tips
Druid beginner performance tipsDruid beginner performance tips
Druid beginner performance tips
 
Demystifying datastores
Demystifying datastoresDemystifying datastores
Demystifying datastores
 
Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker Visualising Basic Concepts of Docker
Visualising Basic Concepts of Docker
 
StormWars - when the data stream shrinks
StormWars - when the data stream shrinksStormWars - when the data stream shrinks
StormWars - when the data stream shrinks
 
Punch clock for debugging apache storm
Punch clock for  debugging apache stormPunch clock for  debugging apache storm
Punch clock for debugging apache storm
 
a wild Supposition: can MySQL be Kafka ?
a wild Supposition: can MySQL be Kafka ?a wild Supposition: can MySQL be Kafka ?
a wild Supposition: can MySQL be Kafka ?
 
Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...
Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...
Build your own Real Time Analytics and Visualization, Enable Complex Event Pr...
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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)wesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 2024The Digital Insurer
 
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 RobisonAnna Loughnan Colquhoun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

A talk on mysql & aurora

  • 1.
  • 3. Our journey to Aurora
  • 4. Our journey to Aurora
  • 5. Our journey to Aurora
  • 6. Our journey to Aurora
  • 7. Our journey to Aurora
  • 8. Our journey to Aurora
  • 9. Our journey to Aurora
  • 10. Our journey to Aurora
  • 12. Indexes Primary key index Secondary key index Clustered key index Hash index*
  • 13. Primary key index (btree)
  • 14. Primary key index (btree) Rows are attached to the Leaf node as part of same data-structure
  • 16. Secondary key index (btree) Leaf node have pointers to PK of rows
  • 17. Clustered Key In absence of PK/uniq key, MySQL creates a hidden clustered key.
  • 18. Index use ● Left prefix rule ○ Name, ID, country ■ Select … where ID = 3 and country = us ■ Select … where ID = 3 ■ Select … where country = us ■ Select … where Name = ‘blah’ and country = us ■ Select … where Name = ‘blah’ and ID = 4
  • 19. Index use ● Left prefix rule ○ Name, ID, country ■ Select … where ID = 3 and country = us ■ Select … where ID = 3 ■ Select … where country = us ■ Select … where Name = ‘blah’ and country = us ■ Select … where Name = ‘blah’ and ID = 4 ● Duplicate indexes ○ Name, country ○ Name, country, zip ○ Name, zip
  • 20. Index use ● Selectivity rule ○ Select … where gender = male ○ Say 2ndary index on gender (cardinality is say 2 = male/female) ○ Say 70 % of rows are male
  • 21. Index use ● Selectivity rule ○ Select … where gender = male ○ Say 2ndary index on gender (cardinality is say 2 = male/female) ○ Say 70 % of rows are male ○ => in the btree, 70% of rows will be under male node.
  • 22. Index use ● Selectivity rule ○ Select … where gender = male ○ Say 2ndary index on gender (cardinality is say 2 = male/female) ○ Say 70 % of rows are male ○ => in the btree, 70% of rows will be under male node. ○ => since 2ndary index, the node has pointers to 70% of rows
  • 23. Index use ● Selectivity rule ○ Select … where gender = male ○ Say 2ndary index on gender (cardinality is say 2 = male/female) ○ Say 70 % of rows are male ○ => in the btree, 70% of rows will be under male node. ○ => since 2ndary index, the node has pointers to 70% of rows ○ What does MySQL Do ?
  • 24. Index use ● Selectivity rule ○ Select … where gender = male ○ Say 2ndary index on gender (cardinality is say 2 = male/female) ○ Say 70 % of rows are male ○ => in the btree, 70% of rows will be under male node. ○ => since 2ndary index, the node has pointers to 70% of rows ○ What does MySQL Do ? ■ Does it read index , traverse it and then go to disk for the 70% of data ?
  • 25. Index use ● Selectivity rule ○ Select … where gender = male ○ Say 2ndary index on gender (cardinality is say 2 = male/female) ○ Say 70 % of rows are male ○ => in the btree, 70% of rows will be under male node. ○ => since 2ndary index, the node has pointers to 70% of rows ○ What does MySQL Do ? ■ Does it read index , traverse it and then go to disk for the 70% of data ? ■ It does not , it bypasses index and goes to disk directly
  • 26. Index use ● Selectivity rule ○ Select … where gender = male ○ Say 2ndary index on gender (cardinality is say 2 = male/female) ○ Say 70 % of rows are male ○ => in the btree, 70% of rows will be under male node. ○ => since 2ndary index, the node has pointers to 70% of rows ○ What does MySQL Do ? ■ Does it read index , traverse it and then go to disk for the 70% of data ? ■ It does not , it bypasses index and goes to disk directly ■ It does a table scan ! (more effective). ● Explain might indicate use of index but in practice it does not!
  • 27. Storage engines Innodb * MyIsam Memory (can create hash index) Federated NDB
  • 28. Storage engines Innodb * (enable adaptive hash idx) MyIsam Memory (can create hash index) Federated NDB
  • 29.
  • 30. Lock wait timeout exceeded error Deadlocks
  • 31. Lock errors 1. Lock wait timeout exceeded: a. set global innodb_lock_wait_timeout = x; <default is 150 sec i believe> b. Show engine innodb status; (when txn is blocked, u can see on whats its blocked) c. Show process list; (list of connections and what they are doing)
  • 32. Lock errors 1. Lock wait timeout exceeded: a. set global innodb_lock_wait_timeout = x; <default is 150 sec i believe> b. Show engine innodb status; (when txn is blocked, u can see on whats its blocked) c. Show process list; (list of connections and what they are doing) 2. Deadlocks a. You have to do nothing. Auto resolved by Mysql - randomly 1 txn wins and other rolled back. b. Show engine innodb status - shows u latest deadlocks that occurred
  • 34. Read locks 1. Select for update a. Use carefully. i. You might end up locking part of the index tree. (select .. where cost > 50) b. Good practice is to select row ids first and then update (i.e. specific row locks) i. Select id where cost > 50 ii. Update where id = x
  • 35. Read locks 1. Select for update a. Use carefully. i. You might end up locking part of the index tree. (select .. where cost > 50) b. Good practice is to select row ids first and then update (i.e. specific row locks) i. Select id where cost > 50 ii. Update where id = x 2. Select for share a. It’s a pure read lock. Writers will wait for read to complete
  • 36.
  • 37. Repeatable read Read committed Read un-committed Serializable
  • 38. Isolation levels 1. Repeatable read (default i believe in aurora) a. The same read if done again in the txn sees the same thing (except if some other txn commits before the second read)
  • 39. Isolation levels 1. Repeatable read (default i believe in aurora) a. The same read if done again in the txn sees the same thing (except if some other txn commits before the second read) 2. Read Committed (newly added) a. Every read in the txn sees the latest state
  • 40. Isolation levels 1. Repeatable read (default i believe in aurora) a. The same read if done again in the txn sees the same thing (except if some other txn commits before the second read) 2. Read Committed (newly added) a. Every read in the txn sees the latest state 3. Read un-Committed (not recommended) a. A read in the txn sees the dirty state of uncommitted txns
  • 41. Isolation levels 1. Repeatable read (default i believe in aurora) a. The same read if done again in the txn sees the same thing (except if some other txn commits before the second read) 2. Read Committed (newly added) a. Every read in the txn sees the latest state 3. Read un-Committed (not recommended) a. A read in the txn sees the dirty state of uncommitted txns 4. Serializable a. All txns go in sequence
  • 42. Why is this important ? For every transaction:
  • 43. Why is this important ? For every transaction: 1. Rows updated: a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored.
  • 44. Why is this important ? For every transaction: 1. Rows updated: a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored. b. Even newly inserted rows are stored in undo log.
  • 45. Why is this important ? For every transaction: 1. Rows updated: a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored. b. Even newly inserted rows are stored in undo log. c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows.
  • 46. Why is this important ? For every transaction: 1. Rows updated: a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored. b. Even newly inserted rows are stored in undo log. c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows. 2. Rows being read: a. A snapshot is stored in the undo log.
  • 47. Why is this important ? For every transaction: 1. Rows updated: a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored. b. Even newly inserted rows are stored in undo log. c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows. 2. Rows being read: a. A snapshot is stored in the undo log. b. It helps satisfy the isolation level of txn
  • 48. Why is this important ? For every transaction: 1. Rows updated: a. Before version of rows is stored in undo-log. If txn is rolled back, the before version is restored. b. Even newly inserted rows are stored in undo log. c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows. 2. Rows being read: a. A snapshot is stored in the undo log. b. It helps satisfy the isolation level of txn c. Once txn completes (rolled back/committed) , the undo log purges the relevant rows.
  • 49. Aurora Undo Log ● Normally in vanilla mysql, ○ each node has its own storage.
  • 50. Aurora Undo Log ● Normally in vanilla mysql, ○ each node has its own storage. ● Storage is shared across nodes ○ => a single undo log that is shared between writer & reader
  • 51. Aurora Undo Log ● Normally in vanilla mysql, ○ each node has its own storage. ● Storage is shared across nodes ○ => a single undo log that is shared between writer & reader ● Imagine long running transactions
  • 52. Aurora Undo Log ● Normally in vanilla mysql, ○ each node has its own storage. ● Storage is shared across nodes ○ => a single undo log that is shared between writer & reader ● Imagine long running transactions ○ Based on isolation level
  • 53. Aurora Undo Log ● Normally in vanilla mysql, ○ each node has its own storage. ● Storage is shared across nodes ○ => a single undo log that is shared between writer & reader ● Imagine long running transactions ○ Based on isolation level ○ The undo log might keep growing …
  • 54. Aurora Undo Log ● Normally in vanilla mysql, ○ each node has its own storage. ● Storage is shared across nodes ○ => a single undo log that is shared between writer & reader ● Imagine long running transactions ○ Based on isolation level ○ The undo log might keep growing … ○ Purging / garbage collection will not occur…
  • 55. Aurora Undo Log ● Normally in vanilla mysql, ○ each node has its own storage. ● Storage is shared across nodes ○ => a single undo log that is shared between writer & reader ● Imagine long running transactions ○ Based on isolation level ○ The undo log might keep growing … ○ Purging / garbage collection will not occur… ○ At some point, Paralysis due to overdue GC
  • 56. Writes to Aurora & Cost ● Keep an eye on IOPS ○ IOPS ++ == $ ++ ● Batch your writes if possible ● Compress your data before sending.
  • 57. 1. Mysql error log 2. Mysql slow query log 3. Metrics
  • 58. Monitoring 1. Never ignore mysql error logs. It might have something critical mentioned. Its your best friend ! 2. Can Enable slow query logs to keep track of slow running queries 3. Metrics a. Recommend Percona PMM (available metrics are graphed nicely) b. Buffer pool usage metrics c. Undo log history growth / RollbackSegmentHistoryListLength metric d. Insert latencies e. IOPS usage
  • 59. Aurora Parallel query 1. The only feature missing in other mysql variants. 2. Allows for parallelism in a select query
  • 60. Aurora Parallel query 1. The only feature missing in other mysql variants. 2. Allows for parallelism in a select query 3. Bypasses the in-memory buffer pool doing table scans on disk. :)
  • 61. Aurora Parallel query 1. The only feature missing in other mysql variants. 2. Allows for parallelism in a select query 3. Bypasses the in-memory buffer pool doing table scans on disk. :) a. => IOPS => $ :)
  • 62. Aurora Parallel query 1. The only feature missing in other mysql variants. 2. Allows for parallelism in a select query 3. Bypasses the in-memory buffer pool doing table scans on disk. :) a. => IOPS => $ :) 4. Supposedly good for your reporting queries
  • 63. Other helpful stuff 1. Use START TRANSACTION READ ONLY ; (less bookkeeping for readonly) 2. Run an explain on your query; be aware if index is used. a. Explains are not always accurate 3. Show process list; (i used to kill long running transactions/ sleeping transactions - no mercy :) ) 4. Show engine innodb status; 5. You have an index on group by columns but order by columns not in index ? 6. Joining 2 tables - think of 2 for loops (keep outer for loop short) 7. Query Cache - apparently works well in aurora ! (discouraged in rds/mysql)
  • 64. Finally ● Make 1 change at a time ○ Change ○ See effect ○ Make next change
  • 65. Finally ● Make 1 change at a time ○ Change ○ See effect ○ Make next change ● Keep an eye on $ cost
  • 66. Select QNS from you; select Thank you from me; Who am I ? Ex Mysql Guy at Flipkart / Data guy at Trustana linkedin.com/in/213vishnu/ mash213.wordpress.com/conferences/ https://twitter.com/sweetweet213