The Top 20 Design Tips

Similar documents
MySQL 101. Designing effective schema for InnoDB. Yves Trudeau April 2015

Explaining the MySQL EXPLAIN

Introduction to SQL on GRAHAM ED ARMSTRONG SHARCNET AUGUST 2018

1Z MySQL 5 Database Administrator Certified Professional Exam, Part II Exam.

MySQL Schema Review 101

MySQL query profiling and optimization

Chapter 8 How to work with data types

Basic SQL. Basic SQL. Basic SQL

ALTER TABLE Improvements in MARIADB Server. Marko Mäkelä Lead Developer InnoDB MariaDB Corporation

Lab # 2 Hands-On. DDL Basic SQL Statements Institute of Computer Science, University of Tartu, Estonia

Effective Software Development with MySQL

SQL Data Definition and Data Manipulation Languages (DDL and DML)

TINYINT[(M)] [UNSIGNED] [ZEROFILL] A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

SQL (and MySQL) Useful things I have learnt, borrowed and stolen

Oracle 1Z0-882 Exam. Volume: 100 Questions. Question No: 1 Consider the table structure shown by this output: Mysql> desc city:

Basis Data Terapan. Yoannita

MySQL Schema Best Practices

MTAT Introduction to Databases

MySQL: an application

itexamdump 최고이자최신인 IT 인증시험덤프 일년무료업데이트서비스제공

Db2 Alter Table Alter Column Set Data Type Char

Writing High Performance SQL Statements. Tim Sharp July 14, 2014

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

Data Types in MySQL CSCU9Q5. MySQL. Data Types. Consequences of Data Types. Common Data Types. Storage size Character String Date and Time.

Tool/Web URL Features phpmyadmin. More on phpmyadmin under User Intefaces. MySQL Query Browser

Mysql Information Schema Update Time Null >>>CLICK HERE<<< doctrine:schema:update --dump-sql ALTER TABLE categorie

Building Better. SQL Server Databases

Advanced MySQL Query Tuning

OKC MySQL Users Group

Covering indexes. Stéphane Combaudon - SQLI

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Data Definition Language with mysql. By Kautsar

MySQL Creating a Database Lecture 3

Building Better. SQL Server Databases

More MySQL ELEVEN Walkthrough examples Walkthrough 1: Bulk loading SESSION

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... )

How to Use JSON in MySQL Wrong

The M in LAMP: MySQL CSCI 470: Web Science Keith Vertanen Copyright 2014

Module 3 MySQL Database. Database Management System

Advanced MySQL Query Tuning

Tired of MySQL Making You Wait? Alexander Rubin, Principal Consultant, Percona Janis Griffin, Database Evangelist, SolarWinds

Tips from the Trenches Preventing downtime for the over extended DBA. Andrew Moore Senior Remote DBA Percona Managed Services

Introduction to SQL Server 2005/2008 and Transact SQL

MySQL Workshop. Scott D. Anderson

Acknowledgments About the Authors

Exact Numeric Data Types

SQL Data Definition Language: Create and Change the Database Ray Lockwood

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases

Oracle 1Z MySQL 5.6 Database Administrator. Download Full Version :

Lecture 5: SQL s Data Definition Language

Programming and Database Fundamentals for Data Scientists

Use Cases for Partitioning. Bill Karwin Percona, Inc

Why we re excited about MySQL 8

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

SQL. Often times, in order for us to build the most functional website we can, we depend on a database to store information.

Lab 4: Tables and Constraints

Data Storage and Query Answering. Data Storage and Disk Structure (4)

MySQL for Database Administrators Ed 3.1

Oracle Exam 1z0-883 MySQL 5.6 Database Administrator Version: 8.0 [ Total Questions: 100 ]

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Exam Questions 1z0-882

SQL: Data Definition Language

Oracle Exam 1z0-882 Oracle Certified Professional, MySQL 5.6 Developer Version: 7.0 [ Total Questions: 100 ]

A Practical Guide to Migrating from Oracle to MySQL. Robin Schumacher

Part 1: IoT demo Part 2: MySQL, JSON and Flexible storage


CIS 363 MySQL. Chapter 4 MySQL Connectors Chapter 5 Data Types Chapter 6 Identifiers

Data types String data types Numeric data types Date, time, and timestamp data types XML data type Large object data types ROWID data type

Percona Live 2017 Santa Clara, California April 24-27, Rick's RoTs Rules of Thumb for MySQL Rick James

ITS. MySQL for Database Administrators (40 Hours) (Exam code 1z0-883) (OCP My SQL DBA)

