content_image/713354.jpg content_image/713355.jpg
mysql> INSERT INTO employees_sub # reuse data in employees table -> SELECT * FROM employees; Query OK, 18 rows affected (0.09 sec) Records: 18 Duplicates: 0 Warnings: 0 mysql> SELECT id, CONCAT(fname, ’ ’, lname) AS name -> FROM employees_sub PARTITION (p2sp1); 

<img src='content_image/713354.jpg'>

You may also use a PARTITION  option in the SELECT  portion of an INSERT ... SELECT  statement, as shown here: 

mysql> CREATE TABLE employees_copy LIKE employees; Query OK, 0 rows affected (0.28 sec) mysql> INSERT INTO employees_copy -> SELECT * FROM employees PARTITION (p2); Query OK, 5 rows affected (0.04 sec) Records: 5 Duplicates: 0 Warnings: 0 

mysql> SELECT * FROM employees_copy; 

<img src='content_image/713355.jpg'>

5 rows in set (0.00 sec) 

Partition selection can also be used with joins. Suppose we create and populate two tables using the statements shown here: 

CREATE TABLE stores ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, city VARCHAR(30) NOT NULL ) PARTITION BY HASH(id) PARTITIONS 2; INSERT INTO stores VALUES (’’, ’Nambucca’), (’’, ’Uranga’), (’’, ’Bellingen’), (’’, ’Grafton’); CREATE TABLE departments ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30) NOT NULL ) PARTITION BY KEY(id) PARTITIONS 2; INSERT INTO departments VALUES (’’, ’Sales’), (’’, ’Customer Service’), (’’, ’Delivery’), (’’, ’Accounting’); 

You can explicitly select partitions (or subpartitions, or both) from any or all of the tables in a join. (The PARTITION  option used to select partitions from a given table immediately follows the name of the 

