Changes between Initial Version and Version 1 of Partition


Ignore:
Timestamp:
06/15/22 00:47:57 (2 years ago)
Author:
krit
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Partition

    v1 v1  
     1= Partition =
     2
     31. mysql restore sample data (mysqlsampledatabase.sql) from [https://www.mysqltutorial.org/mysql-sample-database.aspx here]
     4{{{
     5rpl_user@node1:/mysql/test/T3$ /mysql/bin/mysql -uroot --protocol=socket --socket=/tmp/mysql.0.sock <  mysqlsampledatabase.sql
     6}}}
     7
     82. create table payments2. primary key MUST include in PARTITION
     9{{{
     10mysql> CREATE TABLE payments2 (
     11          customerNumber int(11) NOT NULL,
     12          checkNumber varchar(50) NOT NULL,
     13          paymentDate datetime NOT NULL,
     14          amount decimal(10,2) NOT NULL,
     15          PRIMARY KEY (customerNumber,paymentDate ) ) PARTITION BY RANGE( TO_DAYS(paymentDate) )
     16          ( PARTITION p2003 VALUES LESS THAN (TO_DAYS('2004-01-01')),
     17            PARTITION p2004 VALUES LESS THAN (TO_DAYS('2005-01-01')),
     18            PARTITION p2005 VALUES LESS THAN (TO_DAYS('2006-01-01')) );
     19}}}
     20
     213. copy payments table to just create payments2
     22{{{
     23mysql> insert into payments2 select * from payments
     24}}}
     25
     263. test and notice the '''rows''' between table payments (273) vs payments2 (37)
     27{{{
     28mysql> explain select * from payments2 where paymentDate = "2005-05-03";
     29+----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+
     30| id | select_type | table     | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
     31+----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+
     32|  1 | SIMPLE      | payments3 | p2005      | ALL  | NULL          | NULL | NULL    | NULL |   37 |    10.00 | Using where |
     33+----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+
     341 row in set, 1 warning (0.00 sec)
     35
     36mysql> explain select * from payments where paymentDate = "2005-05-03";
     37+----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+
     38| id | select_type | table    | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
     39+----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+
     40|  1 | SIMPLE      | payments | NULL       | ALL  | NULL          | NULL | NULL    | NULL |  273 |    10.00 | Using where |
     41+----+-------------+----------+------------+------+---------------+------+---------+------+------+----------+-------------+
     421 row in set, 1 warning (0.00 sec)
     43
     44}}}