Search code examples
mysqlsqldatabase-partitioning

My SQL Table Partitions


  • Example : I create a table with 1000 Data .

  • I Partition this table

     alter table rnds add primary key (id) partition by HASH(id) partitions 200;
    
  • I check in mysql data directory and found it create 5 part

rnds#P#p0.ibd , rnds#P#p1.ibd , rnds#P#p2.ibd , rnds#P#p3.ibd , rnds#P#p4.ibd

  • After i insert another 1000 row in this table and it insert successfully .
  • My Questions is that why not new part are create for new 1000 data.
  • After create a table partition how the table manage new data .

Solution

  • If you want create 5 partitions you should use:

    alter table rnds partition by HASH(id) partitions 5;
    

    This command will create 5 partitions and new rows will be added to them based on ID. New partitions are not created automatically. You can add new partition using ADD PARTITION command.

    See this link for details.