Partitioning Sheeri K. Cabral Database Administrator The Pythian Group, January 12, 2009.

Slides:



Advertisements
Similar presentations
CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi.
Advertisements

Project Management Database and SQL Server Katmai New Features Qingsong Yao
Presented by, MySQL AB® & O’Reilly Media, Inc. Applied Partitioning and Scaling Your (OLTP) Database System Phil Hildebrand thePlatform.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
Introduction to Structured Query Language (SQL)
SQL Data Definition II Stanislava Armstrong 1SQL Data Definition II.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Introduction to Structured Query Language (SQL)
Kirkwood Center for Continuing Education By Fred McClurg, Introduction to PHP and MySQL Copyright © 2010 All Rights Reserved.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Sarah Sproehnle Cloudera, Inc
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Oracle9i Database Administrator: Implementation and Administration 1 Chapter 9 Index Management.
MySQL. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn The main subsystems in MySQL architecture The different storage.
Introduction to Internet Databases MySQL Database System Database Systems.
SQL Server Indexes Indexes. Overview Indexes are used to help speed search results in a database. A careful use of indexes can greatly improve search.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Advanced Database Management System
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Proactively Optimizing Queries with EXPLAIN and mk-query-digest Presented by: Sheeri K. Cabral Database Operations Manager MySQL Sunday at Oracle OpenWorld.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Get Rid of Cron Scripts Using Events Sheeri Cabral Senior DB Admin/Architect,
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Chapter 12 Additional Database Objects. Chapter Objectives  Define the purpose of a sequence and state how it can be used by an organization  Explain.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Kirkwood Center for Continuing Education By Fred McClurg, Introduction to PHP and MySQL Copyright © 2015, Fred McClurg, All Rights.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
Bend SQL to Your Will With EXPLAIN Ligaya Turmelle MySQL Support Engineer
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
Understanding SQL Statements
Insert, Update and the rest…
Optimizing MySQL Joins and Subqueries
Importing and Exporting Data with MySQL
Data Definition and Data Types
Are You Getting the Best Out of Your MySQL Indexes?
ITD1312 Database Principles Chapter 5: Physical Database Design
MySQL Explain examples
Sergey Vojtovich Software MariaDB Foundation
Instant Add Columns in MySQL
Structured Query Language (Data definition Language)
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Chapter 8 Working with Databases and MySQL
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
SQL DATA CONSTRAINTS.
CS122 Using Relational Databases and SQL
CSE 544: Lecture 11 Storing Data, Indexes
Data Definition Language
Data Definition Language
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
A – Pre Join Indexes.
Instructor: Samia arshad
CS122 Using Relational Databases and SQL
Presentation transcript:

Partitioning Sheeri K. Cabral Database Administrator The Pythian Group, January 12, 2009

Partitioning ● Why ● What ● How

How to Partition CREATE TABLE tblname ( fld FLDTYPE.... ) PARTITION BY TYPE(fld) part_info – Works with most storage engines!

Partition Definition Information ● 1024 max partitions/subpartitions ● Case-insensitive partition names ● Can use a function instead of a field – PARTITION BY RANGE(expr)

Partition Definition Requirements ● Only integer/NULL fields (except KEY) ● Partitioning function can only use fields from the PRIMARY or UNIQUE keys. ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

Partition Definition Restrictions ● No FULLTEXT index ● No SPATIAL data ● No foreign key or reference to

Partition Definition Restrictions ● No TEMPORARY, MERGE, FEDERATED, CSV ● No tables used for internal logging ● No key cache

Partition Definition Restrictions ● No INSERT DELAYED ● Table {DATA|INDEX} DIRECTORY ignored ● No mysqlcheck / myisamchk

RANGE Partitioning ● type = RANGE ● specify VALUES LESS THAN ● specify partition names

RANGE Partition Definition CREATE TABLE tblname ( fld FLDTYPE.... ) PARTITION BY RANGE(fld) ( PARTITION pname VALUES LESS THAN (val) [,PARTITION pname VALUES LESS THAN (val)] )

RANGE Partition Definition CREATE TABLE nums_range ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) ) ENGINE=InnoDB PARTITION BY RANGE (id) ( PARTITION p0mil VALUES LESS THAN ( ), PARTITION p1mil VALUES LESS THAN ( ), PARTITION p2mil VALUES LESS THAN ( ), PARTITION p3mil VALUES LESS THAN ( ), PARTITION p4mil VALUES LESS THAN ( ) );

Minimum and Maximum values ● INFORMATION_SCHEMA.PARTITIONS ● What about a value >5,000,000 ? ● How can we fix that?