Senturus Analytics Connector. User Guide Cognos to Tableau Senturus, Inc. Page 1

CSE 530A. Inheritance and Partitioning. Washington University Fall 2013

ColdFusion Summit 2016

Effective Testing for Live Applications. March, 29, 2018 Sveta Smirnova

<Insert Picture Here> Boosting performance with MySQL partitions

Lecture 1. Monday, August 25, 2014

user specifies what is wanted, not how to find it

GridDB Advanced Edition SQL reference

Data and Tables. Bok, Jong Soon

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Common MySQL Scalability Mistakes AUTHOR

1Copyright 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12

NoSQL and SQL: The Best of Both Worlds

Compression Users Guide. Adaptive Server Enterprise 15.7

MySQL 5.1 Past, Present and Future MySQL UC 2006 Santa Clara, CA

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS

Careerarm.com. 1. What is MySQL? MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle)

What's New in MySQL 5.7?

MySQL Utilities, part 1. Sheeri Cabral. Senior DB Admin/Architect,

CS143: Relational Model

IBM DB2 UDB V7.1 Family Fundamentals.

MySQL Database Administrator Training NIIT, Gurgaon India 31 August-10 September 2015

Simple Quesries in SQL & Table Creation and Data Manipulation

1z0-882.exam.55q 1z0-882 Oracle Certified Professional, MySQL 5.6 Developer

Experimental Finance, IEOR. Mike Lipkin, Alexander Stanton

Chapter 3 Introduction to relational databases and MySQL

Provide One Year Free Update!

THE UNIVERSITY OF AUCKLAND

This lab will introduce you to MySQL. Begin by logging into the class web server via SSH Secure Shell Client

Transcription:

The Top 20 Design Tips For MySQL Enterprise Data Architects Ronald Bradford COO PrimeBase Technologies April 2008 Presented Version By: 1.1 Ronald 10.Apr.2008 Bradford

1. Know Your Technology Tools Generics are inefficient Product expertise in a different RDBMS is not enough You have chosen MySQL Maximize it's strengths Minimize it's weaknesses

Overview Table Structure SQL Indexes Enterprise Approaches

1. Know Your Technology Tools Maximize MySQL strengths Scale out / HA Options Different Storage Engines Query Cache Minimize MySQL weaknesses No Online Alter Backup Strategies Instrumentation

