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?