MySQL 5.5 partition table by A-Z

后端 未结 1 1796
遇见更好的自我
遇见更好的自我 2021-01-02 17:59

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 c

相关标签:
1条回答
  • 2021-01-02 18:43

    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 讨论(0)
提交回复
热议问题