I can't understand how the subpartitioning works in mysql.
I am reading the following example:
create table invoices (
customer_id int not null,
product_id int not null,
amount decimal (8,2) not null,
entry_date date not null default '2006-01-01',
store_id int not null
)
partition by range (year(entry_date))
subpartition by hash(customer_id)
subpartitions 4 (
partition p0 values less than (2008),
partition p1 values less than (2009),
partition p2 values less than (2010),
partition p3 values less than (2011),
partition plast values less than MAXVALUE
);
I can not understand or visualize how this is formed in the HD.
I think that 4 * 5 = 20 physical files are created. Is this correct?
And what data are stored together? Is there a "clustering" of 2008 dates for all customers with the same hash? I am confused on that. Also I am confused how the data are fetched.
Is the customer_id hash used first to determine the range partition or the opposite. What are the exact steps to fetch the data?
UPDATE
Another example. I did the following:
mysql> 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
-> );
Query OK, 0 rows affected (0.28 sec)
mysql> select partition_name, subpartition_name as sub, partition_method as method, partition_description ,table_rows from information_schema.partitions where table_name='nums_composite';
+----------------+-------+--------+-----------------------+------------+
| partition_name | sub | method | partition_description | table_rows |
+----------------+-------+--------+-----------------------+------------+
| p0 | p0sp0 | RANGE | 10 | 17 |
| p0 | p0sp1 | RANGE | 10 | 24 |
| p1 | p1sp0 | RANGE | 20 | 20 |
| p1 | p1sp1 | RANGE | 20 | 17 |
| p2 | p2sp0 | RANGE | MAXVALUE | 13 |
| p2 | p2sp1 | RANGE | MAXVALUE | 9 |
+----------------+-------+--------+-----------------------+------------+
6 rows in set (0.00 sec)
It seems that I am right it creates hash_no* subpartition files but where are they?
root@jim-Linux:/# find . -iname "*_composite*"
./var/lib/mysql/partioning_chapter_test/nums_composite.frm
./var/lib/mysql/partioning_chapter_test/nums_composite.par
Why can't I see the actual files?
show global variables like 'datadir';.cdthat folder, and you will see the ibdata. Thencd testa dn runls -l nums_comp*. That's where the files should be. since they are not there and the information_schema says they are there, the table is logically inside ibdata1. – RolandoMySQLDBA Aug 31 '14 at 20:31SET global innodb_file_per_table=ON– Jim Sep 06 '14 at 21:14echo "innodb_file_per_table=ON" >> /etc/mysql/my.cnf– Jim Sep 06 '14 at 21:14[mysqld]inmy.cnf. Doingecho "innodb_file_per_table=ON" >> /etc/mysql/my.cnfonly works if[mysqld]is the last group header. If it is not, it will get missed. In fact, that might prevent mysqld from being restarted. You should manually edit themy.cnffile and make sure it is under the[mysqld]group header. – RolandoMySQLDBA Sep 06 '14 at 22:13innodb_file_per_tablewas not under[mysqld]header. But the last line under an include.But is isinnodb_file_per_table=ONorinnodb_file_per_table=1?In the answer you mention1. I had set it toONvia theSET GLOBAL– Jim Sep 07 '14 at 09:05