Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs...
Transcript of Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs...
![Page 1: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/1.jpg)
Percona Live 2017Santa Clara, California | April 24-27, 2017
Rick's RoTsRules of Thumb for MySQL
Rick James
![Page 2: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/2.jpg)
AgendaIndexingOptimizationPartitioningCharacter SetsGalera/PXCDatatypesHow ToHardwareMiscellany
![Page 3: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/3.jpg)
INDEXing
A Mini Lesson
![Page 4: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/4.jpg)
INDEX Purpose & Design• Index may greatly speed up SELECT• Adding indexes is not a panacea• BTree – good all around
![Page 5: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/5.jpg)
INDEX -- 2• Start INDEX with "=" from WHERE• Avoid: WHERE func(col) = 'const' • flip: WHERE col = inverse('const')• Hard to opt: WHERE active = 1• Only 1 index used per SELECT• Prefix often bad: INDEX(name(10))• Usually wrong: UNIQUE(name(10))
![Page 6: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/6.jpg)
INDEX -- 3• INDEX(a,b) != INDEX(a), INDEX(b)• INDEX(a,b) handles INDEX(a), not (b)• INDEX(a,b,c,d,e) – may be excessive• "Using index" = "Covering index" = 2x speedup
![Page 7: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/7.jpg)
INDEX -- 4• Index is shunned if need > ~20% of table
• Avoid USE/FORCE/IGNORE INDEX,STRAIGHT_JOIN • except in desperation
![Page 8: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/8.jpg)
Index Q&A1 question (hold rest until end)
Index Cookbook (includes 7 tips on efficientmany:many mapping tables):mysql.rjweb.org/doc.php/index_cookbook_mysql
![Page 9: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/9.jpg)
Optimization
(or not)
![Page 10: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/10.jpg)
Opt 1 -- Subqueries• Subqueries may perform poorly • Turn into JOIN where possible • Even with 5.6's auto-key, subquery slow• IN ( SELECT … ) – especially bad• ( … GROUP / LIMIT ) – may be good
![Page 11: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/11.jpg)
Opt 2• OR ⇒ UNION• "Using Temporary" and "Filesort" -- • not the end of the world • does not necessarily mean hitting the disk
![Page 12: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/12.jpg)
Opt 3• Clustered Data is 10x faster (less I/O) • Range by PK in InnnoDB• 1000 qps (YMMV)• SlowLog is best clue• No: mix DISTINCT and GROUP BY• On UNION, explicitly ALL or DISTINCT• JOIN + GROUP BY over-counts aggregates
![Page 13: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/13.jpg)
Opt 4• How serious are optimizations? • 1K rows: Yawn • 1M rows: Serious • 1B rows: You'll need more than these RoTs
![Page 14: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/14.jpg)
Opt 5• < 10% improvement ⇒ don't bother • Except: do datatypes 'right' up front• Normalize, but don't over-normalize• Protect against "SQL injection"• InnoDB transaction length: • if > 5 seconds, redesign
![Page 15: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/15.jpg)
Optimization Q&A1 question (hold rest until end)
![Page 16: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/16.jpg)
PARTITIONing
Are you sure?
![Page 17: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/17.jpg)
Partition - When?• Don't use PARTITION, unless… • You know that it will help • > 1M rows
• No UNIQUE, FOREIGN KEY (maybe 8.x?)
![Page 18: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/18.jpg)
Partition - Use Cases• Sliding time• 2D index needed• Hot partition + messy indexes• 'Transportable tablespaces'
![Page 19: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/19.jpg)
Partition - Limits• Only BY RANGE• No SUBPARTITION• No index should start with Partition key• AUTO_INCREMENT • need not be PRIMARY KEY • must be 1st col of some key • 20-50 partitions/table (more in 8.0?)
![Page 20: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/20.jpg)
Partition - Q&A1 question (hold rest until end)
mariadb.com/kb/en/mariadb/partition-maintenance/
![Page 21: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/21.jpg)
CHARACTER SETs
And COLLATION
![Page 22: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/22.jpg)
Notation• UTF-8 is what the rest of the world calls it• utf8mb4 is the equivalent in MySQL • utf8 is a subset of utf8mb4• "Unicode" is related, but not what to use in text
• CHARACTER SET != COLLATION• UTF-8 != Unicode
![Page 23: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/23.jpg)
Character set• Use utf8mb4 for text • utf8 fails to handle Emoji and some of Chinese
• Use ascii or latin1 • for hex/ascii • GUID, UUID, md5, sha1 • IP address • country_code, postal_code, …
![Page 24: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/24.jpg)
Character set debugging• HEX(col)• LENGTH(col) – bytes• CHAR_LENGTH(col) – characters
![Page 25: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/25.jpg)
Common corruptionFor Señor, you might see
• Se?or – Question marks• Señor – Mojibake or Double-encoding• Se�or – Black diamond• Se – Truncation
![Page 26: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/26.jpg)
Best Practice• Outside: Use UTF-8 for bytes, editor, and client• Connection: SET NAMES utf8mb4; • or some API-specific equivalent
• Have the column/table declared <CHARACTER SET utf8mb4• HTML – starting and forms: <meta charset=UTF-8> <form accept-charset="UTF-8">
![Page 27: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/27.jpg)
COLLATIONLeast realistic to most: utf8mb4_bin -- just compare bits utf8mb4_general_ci -- no multi-char equiv utf8mb4_unicode_ci -- old Unicode utf8mb4_unicode_520_ci -- 5.20 utf8mb4_0900_ai_ci -- 9.0 (in 8.0)
Case folding and Accent stripping go together ☹
![Page 28: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/28.jpg)
Index too large (767)To work around this error, do one of• Change 255 to 191 on the VARCHAR (but limit column size)• ALTER .. CONVERT TO utf8 (but disallow Emoji andsome Chinese)• Use a "prefix" index (ill-advised)• Reconfigure (for 5.6.3)• Upgrade to 5.7.7 (or later)
![Page 29: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/29.jpg)
Character Set - Q&A1 question (hold rest until end)
More on common troubles and solutions:stackoverflow.com/a/38363567/1766831
Collations:mysql.rjweb.org/utf8_collations.html
![Page 30: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/30.jpg)
Galera / PXC
Galera and XtraDB Cluster
![Page 31: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/31.jpg)
Galera - on Local Node• Check for errors even after COMMIT• AUTO_INCREMENT values not consecutive
![Page 32: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/32.jpg)
Galera - on Local Node• Transactions may be faster or slower, even betweendatacenters
• Best HA: 3 datacenters, 1+ node each
• SET SESSION wsrep_sync_wait = 1;before SELECT
![Page 33: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/33.jpg)
Galera - on Local Node• For Backup, testing, upgrades, alter, …: • Remove node from cluster; • Do the task; • Put back in cluster; syncup is auto
![Page 34: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/34.jpg)
HA Competition• PXC is Galera, plus a few mods• Group Replication (from Oracle) seems to be goodcompetition• Fabric (from Oracle) seems to be dead• MHA and Orchestrator are good, but not quite in the sameniche• Traditional Replication with Dual-Masters – less desirable
![Page 35: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/35.jpg)
Galera Q&A1 question (hold rest until end)
If you might use PXC / Galera, code for it anyway
Tips for Programmers/DBAs:mariadb.com/kb/en/mariadb/tips-on-converting-to-galera/
![Page 36: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/36.jpg)
Datatypes
Declaring Columns (do it right tostart with)
![Page 37: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/37.jpg)
Datatypes - 1• DATETIME, not DATE and TIME• Usually UNSIGNED• Usually NOT NULL
![Page 38: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/38.jpg)
Datatypes - 2• Overlap test: WHERE a.start < b.end AND a.end > b.start
• SEQUENCE ⇒ AUTO_INCREMENT • See also MariaDB's sequence tables
![Page 39: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/39.jpg)
Datatypes - Sizes• INT(2) ain't what you think! • Learn the sizes (INT is 4 bytes, etc)• BIGINT – do you really need such large• No: FLOAT/DOUBLE for money - use DECIMAL• Never: FLOAT(m,n)• Eschew VARCHAR(255)• VARCHAR, not CHAR (unless truly fixed len)
![Page 40: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/40.jpg)
Datatypes - Custom• GUID/UUID/MD5 as a key: Random, hence slow
• IP address (IPv6) - VARBINARY(39) orBINARY(16)
• No: Credit cards, SSNs, etc – Security issues
• Lat/lng: DECIMAL( ,4)
![Page 41: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/41.jpg)
Datatypes - Q&A1 question (hold rest until end)
IP ranges:mariadb.com/kb/en/ip-range-table-performance/
Find the 10 nearest Starbucks:mariadb.com/kb/en/latitudelongitude-indexing/
![Page 42: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/42.jpg)
How To
Tips on various problems
![Page 43: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/43.jpg)
Pagination• No: Pagination via OFFSET and LIMIT • Can display dup/missing rows • Instead, remember where "left off"
![Page 44: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/44.jpg)
Fast INSERT• LOAD DATA
• batch INSERT • 100-1000 rows per batch • Replication-friendly • Transaction per batch
![Page 45: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/45.jpg)
Fast DELETE• DELETE • 1000 rows per DELETE • Chunk on primary key• Delete via DROP PARTITION
![Page 46: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/46.jpg)
Date range tip dt >= '2017-02-26' AND dt < '2017-02-26' + INTERVAL 7 DAY• avoids end second• avoids leapday (etc) hassle• works for DATE, DATETIME, DATETIME(6),TIMESTAMP, etc.
![Page 47: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/47.jpg)
Data Warehouse• Create & maintain Summary Tables
• Do not normalize "continuous" values (dates, floats)
• With MariaDB, consider ColumnStore (neeInfoBright), TokuDB
![Page 48: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/48.jpg)
Entity-Attribute-Value• Don't use Key-value schema • Instead toss into JSON blob
![Page 49: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/49.jpg)
How To - Q&A1 question (hold rest until end)
14 Tough Tasks (including the above) - See the firstsection of this:mysql.rjweb.org/
![Page 50: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/50.jpg)
Hardware
Only a 1-time performance fix
![Page 51: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/51.jpg)
Hardware• Fix the schema, not the hardware• 10x speedup for cached data• When timing: • SQL_NO_CACHE (to avoid Query cache) • Run twice (to allow for other caching)
![Page 52: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/52.jpg)
Disk• "Count the disk hits"• 100 IOPs on plain drives • more on SSDs
• RAID • N times as fast (striping) • BBWC ⇒ "instant write"
• No: manually separating tables across filesystems
![Page 53: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/53.jpg)
Hardware CPU / IO• MySQL uses only 1 CPU core per connection • PARTITION or UNION – still only 1• High CPU ⇒ fix slow query • often need "composite" index• High I/O ⇒ tuning / schema / index• Linux: use XFS filesystem
![Page 54: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/54.jpg)
Memory Allocation• InnoDB: 70% of RAM for buffer_pool • lower % for tiny VMs• Other tunables – defaults usually OK • You won't hit any hard limits• Do not let mysqld swap!• Query_cache_type/size = OFF/0
![Page 55: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/55.jpg)
Hardware Q&A1 question (hold rest until end)
Hard Limits:mysql.rjweb.org/doc.php/limits
![Page 56: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/56.jpg)
Miscellany
(What did not fit above)
![Page 57: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/57.jpg)
Numbers• 1000 qps (YMMV)• SlowLog is best clue• No: 1000 databases• No: 1000 tables in a db
• Tame MaxClients• SHOW CREATE TABLE is more descriptive thanDESCRIBE
![Page 58: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/58.jpg)
SELECTs• No: SELECT * • Except debugging or into client hash• COUNT(*), not COUNT(x) • The latter checks each for not NULL.• No: mix DISTINCT and GROUP BY• Aggregate counts/sums are inflated when doing bothJOIN and GROUP BY
![Page 59: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/59.jpg)
Processing• Linux "Load Average" is of little use• Profiling is of little use • nor Performance Schema
• Threads_running > 10 may mean trouble
• "Don't queue it, just do it."
![Page 60: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/60.jpg)
Locked• SHOW PROCESSLIST saying "Locked": • Look for other process that is hogging • or transaction that failed to COMMIT • autocommit=0 begs you to forget to COMMIT
![Page 61: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/61.jpg)
ALTER• Usually combine multiple ALTERs to get rebuild allat once• 5.6.5 allows for many ALTERs to be doneALGORITHM=INPLACE• pt-online-schema-change
![Page 62: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/62.jpg)
MyISAM• MyISAM is dying; don't use it • Gone in 8.0
Conversion tips:mysql.rjweb.org/doc.php/myisam2innodb
![Page 63: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/63.jpg)
Miscellany - Q&A1 question (hold rest until end)
Memory Allocation:mysql.rjweb.org/doc.php/memory
![Page 64: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/64.jpg)
Closing Let the questions flow! Rate My Session
Rick's RoTs – Slides / more detailsmysql.rjweb.org/slides/rots.pdfmysql.rjweb.org/doc.php/ricksrots
Rick: [email protected]/
![Page 65: Percona Live 2017 · Percona Live 2017 Santa Clara, California | April 24-27, 2017 Rick's RoTs Rules of Thumb for MySQL Rick James. Agenda Indexing Optimization Partitioning Character](https://reader030.fdocuments.us/reader030/viewer/2022040516/5e747c84f8aab249195fdb4e/html5/thumbnails/65.jpg)