开发者

MySQL 5.5 partition table by A-Z

I understand that as of MySQL 5.5, you can now partition a table by non-integer values like a varchar. I have a table where I perform a lot of lookups on a single varchar column, hence I would like to partition on that for performance reasons.

In all instances, the value of the column is a single alphabetical word (strictly lower case a-z, enforced by validation).

What I would like to do is partition t开发者_StackOverflow中文版his table by the first letter in each word stored, so all words beginning with 'a' go in the first partition, 'b' in the second etc.

My gut feeling is that I could probably construct the create/alter table statement to use the LIKE statement, but am unsure about the syntax.

Has anyone done anything like this using MySQL 5.5?


If you are determined to do it by the first letter, I think that RANGE partitioning would do the trick. However, if you don't have an absolute requirement for the partitioning to by by first letter, LINEAR KEY partitioning might be better.

Here is an example I lifted from the manual page sited and modified to use a varchar column:

CREATE TABLE employees (
    id INT NOT NULL,
    fname VARCHAR(30),
    lname VARCHAR(30),
    hired DATE NOT NULL DEFAULT '1970-01-01',
    separated DATE NOT NULL DEFAULT '9999-12-31',
    job_code INT NOT NULL,
    store_id INT NOT NULL
)
PARTITION BY RANGE COLUMNS(fname) (
    PARTITION p0 VALUES LESS THAN ('h'),
    PARTITION p1 VALUES LESS THAN ('m'),
    PARTITION p2 VALUES LESS THAN ('t'),
    PARTITION p3 VALUES LESS THAN MAXVALUE
);

And running it:

... Physical database connection acquired for: Feynman
 12:33:07  [CREATE - 0 row(s), 0.062 secs]  Command processed. No rows were affected
... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.062/0.000 sec  [0 successful, 1 warnings, 0 errors]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