The Top 20 Design Tips For MySQL Enterprise Data Architects
The Top 20 Design Tips For MySQL Enterprise Data Architects
Ronald Bradford
COO
PrimeBase Technologies
April 2008
(c) Copyright 2008 PrimeBase Technologies Presented
VersionBy:
1.1 Ronald Bradford
10.Apr.2008 www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
Overview
❖ Table Structure
❖ SQL
❖ Indexes
❖ Enterprise Approaches
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
❖ TIMESTAMP v DATETIME
❖ Suitable for EPOCH only values
❖ TIMESTAMP is 4 bytes
❖ DATETIME is 8 bytes
❖ FYI: DATE is 3 bytes, TIME is 3 bytes = 6 Bytes???
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
❖ CHAR(n)
❖ Use VARCHAR(n) for variable values
❖ e.g. CHAR(128) when storing ~10 bytes
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
6. NOT NULL
Best
Always use NOT NULL unless Practice
there is a reason why not
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
❖ VARCHAR(255)
❖ Poor Design - No understanding of underlying
data
❖ Old Design - ( 4.x limitation, now 3-4 years old)
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
9. Be Wary of TEXT/BLOB
❖ Using SELECT *
❖ MySQL Internal Temporary table will force Temp
Disk Table
❖ Internal storage (e.g. Innodb)
❖ Stores first 768 bytes, then a separate 16k data
page per row per TEXT/BLOB field
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
❖ Good
❖ Dramatic performance improvements
❖ Improves memory usage
❖ Data Integrity
❖ Bad
❖ Slows performance for writes
❖ Wastes disk space for unused, duplicate or
ineffective indexes
❖ In-effective usage of memory
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
❖ Concatenated Indexes
❖ (col1, col2)
❖ Partial Indexes
❖ (name(20))
❖ Covering Indexes
❖ Full Text Indexes
❖ No function based indexes
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
15. Transactions
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
Best
Practice
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
+--------------------------------+----------+---------------------------+---------------+-------------+
| Status | Duration | Source_function | Source_file | Source_line |
+--------------------------------+----------+---------------------------+---------------+-------------+
| (initialization) | 0.000014 | send_result_to_client | sql_cache.cc | 1143 |
| checking query cache for query | 0.000042 | open_tables | sql_base.cc | 2652 |
| Opening tables | 0.000015 | mysql_lock_tables | lock.cc | 153 |
| System lock | 0.000009 | mysql_lock_tables | lock.cc | 163 |
| Table lock | 0.000034 | mysql_select | sql_select.cc | 2273 |
| init | 0.000041 | optimize | sql_select.cc | 765 |
| optimizing | 0.000008 | optimize | sql_select.cc | 924 |
| statistics | 0.000016 | optimize | sql_select.cc | 934 |
| preparing | 0.000012 | exec | sql_select.cc | 1594 |
| executing | 0.000008 | exec | sql_select.cc | 2114 |
| Sending data | 0.000163 | mysql_select | sql_select.cc | 2318 |
| end | 0.000021 | mysql_execute_command | sql_parse.cc | 5141 |
| query end
| freeing items
| closing tables
Text
| 0.000007 | query_cache_end_of_result | sql_cache.cc |
| storing result in query cache | 0.000007 | mysql_parse
| 0.000018 | dispatch_command
| 0.000009 | log_slow_statement
| sql_parse.cc |
| sql_parse.cc |
| sql_parse.cc |
735 |
6142 |
2146 |
2204 |
| logging slow query | 0.000006 | dispatch_command | sql_parse.cc | 2169 |
+--------------------------------+----------+---------------------------+---------------+-------------+
17 rows in set (0.00 sec)
+--------------------------------+----------+-----------------------+--------------+-------------+
| Status | Duration | Source_function | Source_file | Source_line |
+--------------------------------+----------+-----------------------+--------------+-------------+
| (initialization) | 0.000012 | send_result_to_client | sql_cache.cc | 1143 |
| checking query cache for query | 0.00001 | send_result_to_client | sql_cache.cc | 1224 |
| checking privileges on cached | 0.000007 | send_result_to_client | sql_cache.cc | 1317 |
| sending cached result to clien | 0.000025 | log_slow_statement | sql_parse.cc | 2204 |
| logging slow query | 0.000007 | dispatch_command | sql_parse.cc | 2169 |
+--------------------------------+----------+-----------------------+--------------+-------------+
5 rows in set (0.00 sec)
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
Executive Summary
❖ PrimeBase Technologies
❖ Technology Experts
❖ Solution Experts
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org
The Top 20 Design Tips
(c) Copyright 2008 PrimeBase Technologies Presented By: Ronald Bradford www.primebase.org