2. Know Your Disk Footprint Disk = Memory = Performance Every single byte counts Average 25% - 30% saving on engagements ( System Better 60% (200GB ( masters Best 78% (8GB per master with 12 Less disk accesses and more data in memory

3. Choose Your Numeric Data Type MySQL has 9 numeric data types Oracle for example has only 1

3. Choose Your Numeric Data Type Integer: TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT Floating Point: FLOAT, DOUBLE Fixed Point: Other: DECIMAL ( maybe BIT, (ENUM

3. Choose Your Numeric Data Type Favorite signs of poor design ( INT(1 BIGINT AUTO_INCREMENT no UNSIGNED used ( DECIMAL(31,0

3. Choose Your Numeric Data Type INT(1) - 1 does not mean 1 digit (1) represents client output display format only INT is 4 Bytes, TINYINT is 1 Byte TINYINT UNSIGNED can store from 0 255 BIT is even better when values are 0-1

3. Choose Your Numeric Data Type BIGINT is not needed for AUTO_INCREMENT INT UNSIGNED stores 4.3 billion values You should be partitioning when at billions of rows BIGINT is applicable for some columns e.g. summation of values

3. Choose Your Numeric Data Type Best Practice All integer columns UNSIGNED unless there is a reason otherwise Adds a level of data integrity for negative values Best Practice

4. Other Data Type Efficiencies 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???

4. Other Data Type Efficiencies ( CHAR(n Use VARCHAR(n) for variable values e.g. CHAR(128) when storing ~10 bytes

5. Application Data Type Efficiencies Using Codes or ENUM A description is a presentation layer function e.g. 'M', 'F' instead of 'Male', 'Female' e.g. 'A', 'I' instead of 'Active', 'Inactive' ( BINARY(16/20 v CHAR(32/40) MD5() or HASH() Hex value with twice the length INT UNSIGNED for IPv4 address VARCHAR(15) results in average 12 bytes v 4 bytes

6. NOT NULL Saves up to a byte per column per row of data Double benefit for indexed columns Don't use frameworks or tools NOT NULL DEFAULT '' is bad design Always use NOT NULL unless there is a reason why not Best Practice

7. Know about character sets Default in MySQL 5 is UTF8 Can be defined at database, schema, table or column level Only define columns that need UTF8 e.g. Codes, MD5 Value, web address MySQL internal buffers are fixed width e.g. VARCHAR(255) utf8 is 765 bytes to store just 1 byte

8. When VARCHAR Is Bad ( VARCHAR(255 Poor Design - No understanding of underlying data Old Design - ( 4.x limitation, now 3-4 years ( old Disk usage may be efficient MySQL internal memory usage is not

8. When VARCHAR is bad CREATE TABLE `XXX` ( `orderhandle` varchar(255) NOT NULL default '', `personname` varchar(255) default NULL, `addresslines` varchar(255) default NULL, `city` varchar(255) default NULL, `state` varchar(255) default NULL, `postalcode` varchar(255) default NULL, `countrycode` varchar(255) default NULL, `phone` varchar(255) default NULL, `email` varchar(255) default NULL, `shipmethod` varchar(255) default NULL, `shipto` varchar(255) default NULL, `receivebydate` date default NULL, `currency` varchar(3) default NULL, `price` varchar(255) default NULL, `flags` int(11) default '0', `lastupdatetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `creationtime` timestamp NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`orderhandle`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8

9. Be Wary of TEXT/BLOB Using SELECT * MySQL Internal Temporary table will force Temp Disk Table ( Innodb Internal storage (e.g. Stores first 768 bytes, then a separate 16k data page per row per TEXT/BLOB field

10. Know Every SQL Statement Developers don't write proper SQL statements SQL statements will directly affect your performance For Example Repeating SQL statements for no benefit 1000 very quick small unnecessary queries is worse then 1 slow query

10. Know Every SQL Statement Data collection options Incomplete Options Slow Query Log SHOW PROCESSLIST Application level logging Impractical Options General Log

10. Know Every SQL Statement Data collection options MySQL Proxy See histogram.lua Firewall forwarding rules

11. Monitor Every SQL Statement ( QEP ) Review Query Execution Plan EXPLAIN Time queries Row Count / Affected rows Result Set Size Best Practice Review over time, things change

12. The Impact Of Indexes 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

13. Index Types For Design Concatenated Indexes (col1, col2) Partial Indexes (name(20)) Covering Indexes Full Text Indexes No function based indexes

14. Minimizing internal MySQL processing Correctly design tables, indexes and SQL to eliminate Using temporary table Using filesort

15. Transactions Always design for transactions Always use transactions Use a transactional storage engine

16. Data Integrity is Key MySQL historically has been very lax Warnings (e.g. Truncations) are rarely every caught SQL_MODE=STRICT_ALL_TABLES Within Schema NOT NULL ENUM UNSIGNED

17. Leverage The Query Cache Query Cache can be a great benefit Deterministic v Non Deterministic SQL Best Practice MySQL Query Cache is not the only type of caching you should consider

17. Leverage The Query Cache

17. Leverage The Query Cache SHOW PROFILE Path Simple SELECT No Query Cache 17 steps With Query Cache 5 steps Does not perform parse Does not perform optimize

+--------------------------------+----------+---------------------------+---------------+-------------+ 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 0.000007 query_cache_end_of_result Text sql_cache.cc 735 storing result in query cache 0.000007 mysql_parse sql_parse.cc 6142 freeing items 0.000018 dispatch_command sql_parse.cc 2146 closing tables 0.000009 log_slow_statement sql_parse.cc 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)

18. Create Objects Appropriately Using 1 table instead of ʻnʼ for same column structure e.g. Code table for each type of code Splitting tables for optimal storage e.g. Placing optional TEXT/BLOB columns in second table Use permanent tables instead of TEMPORARY tables

19. Naming Standards Name all Primary Keyʼs Uniquely e.g. customer_id, order_id not id Use Data Dictionary SQL to verify data types Data Types & Lengths Be Descriptive e.g. invoice_date not just date Avoid Reserved Words e.g. date, time, timestamp

20. Testing, Testing, Testing You must have a testing environment Testing on a Production server is not an option Best Practice The goal of a testing environment is not to test your software, it is to break your software.

Executive Summary Learn and know MySQL specifics Disk = Memory = Performance If you don't know your SQL you don't know your application. Log, Review & Monitor all SQL Know all benefits of different indexes You must test to failure in a dedicated test environment

Professional Help is Available PrimeBase Technologies Technology Experts Solution Experts 2 decades Expertise & Experience in Enterprise RDBMS Data Architecture 9 years in MySQL