Minimum and Maximum values ● INFORMATION_SCHEMA.PARTITIONS ● What about a value >5,000,000 ? ● How can we fix that? – VALUES LESS THAN MAXVALUE

RANGE Partition Definition CREATE TABLE nums_range_mod ( id int NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB PARTITION BY RANGE (id % 4) ( PARTITION zero VALUES LESS THAN (1), PARTITION one VALUES LESS THAN (2), PARTITION two VALUES LESS THAN (3), PARTITION three VALUES LESS THAN (4), PARTITION should_be_empty VALUES LESS THAN MAXVALUE);

LIST Partitioning ● Like RANGE, but exact value matches – PARTITION BY LIST (PARTITION name VALUES IN (list) ) ● Order not important ● No catch-all

LIST Partition Definition CREATE TABLE nums_list_mod ( id int NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB PARTITION BY LIST (id % 4) ( PARTITION zero VALUES IN (0), PARTITION one VALUES IN (1), PARTITION two VALUES IN (2), PARTITION three VALUES IN (3) );

HASH Partitioning ● What to partition ● Number of partitions PARTITION BY HASH (expr) PARTITIONS x

HASH Partition Definition CREATE TABLE nums_hash ( id int NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB PARTITION BY HASH (id) PARTITIONS 4;

LINEAR HASH Partitioning ● Like HASH ● Does not use % PARTITION BY LINEAR HASH (expr) PARTITIONS x

KEY Partitioning Basics ● Like HASH, but field(s) only ● Part or all of PRIMARY KEY ● Can use non-integer/NULL fields

KEY Partitioning Algorithm PARTITION BY KEY([fld1[, fld2]]...) PARTITIONS x ● Uses internal algorithm ● Storage engine dependent

KEY Partition Definition CREATE TABLE nums_key ( id int NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB PARTITION BY KEY() PARTITIONS 4;

LINEAR KEY Partitioning ● Like LINEAR HASH PARTITION BY LINEAR KEY ([fld1 [, fld2]]) PARTITIONS x

Composite Partitioning ● Subpartition RANGE/LIST partitions... ●...into HASH/KEY subpartitions

Composite Partitioning CREATE TABLE nums_composite ( id INT, happened DATETIME NOT NULL, PRIMARY KEY (id, happened) ) ENGINE=InnoDB PARTITION BY RANGE (HOUR(happened)) SUBPARTITION BY HASH( id ) SUBPARTITIONS 2 ( PARTITION p0 VALUES LESS THAN (10), PARTITION p1 VALUES LESS THAN (20), PARTITION p2 VALUES LESS THAN MAXVALUE );

Loading the Data mysql> INSERT INTO nums_composite (id, happened) SELECT id, ' :00:00' + INTERVAL id HOUR FROM nums_hash; Query OK, 500 rows affected (0.01 sec) Records: 500 Duplicates: 0 Warnings: 0

Manual Subpartitions ● Can specify {DATA | INDEX} DIRECTORY ● Must specify name, for others, default ● Subpartition names unique across table

NULL ● RANGE = lowest value ● LIST = must contain VALUES IN (NULL) ● HASH/KEY = treated as 0

Removing Partitions/ing ALTER TABLE tbl REMOVE PARTITIONING ALTER TABLE tbl DROP PARTITION pname ● Only for named partitioning! LIST/KEY

Changing Partitioning ALTER TABLE tbl PARTITION BY.... ALTER TABLE tbl REORGANIZE PARTITION pname [, pname] INTO ( partition definition(s) ) – REORGANIZE for LIST/RANGE only

Changing HASH/KEY Partitioning ALTER TABLE tbl COALESCE PARTITION x ALTER TABLE tbl ADD PARTITION PARTITIONS x

Partition Maintenance – ALTER TABLE tbl... ● REBUILD PARTITION list – defrag ● OPTIMIZE PARTITION list – defrag, reclaim space

Partition Maintenance – ALTER TABLE tbl.. ● CHECK PARTITION list ● REPAIR PARTITION list ● ANALYZE PARTITION list

EXPLAIN ● EXPLAIN PARTITIONS SELECT... mysql> EXPLAIN PARTITIONS SELECT * -> FROM nums_range_mod limit 10\G ********************** 1. row ******************* id: 1 select_type: SIMPLE table: nums_range_mod partitions: zero,one,two,three,should_be_empty type: index possible_keys: NULL key: PRIMARY key_len: 4 ref: NULL rows: 501 Extra: Using index 1 row in set (0.00 sec)

Resources ● MySQL Manual ● Forums ● ning-limitations.html

Sheeri Cabral