Skip to content

Instantly share code, notes, and snippets.

@brihter
Last active December 21, 2015 08:49
Show Gist options
  • Save brihter/6280645 to your computer and use it in GitHub Desktop.
Save brihter/6280645 to your computer and use it in GitHub Desktop.
MySQL partitioning snippets (assuming MyISAM engine).
-- create a partitioned table
-- use a default (unused) value for a dummy initial partition when dynamically adding more
create table `TABLE` (
`id` int(10) not null,
...
)
collate='utf8_general_ci'
engine=MyISAM
partition by list (id)
(
partition p0 values in (0)
);
-- see if partition exists
select count(*) from information_schema.partitions where table_schema = 'SCHEMA' and table_name = 'TABLE' and partition_name = 'pXXX'
-- dynamically add a partiton
alter table TABLE add partition (partition pXXX values in (XXX));
-- empty the partition
alter table TABLE truncate partition pXXX;
-- remove the partition
alter table TABLE drop partition pXXX;
-- select the partition
select * from TABLE partition (pXXX, ...);
-- repair a broken partition
alter table TABLE repair partition pXXX;
-- compress unused space (used when removing a lot of data from a partition)
alter table TABLE optimize partition pXXX;
-- does a full re-insert into partition
alter table TABLE rebuild partition pXXX;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment